Subdomains with Apache 2

This semester at university I’m doing a group project module. Most of the group are on IRC a lot of the time, but it doesn’t really provide for reliable collaboration. I’d seen punBB being used a lot in recent months and knew it was basically a no-frills discussion forum that was really fast (and it validates as XHTML Strict! woo!). I’ve been wanting to give it a shot for ages – and this was my excuse. Thing is, with this blog being here, I’d have to create a sub-domain to use.

First of all, I updated the DNS records on my American server (which manages this domains DNS) so that it included a wildcard record.

*.davidwinter.me.uk. A 123.456.789.000

This means that any request to a sub-domain gets forwarded onto my server here at home. It’s a ton easier than having to set up each sub-domain a separate name record.

However, my good friend Greg told me that it’s important to also include a record for the domain name itself:

davidwinter.me.uk. A 123.456.789.000

With that all set up, and changes applied – I moved onto configuring my server at home.

I won’t bore you with all the problems I had getting this set-up correct. But in a sentence, the problem I was having was that only the first virtual server was displayed regardless of what sub-domain I used.

The solution?

In the Apache config file (httpd.conf), place this at the very top:

NameVirtualHost 192.168.0.1:80

Where 192.168.0.1 is the internal IP of your server running Apache.

Then, for each virtual host entry in the configuration file, set them up using:

<VirtualHost 192.168.0.1:80>

Using the same internal IP you specified in NameVirtualHost.

Save the file and restart Apache. All should work fine.

For my set-up, I still added DNS records for the sub-domains locally on my home server so that I could use the domains on my internal network.

2006-02-14 [, , ]

Comments

Powered by WP Hashcash