Provide HTTP(s) Integration with Apache

From Zimbra :: Wiki

Jump to: navigation, search

Contents

Setting up HTTP and HTTPS support through Apache VirtualHosts

   Article-alert.png  - This article is a community contribution and may include unsupported customizations for network edition customers.



Scenario

Single production server, with public IP address running apache web server hosting multiple virtual domains, and Zimbra Groupware server to providing email and webmail access to users in multiple virtual domains.

The example domain used in this article is 'server.com' - replace with your own domain and is aimed at Redhat/CentOS based machines - the syntax of most commands will no doubt succeed on alternative Linux distributions but the file structuring may differ slightly.

Aims

  • You want to provide both http (insecure) and https (secure) access to clients through the webmail interface.
  • The Apache server listens on default ports 80 and 443, the Zimbra server listens on port 81 and uses the insecure login authentication method (zmtlsctl http).

System Requirements

Time To Implement

Outside of meeting the system requirements, and reading this article through - the actual coding will take between 5-15 minutes depending on how familiar you are with the Linux command-line and the Zimbra server.

Advice

The article has been written by community members, Zimbra administrators and experienced coders - the proof-reading may not be perfect and aims to provide ideas and an example of a successful working practice.

Please feel free to use the Zimbra Forums to request more specific help, follow the article closely and do not rush - it will only take longer !

Top

Laying the foundations

Plan of Action

All following commands are issued whilst logged in with the 'zimbra' user.

sudo su - zimbra

Top

Step 1

  • Ensure Zimbra is running on port 81

Using the syntax : zmprov ms <your-server> zimbraMailPort <your-port-number>

zmprov ms server.com zimbraMailPort 81

Step 1 Breakdown

We logged in as the 'zimbra' user, then using the zmprov command to manipulate server name pair values, tell Zimbra to use the mail port number 81.

n.b. a more detailed thread here

Top

Step 2

  • Tell Zimbra to use the http authentication method - this does not redirect logins to SSL basically.

zmtlsctl http
zmcontrol stop;zmcontrol start

Step 2 Breakdown

We issued the 'zmtlsctl' command and passed the http value (other options include https,both,mixed,redirect but they do not apply to this article)

The Zimbra server was then restarted using the 'zmcontrol' command.

Top

Step 3 - requires root access

  • Create a new apache configuration file to listen for webmail requests on port 80 within /etc/httpd/conf.d/zimbra.conf.

sudo su - 
nano /etc/httpd/conf.d/zimbra.conf

Once within your text editor ensure it looks like this:

<VirtualHost *:80> 
     ServerAlias webmail.*
     ProxyPass / http://server.com:81/
     ProxyPassReverse / http://server.com:81/
     ErrorLog /var/log/httpd/zimbra-error.log
</VirtualHost>

Step 3 Breakdown

We logged in as root using the 'sudo su - ' command, allowing us write access to the Apache configuration directory - located at /etc/httpd/conf.d/.

Then created a new virtual host that listens on port 80 on all network interfaces.

The new virtual host has a server alias of webmail.* - meaning any virtual domain on your server's IP addresses beginning with webmail. will be handled here.

The proxypass line silently redirects all traffic to the zimbra port without the user knowing what is going on behind the scenes.

The proxypassreverse line, simply listens for traffic coming back from the redirect - again without the end user knowing what is going on behind the scenes.

Always useful - we tell Apache to keep a log of any errors in the usual /var/log/httpd/ directory using the ErrorLog line- in case we experience problems we can use the log to troubleshoot. (If all runs smoothly just a # to the beginning of this line to turn the error logging off).

Top

Step 4 - requires root access

  • Create a new apache configuration file to listen for webmail requests on port 443 within /etc/httpd/conf.d/zimbra.conf

sudo su - 
nano /etc/httpd/conf.d/zimbra.conf

Add the following underneath our previous entry:

<VirtualHost *:443> 
        ServerAlias webmail.*
        SSLProxyEngine ON
        SSLEngine On
        SSLCertificateFile /opt/zimbra/ssl/ssl/server/server.crt
        SSLCertificateKeyFile /opt/zimbra/ssl/ssl/server/server.key
        ProxyPass / http://server.com:81/
        ProxyPassReverse / http://server.com:81/
        ErrorLog /var/log/httpd/zimbra_ssl-error.log
</VirtualHost>

Step 4 Breakdown

We logged in as root using the 'sudo su - ' command, allowing us write access to the Apache configuration directory - located at /etc/httpd/conf.d/.

Then we created a new virtual host that listens for https requests on port 443 on all network interfaces.

The new virtual host, again, has a server alias of webmail.* - meaning any virtual domain on your server's IP addresses beginning with webmail. will be handled here - as before but ensuring all https requests are acknowledged.

The proxypass line silently redirects all traffic to the zimbra port without the user knowing what is going on behind the scenes, as before but this time wrapping the insecure back-end within the https front-end to the client's browser.

The proxypassreverse line, simply listens for traffic coming back from the redirect - again without the end user knowing what is going on behind the scenes, again wrapping the insecure back-end responses ready for the secure server to client transfer.

Always useful - we tell Apache to keep a log of any SSL errors in the usual /var/log/httpd/ directory, using the ErrorLog line- in case we experience problems we can use the log to troubleshoot. (If all runs smoothly just a # to the beginning of this line to turn the error logging off).

Top

Apache Config check

  • Test the configuration file to ensure we have no syntax errors before restarting the server

sudo httpd -t

Apache config breakdown

Using the 'sudo' command to elevate our privileges, we run the httpd binary and the -t switch to test all configuration files for syntax errors.

Hopefully, the response should be:

Syntax OK

If not read the error carefully, check and re-check your zimbra.conf file and utilise your resources - i.e. Google, the Zimbra forums etc.

Top

Restart and test your login

  • Restart Apache

sudo /etc/init.d/httpd restart

  • Open your browser and test your insecure login page

http://webmail.server.com

  • Open a new tab and test your secure login page

https://webmail.server.com

Top

Zimbra and mod_security

After recently installing mod_security, post zcs install, I noticed the webmail interface had problems when using proxy virtualhost configurations.

After a lot of effort I decided the easiest thing to get the job working with minimal fuss was to simply disable the security filter for webmail virtualhosts.

This still leaves mod_security to do it's job with other virtualhosts by default.

Just add the following fot http virtualhosts:

<VirtualHost *:80> 
     ServerAlias webmail.*
     SecFilterEngine Off
     ProxyPass / http://server.com:81/
     ProxyPassReverse / http://server.com:81/
     ErrorLog /var/log/httpd/zimbra-error.log
</VirtualHost>

and for https virtualhosts:

<VirtualHost *:443> 
        ServerAlias webmail.*
        SecFilterEngine Off
        SSLProxyEngine ON
        SSLEngine On
        SSLCertificateFile /opt/zimbra/ssl/ssl/server/server.crt
        SSLCertificateKeyFile /opt/zimbra/ssl/ssl/server/server.key
        ProxyPass / http://server.com:81/
        ProxyPassReverse / http://server.com:81/
        ErrorLog /var/log/httpd/zimbra_ssl-error.log
</VirtualHost>

Created by Costa-101

ERROR: mod_proxy with Apache2

If you are getting some "500 Internal Server Error" when accessing http://webmail.server.com/, and you find an error like this in your "zimbra-error.log":

[DATE TIME] [warn] proxy: No protocol handler was valid for the URL /favicon.ico. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

This problem could most likely be solved by linking and therefore loading a required mod. Run the following as root:

ln -s /etc/apache2/mods-available/proxy_http.load \
/etc/apache2/mods-enabled/proxy_http.load

verify that apache configuration is working fine by running

apache2ctl configtest
apache2ctl graceful

Added by Mordred

External Links

Verified Against: unknown Date Created: 2/17/2008
Article ID: http://wiki.zimbra.com/index.php?title=Provide_HTTP(s)_Integration_with_Apache Date Modified: 06/20/2013
Personal tools