Managing multiple reverse proxies for one virtual host in apache2

Posted by Chris Betti on Pro Webmasters See other posts from Pro Webmasters or by Chris Betti
Published on 2012-04-30T15:24:35Z Indexed on 2012/05/31 4:50 UTC
Read the original article Hit count: 1003

I have many reverse proxies defined for my js-host VirtualHost, like so:

/etc/apache2/sites-available/js-host

<VirtualHost *:80>
ServerName js-host.example.com
[...]
ProxyPreserveHost On
ProxyPass        /serviceA http://192.168.100.50/
ProxyPassReverse /serviceA http://192.168.100.50/
ProxyPass        /serviceB http://192.168.100.51/
ProxyPassReverse /serviceB http://192.168.100.51/
[...]
ProxyPass        /serviceZ http://192.168.100.75/
ProxyPassReverse /serviceZ http://192.168.100.75/
</VirtualHost>

The js-host site is acting as shared config for all of the reverse proxies. This works, but managing the proxies involves edits to the shared config, and an apache2 restart.

Is there a way to manage individual proxies with a2ensite and a2dissite (or a better alternative)? My main objective is to isolate each proxy config as a separate file, and manage it via commands.

First Attempt

I tried making separate files with their own VirtualHost entries for each service:

/etc/apache2/sites-available/js-host-serviceA

<VirtualHost *:80>
ServerName js-host.example.com
[...]
ProxyPass        /serviceA http://192.168.100.50/
ProxyPassReverse /serviceA http://192.168.100.50/
</VirtualHost>

/etc/apache2/sites-available/js-host-serviceB

<VirtualHost *:80>
ServerName js-host.example.com
[...]
ProxyPass        /serviceB http://192.168.100.51/
ProxyPassReverse /serviceB http://192.168.100.51/
</VirtualHost>

The problem with this is apache2 loads the first VirtualHost for a particular ServerName, and ignores the rest. They aren't "merged" somehow as I'd hoped.

© Pro Webmasters or respective owner

Related posts about apache2

Related posts about web-services