Named reverse proxy

From FBSD_tips

Jump to: navigation, search

We combine 2 aspects of apache here to create a reverse proxy that can run on one IP and redirect http requests to many other http servers based on the name of the server. One case where this can be particularly useful is when you have 1 internet routable IP and control of your DNS zone and wish to serve many sites. You can accomplish this this by making multiple CNAME DNS records (or aliases) for the IP that the server is running on, the server name will be carried in the metadata of the http header. For instance if both test1.something.net and test2.something.net resolve to the same IP, and you have apache listening on it.

In your zone file for something,net in this case, put :

test1.something.net.  IN      CNAME   74.182.77.10
test2.something.net.  IN      CNAME   74.182.77.10

And assuming that a real name exists (and apache is listening on it) e.g.

realname.something.net IN  A            74.182.77.10

Now add this to the stock apache2 config file :

NameVirtualhost *:80

<VirtualHost *:80>
       ServerName test1.something.net

       ProxyPass /  http://192.0.0.101/
       ProxyPassReverse /   http://192.0.0.101
</VirtualHost>

<VirtualHost *:80>
       ServerName test2.something.net

       ProxyPass /  http://192.0.0.201/
       ProxyPassReverse /   http://192.0.0.201
</VirtualHost>

This will relay connections to test1.something.net to http://192.0.0.101/ and connections to test2.something.net will be relayed to http://192.0.0.201/.

A more comprehensive treatment of the subject of reverse proxies can be found here


Gongo 23:53, 11 October 2007 (UTC)

Personal tools