Template:Apache2 reverse proxies

From

Jump to: navigation, search

Apache2 reverse proxies

This solution solves the problem of having multiple servers on a LAN which has a single router connected to the Internet. The router forwards all port 80 traffic to a single primary server. That server will then be required to act as a proxy for the other servers on the LAN, redirecting incoming traffic addressed to the URLs of those other servers to their respective LAN IP addresses.

This increases the amount of traffic passing through the primary server, so is not a recommended solution for high volume situations unless the primary server is a dedicated gateway/proxy server. (For high volume situations, a load balancer such as Pound should be used.)

This method uses Apache2 virtual host configuration files on the primary server (to which the router sends port 80 traffic).

  • On the primary server (which will act as the proxy), create a symbolic link to enable the proxy modules in Apache2, then restart Apache2:
sudo ln -s /etc/apache2/mods-available/proxy.load /etc/apache2/mods-enabled
sudo ln -s /etc/apache2/mods-available/proxy_http.load /etc/apache2/mods-enabled
sudo /etc/init.d/apache2 restart
  • Edit a virtual host file for all secondary servers (use the gedit text editor instead of kate if using Ubuntu instead of Kubuntu):
sudo kate /etc/apache2/sites-available/proxiedhosts
and edit the file so that it resembles:
<VirtualHost *:80>
#
ServerName internalserver2.mydomain.org
#
    ProxyPreserveHost On
    ProxyRequests off
    ProxyPass / http://192.168.1.192/
    ProxyPassReverse / http://192.168.1.192/
#
</VirtualHost>
#
#<VirtualHost *:80>
#
#ServerName internalserver3.mydomain.org
#
#     ProxyPreserveHost On
#     ProxyRequests off
#     ProxyPass / http://192.168.1.193/
#     ProxyPassReverse / http://192.168.1.193/
#
#</VirtualHost>
#
#<VirtualHost *:80>
#
#ServerName internalserver4.mydomain.org
#
#     ProxyPreserveHost On
#     ProxyRequests off
#     ProxyPass / http://192.168.1.194/
#     ProxyPassReverse / http://192.168.1.194/
#
#</VirtualHost>
Make sure that each URL for each server has an entry (and obviously remove the hashmarks for each one that is active).
  • Activate the virtual host file by making a symbolic link to the Apache2 sites-enabled folder then restarting Apache2:
sudo ln -s /etc/apache2/sites-available/proxiedhosts /etc/apache2/sites-enabled
sudo /etc/init.d/apache2 restart

Other resources

The information for this page was synthesized from these sources:

Personal tools
Sponsor
  System76