ubuntu + apache + ssl + mod_rewrite proxy

October 10, 2006

I wanted to be able to get to a couple of internal only sites securely from outside of my home network. So, I added an https virtual server with password that proxies the internal stuff. It goes a little something like this:

enable the ssl module:

a2enmod ssl

make a cert

apache2-ssl-certificate

make an htpasswd file

htpasswd -c /etc/apache2/utility.passwd admin

setup apache to use port 443

echo “Listen 443″ >> /etc/apache2/ports.conf

create your virtual server

vi /etc/apache2/sites-available/utility_proxy

NameVirtualHost *:443
<VirtualHost *:443>
    ServerName yourserver.yourdomain.com
    SSLEngine On
    SSLCertificateFile /etc/apache2/ssl/apache.pem
    <Location "/">
        AuthType Basic
        AuthName "Utility Server"
        AuthUserFile /etc/apache2/utility.passwd
        Require valid-user
    </Location>
    RewriteEngine On
    DocumentRoot /var/www
    #add rules here for your internal stuff
    RewriteRule ^/routerproxy/(.*) http://192.168.1.254/$1 [P]
    RewriteRule ^/localhost8080/(.*) http://localhost:8080/$1 [P]
</VirtualHost>

enable the virtual

ln -s /etc/apache2/sites-available/utility_proxy /etc/apache2/sites-enabled/utility_proxy

restart apache

/etc/init.d/apache2 restart

This is assuming you already have some means of getting to this server from the outside.  Your proxies will be availible at https://yourserver.yourdomain.com/routerproxy/ etc.  I had some trouble with having authentication on when the site that was being proxied also had authentication. So I had to change the Location tag so that rewrite rule was outside of the authenticaion in my apache server and only used the authentication on the proxied server.