Apache 2 Web Server Configuration


I finally got my site backup up and working on a new server. A very quiet Dell Studio Slim 540s, running Ubuntu 8.10 and apache 2. I had been running apache (1) on an old hand built Celeron 500MHz server that made a lot of noise and had some hard drives dying. It was long over due for an upgrade.

Installing Ubuntu 8.10 was easy enough as was moving subversion over (it was the first thing I did). All I needed to do for subversion was to rsync the directory over along with all of the other files I was copying, and start the service. Once I had my ssh keys setup, subversion worked just like it did on the old server.

Getting apache to work correctly, however, was not nearly as easy. The server itself worked fine out of the box, but I have a lot of domain names that I proxy with apache and it took me a while to figure out how to set those up correctly. After looking at far too many examples online I finally got it working. The following are the steps I took, and hopefully this will save someone else the time it took me to figure it out. Note that all of these commands need to be run as root or via sudo.

First I added some needed modules:

a2enmod proxy proxy_connect proxy_http proxy_ftp userdir

Then setup the proxy configuration by editing /etc/apache2/mods-available/proxy.conf:

<IfModule mod_proxy.c>
    ProxyRequests Off

    <Proxy *>
        AddDefaultCharset off
        Order deny,allow
        Deny from all
        Allow from all

    ProxyVia On

I did not need to make any changes to the default userdir.conf.

Now create a site file for every site you run. Here is mine for nulldot as an example:

Edit /etc/apache2/sites-enabled/nulldot:

<VirtualHost *:80>
    ServerName nulldot.net
    ServerAlias nulldot.net *.nulldot.net

    ProxyPass / http://localhost/~kyle/blog/
    ProxyPassReverse / http://localhost/~kyle/blog/

Obviously, replace nulldot.net with your domain name and point the ProxyPass and ProxyPassReverse lines to your target directory.

Then enable the site with:

a2ensite nulldot

Now restart apache2 and hopefully everything works:

/etc/init.d/apache2 restart

Getting information off the Internet is like taking a drink from a fire hydrant.

– Mitchell Kapor

Tags: apache software