The other day I had someone ask if there’s a nice solution to the following problem:

Multiple web development virtual machines but only one external IP address.

The quick solution is to port forward on different ports to each virtual machine. For example 81 goes to VM1, 82 goes to VM2, 83 goes to VM3 etc. Which granted, would work, but isn’t a “neat” solution.

Using mod_proxy under Apache is a much better solution to this problem.

Deploy a “front-end” server running Apache and mod_proxy. Create a virtual host for each virtual server and then using mod_proxy, reverse proxy to the virtual server. Port forward from the WAN to your front-end Apache server running mod_proxy.

Here’s what an example config would look like on the front-end Apache server:

<VirtualHost 213.131.192.201:80>
     ServerName cust1.dev.domain.com
     ServerAdmin webmaster@cust1.dev.domain.com
     ProxyRequests off
     ProxyPreserveHost on
     ProxyPass / http://192.168.0.100/
     ProxyPassReverse / http://192.168.0.100/
     <Proxy *>
          Order allow,deny
          Allow from all
     </Proxy>
     ErrorLog /var/log/apache2/cust1.dev.domain.com.log
     CustomLog /var/log/apache2/cust1.dev.domain.com.err.log combined
</VirtualHost>

<VirtualHost 213.131.192.201:80>
     ServerName cust2.dev.domain.com
     ServerAdmin webmaster@cust2.dev.domain.com
     ProxyRequests off
     ProxyPreserveHost on
     ProxyPass / http://192.168.0.101/
     ProxyPassReverse / http://192.168.0.101/
     <Proxy *>
          Order allow,deny
          Allow from all
     </Proxy>
     ErrorLog /var/log/apache2/cust2.dev.domain.com.log
     CustomLog /var/log/apache2/cust2.dev.domain.com.err.log combined
</VirtualHost>

Requests for cust1.dev.domain.com would be reverse proxied to 192.168.0.100 and requests for cust2.dev.domain.com would be reverse proxied to 192.168.0.101. All with one external IP address and one port forward rule.

Just one of the many uses of mod_proxy. You can also use it for SSL bridging and SSL offloading. Neat!

1 Comment

Leave a Reply to John Garrett Cancel reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.