Monday, November 12, 2012

Working with DNS and lighttpd with multiple subdomains

So since recently I had the brilliant idea of buying a proper domain, I figured it was time I setup my website again but as I've been studying in school to setup multiple sites and subdomains I figured I'd learn to do the same with my http server of choice.

I'm not going to go through the details of how I installed lighttpd since in most distros it's in your default repos, but I will describe how I've set up several subdomains.

Currently my main domain redirects here but as I also wanted to have the site I coded 4 years ago, I wanted to make it a subdomain.
I started thinking I wanted something simple so I decided to make a subdomain called old.kaizokuden.org.

After reading up on how the config file of lighttpd (/etc/lighttpd/lighttpd.conf) works I found the winning entry is structured like this:

$HTTP["host"] == "files.website.com"{
server.document-root = "/path/to/files.website.com/http"
accesslog.filename = "/var/log/lighttpd/files.website.com/access.log"
}

Where "files.website.com" is the desired subdomains address, in my case the address was to be old.kaizokuden.org.

Server.document-root, is as you'd expect the folder in which the files of the subdomain are located ex. "files.website.com".

Accesslog.filename is the log file that logs who connects to the website and such things.

This by itself was ofcourse not enough as I dont have a dns server installed on my server, so I added a sub domain to my domain at the address of "old.kaizokuden.org".
After about an hour my new page had gone live and the two pages directed to my different folders.