Proxy forwarding on Apache

If you’re hosting on a web server that requires Apache to be the front-end, like using it as a virtual domain host for multiple domains, chances are it’ll be difficult for you to swap Apache with any other web server, especially if the other domains are happily hosted without a problem. But what if you are required to use some other app servers without taking away Apache instead?

I’m not sure about most distributions, but mod_proxy comes default with the Apache distribution, but it’s just not enabled in RedHat. So in order to make use of mod_proxy, you’ll need to enable it first. Stick this somewhere in your Apache configuration file:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so

After which you can start your other app servers at unoccupied ports on your server, eg. 8080, and setup Apache to perform the forwarding. An example setup may look something like this:

<virtualhost *.80>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
ServerAdmin admin@yourdomain.com

ErrorLog /var/log/[wherever.your.error.file.is]
CustomLog /var/log/[wherever.your.log.file.is] custom

ProxyPreserveHost On

# Example to serve the entire domainname, from the root directory (/)
ProxyPass        / http://127.0.0.1:8080/
ProxyPassReverse / http://127.0.0.1:8080/

</virtualhost>

The configuration assumes that your alternate app server is hosted on the same server on port 8080 as indicated, given that port 80 is already occupied by Apache. Otherwise this should allow all connections to be transparently forwarded to your new app server without losing functionality of your existing hosts.