Apache Reverse Proxy & Virtual Hosts

Posted on 08 June 2010

I’ve been working on a .NET project and needed to make a development box available on the web.  I already have another server running that is serving up several other websites.  Since I only have 1 IP from my ISP I needed to figure out how to pass port 80 traffic to multiple internal hosts. 

You cannot NAT port 80 to two different internal or DMZ hosts with only 1 public IP.  You can of course use PAT if your willing to use an alternate port for one of the servers.  I did some quick research on reverse proxies originally intending to use Nginx.   I’d worked with it on a project at one of my previous gigs.    Then I discovered that Apache using mod_proxy can do the same thing.

Design

Proxy Traffic Flow

I’m not going to go through all details, but you can find a good how to here at apache tutor.   I’ll list a short run-down of the highlights for my situation.

  • Upgraded my apache2 installation to apache2-dev so I had access to apxs to build mod_proxy_html (note you may or may not need mod_proxy_html but you probably will). 
  • Download and compile mod_proxy_html from here. http://apache.webthing.com/mod_proxy_html/
  • Build mod_proxy_html using apxs

# apxs -c -I/usr/include/libxml2 -I. -i mod_proxy_html.c

(make sure you have libxml2 installed.  If you get errors building mod_proxy_html.c try upgrading your libxml2 – worked for me)

  • Now edit your httpd.conf to make sure you load the correct modules

LoadModule  proxy_module         modules/mod_proxy.so
LoadModule  proxy_http_module    modules/mod_proxy_http.so
LoadFile    /usr/lib/libxml2.so
LoadModule  proxy_html_module    modules/mod_proxy_html.so

  • Configure the virtual hosts section of httpd.conf.  I’ve got a  FQDN of www.domain3.com that I want to reverse proxy to a different internal server which answers to internal.domain3.com.   The below is how I configured my httpd.conf.

<VirtualHost *:80>
 ServerName www.domain3.com

 ProxyRequests off
 ProxyPass / http://internal.domain3.com/
 ProxyPassReverse / http://internal.domain3.com/
 ProxyHTMLURLMap http://internal.domain3.com/  /
</VirtualHost>

  • Restart apache  #/etc/init.d/httpd restart

1 Response to Apache Reverse Proxy & Virtual Hosts

  • [...] configured an Apache2 reverse proxy as described here.  I could get the index page of the site to load but the css wasn’t getting applied.  If I [...]

  • Recent Posts

    Tag Cloud

    Meta

    Squishnet is proudly powered by WordPress and the SubtleFlux theme.

    Copyright © Squishnet