Configure a Reverse Proxy with Apache

In a previous post, I discussed the details required to set up Subsonic on Ubuntu Server. The problem with Subsonic is that it runs on Tomcat on a non-standard port. The rest of my web applications run in Apache on port 80. Therefore, it would be nice if instead of having to go to http://athos.zacintosh.com:8180/subsonic/, I could simply go to http://athos.zacintosh.com/subsonic/. The solution is called a reverse proxy. Reverse proxies can do things like load balance between multiple web servers or simply make resources on an internal web server available externally. In this case, I am using a reverse proxy to make a web application available on a different port available on the standard port 80.

The set up is fairly simple. On Ubuntu, it should be as simple as issuing this command (as root) to enable the proxy modules:

a2enmod proxy_http

Next I inserted the following into /etc/apache2/conf.d/subsonic.conf to make it available on all websites running on my server. If you only wanted it to be available for a single website, you could insert this into a site inside of /etc/apache2/sites-available/.

ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
    Order allow,deny
    Allow from all
</Proxy>
ProxyPass /subsonic/ http://localhost:8180/subsonic/
ProxyPassReverse /subsonic/ http://localhost:8180/subsonic/

The configuration above says to not proxy all requests (not act as a forward proxy server). The ProxyPass and ProxyPassReverse set up the actual retrieval of data from Subsonic running on Tomcat. You need to replace the localhost and the port number with the specific items for your configuration. Finally, you need to reload the Apache configuration:

/etc/init.d/apache2 force-reload

Now Subsonic should be available on port 80 just like everything else running on your web server with Apache.

AWStats on Ubuntu Server

Since I am running this blog on my own server, I decided I should probably set up some log parsing. My personal website is hosted by Nearly Free Speech, and they provide AWStats for statistics. Another site I administer is hosted by DreamHost. DreamHost provides Analog web statistics. After playing with both, I decided to use AWStats.

Ubuntu Tutorials has provided a nice tutorial about setting up AWStats on Ubuntu. I configured my sites individually with no default site in the following files:

/etc/awstats/awstats.blog.lundscape.com.conf
/etc/awstats/awstats.claude.zacintosh.com.conf
/etc/awstats/awstats.wiki.lundscape.com.conf

This means that browsing to “http://domain.tld/awstats/awstats.pl” as they suggest won’t work. Instead, I append the site to the end of the string like this: “http://domain.tld/awstats/awstats.pl?config=blog.lundscape.com”.

Also, rather than adding entries to my crontab, I simply added a script to my “/etc/cron.hourly”:

#! /bin/bash

/usr/lib/cgi-bin/awstats.pl -config=blog.lundscape.com \
	-update > /dev/null 2>&1
/usr/lib/cgi-bin/awstats.pl -config=claude.zacintosh.com \
	-update > /dev/null 2>&1
/usr/lib/cgi-bin/awstats.pl -config=wiki.lundscape.com \
	-update > /dev/null 2>&1

This automatically updates my AWStats every hour whether I view my statistics in a web browser or not.