Find file
Fetching contributors…
Cannot retrieve contributors at this time
125 lines (86 sloc) 5.92 KB
deprecated author description keywords license alias modified modified_by published title
name email
How to use separate web servers to host sites or applications using ProxyPass with Apache.
apache,proxypass,apache on fedora,multiple web servers
Friday, April 29th, 2011
Thursday, February 4th, 2010
Multiple Web Servers with ProxyPass on Fedora 12

In some cases, administrators find that while Apache meets most of their general-purpose web serving needs, other web or application servers are better suited for certain tasks. Fortunately, it's easy to configure Apache to pass certain requests to other web server processes. These secondary (or tertiary) web servers may be running on the same VPS or separate nodes (perhaps via private networking). Our examples use lighttpd as a secondary web server, but they apply to any web server or application you'd like to proxy HTTP requests to.

We assume you have followed our getting started guide, and already have Apache running on your Linode. If you don't, you may wish to review our Apache on Fedora 12 guide before proceeding. These steps should be performed as root via a shell session.

Enabling the Proxy Module

The Fedora package of the Apache HTTP server includes the proxy module. To enable this module, create the /etc/httpd/conf.d/proxy.conf file with the following content:

{: .file-excerpt } /etc/httpd/conf.d/proxy.conf : ~~~ apache #turning ProxyRequests on and allowing proxying from all may allow #spammers to use your proxy to send email.

        ProxyRequests Off

        <Proxy *>
                AddDefaultCharset off
                Order deny,allow
                Allow from all

        # Enable/disable the handling of HTTP/1.1 "Via:" headers.
        # ("Full" adds the server version; "Block" removes all outgoing Via: headers)
        # Set to one of: Off | On | Full | Block

        ProxyVia On

This turns on proxy support in the module configuration. Please note the warning regarding the ProxyRequests directive. It should be "off" in your configuration. Next, we'll issue the following command to restart Apache:

/etc/init.d/httpd restart

Apache should restart cleanly. If you encounter any issues, you may wish to inspect the logs available under /var/log/httpd/ for more information.

Proxying a Domain to Lighttpd

We already have a site called "" running under Apache as a normal virtual host. We'll use Apache to send requests for the site "" to a lighttpd instance, which we've configured to run on port 8080 on localhost. You can proxy to any local and non-local HTTP servers as required by your deployment. Here are the configuration directives for "":

{: .file-excerpt } /etc/httpd/conf.d/vhost.conf : ~~~ apache ServerAdmin ServerName ServerAlias

     ProxyPass / http://localhost:8080/

     # Uncomment the line below if your site uses SSL.
     #SSLProxyEngine On

The ProxyPass directive tells Apache to forward all requests for this domain to a web server running on port 8080. If our target server was running on another VPS (as with a server that only answers on the backend private network), we could just specify that address instead. We'll enable the site with the following command:

/etc/init.d/httpd reload

Let's do some testing. Here's the normal Apache-served site "" in our browser:

Website running under Apache on Fedora 12.

Here's the site "" being served by lighttpd via ProxyPass:

Website running under Lighttpd on Fedora 12.

Proxying a Specific URL to Lighttpd

If we wanted to have served by a web application running under lighttpd, we'd simply modify its configuration file to look like this:

{: .file-excerpt } /etc/httpd/conf.d/vhost.conf : ~~~ apache ServerAdmin ServerName ServerAlias DocumentRoot /srv/www/ ErrorLog /srv/www/ CustomLog /srv/www/ combined

     ProxyPass /myapp http://localhost:8080/

Now the location "/myapp" will be served by lighttpd instead of Apache. After reloading the Apache configuration with /etc/init.d/httpd reload, we can see that it's functioning correctly:

Web application running under a directory via lighttpd on Fedora 12

This is an easy method for hosting multiple application servers (with different web server requirements) under a single domain.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.