Using a reverse Proxy with a subdomain

Apache
Having an Apache server is really a great thing, every day you can discover something new:D Today I discovered that I can use a reverse proxy to point to a server behind my firewall. Even better I can use a subdomain to access it, which is exactly what I need.

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.

SSCP, Systems Security Certified Practitioner provides an ideal training for IT specialists and trainers for the maintenance of security system. JN0-310, juniper certification exams are considered one of the best certification exams for IT personnel. HP0-W02 stands for Implementing HP StorageWorks EVA Solutions certification exams training which a valuable exam is for IT candidates. HP0-752 provides full training for IT professionals in authentic way. HP0-096 certification exams are designed to develop professional perfection in IT specialists and technicians. 9A0-044, ADOBE ACE Photoshop CS2 certification exam is very valuable for web developers and designers to enhance the professional skills. 920-136 certification exams are one of the leading exams to enhance the knowledge and professional skills of IT professionals.
Did you like this? Share it:

4 Responses to “Using a reverse Proxy with a subdomain”

  1. LaTenT  on September 28th, 2008

    Thank you for this article. I’m using sometimes anonymous surf sites for unblock sites.

    Reply

  2. Unblock Me  on January 29th, 2009

    Just wanted to thank you for a really good post. I found it quite useful and will check your site often.

    Reply

  3. tech support guy  on May 31st, 2011

    That's pretty neat discovery. Thanks for sharing!

    Reply

  4. Lorene  on December 15th, 2011

    You’ve got to be kidding me-it’s so tarnspranetly clear now!

    Reply


Leave a Reply