Friday, July 29, 2011

Reverse Proxy with ModProxy


Mod proxy is a versatile module for apache that has many uses. One of its many uses is the reverse proxy feature. Lets say you have multiple web servers behind a router and want to give the outside world access to each server. Your router can only open port 80 for one host, but with modproxy you can direct users to different servers depending on which sub domain or directory they are requesting. This also works for external sites that may not be on your private network.
Hit the jump to see how.
To do this is quite simple:
ProxyRequests Off

Order deny,allow
Allow from all
ProxyPass /foo http://foo.example.com/bar
ProxyPassReverse /foo http://foo.example.com/bar
Example from: http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
Basically when some one requests /foo on your web server that the public port 80 points to, it proxies the request to foo.example.com/bar. The reverse is to make sure that the requests come back to the user that requested it. As the documentation states you should secure your servers before using mod_proxy which is probably a wise choice, but you should always secure your servers.