Using a reverse Proxy with a subdomain

So let’s see, what I need is that every request to a certain subdomain to be mapped to another server, with a private IP-Address. This is great because I only expose parts of my server to the Network that I want.
First things first: in the apache configuration, which is usually located at /etc/sysconfig/apache2 edit the APACHE_OPTS to contain -D REVERSE, -D PROXY and -D PROXY_HTML (actually the last one’s not needed as we wont be adjusting any URLs, but let’s keep it anyway).
APACHE2_OPTS="-D DEFAULT_VHOST -D PHP5 -D PERL -D PROXY_HTML -D REVERSE -D PROXY"
Now that we have enabled the proxy stuff, we can start configuring it. In the vhost directory (something like /etc/apache2/vhosts.d/) create a new file that will hold the configurationfor the subdomain:
<virtualhost your-ip-here>
DocumentRoot /srv/www/subdomain/htdocs
ServerName subdomain.domain.tld
ServerAdmin webmaster@subdomain.domain.tld
AccessFileName .htaccess
ScriptAlias /cgi-bin/ /srv/www/subdomain/cgi-bin/
ServerAlias subdomain.domain.tld sudomain
<directory /srv/www/subdomain/htdocs>
Order allow,deny
Allow from all
</directory>
<directory /srv/www/subdomain/cgi-bin>
AllowOverride None
Order allow,deny
Options ExecCGI
Allow from all
</directory>
</virtualhost>
Ok so by bow we have created the new subdomain, just to let apache shut up about missing folders we’ll create the required folder:
mkdir -p /srv/www/subdomain/{htdocs,cgi-bin}
What’s missing now? Right, the reverse Proxy
so we have to add two new lines to the definition above:
ProxyPass / http://internal-ip-address/
ProxyPassReverse / http://internal-ip-address/
That’s it! Just put the above before the Closing VirtualHost tag and it should work just fine.

Chris Messina takes an in depth look at Adobes recent donation of Source Code to the Open Source Community (this is to be read as Mozilla).