Monday 2 November 2009

Virtual host order on Mac OS X Server

I am in the process of converting my website forwarding setup to actual host names (A-records). I was quite reluctant to do this at first, because I could not oversee the consequences and googling didn't reassure me either. But on the LDC09, I talked to Chris who kindly explained to me how easy and unproblematic this actually is. Being a sceptic, I did not start by converting all entries at once, but I do convert one entry per day - when it succeeds.

The first one went wrong already because of my logical thinking as a programmer. I pointed the subdomain name to our Mac OS 10.4 server and setup the site there, putting the default (*) at the bottom. Hey, where is a catch-all entry for!? It belongs at the end, just like with a if/else/end - the last 'else' is the catch-all. But from that moment on, every site landed on my newly created domain, so I quickly swapped the two site entries so that the catch-all was the first one again. Now it worked.

So I made a whole plan : setup a subdomain on one afternoon and check if it works the next morning. This way I set some others up on this 10.4 server and they all work.

Then comes the day I needed to setup the same construct on a Mac OS 10.5 Server. So I deleted the website forwarding entry, created the A-record, created the site on the OS X server, leaving the catch-all at the top and waited until the next morning. The domain name worked all right, but landed on /library/webserver/documents/ (the www-root) instead of the path I put into the site. I have been struggling for two days with this 10.5 server. I checked and double checked, changed the site's path, etc.. Nothing worked, it kept landing on the webroot. And today I thought, what if I swap the site entries and put the default (*) at the bottom (as I did at first on the 10.4 server) and ... it worked! I tested the other sites which have no domain name yet (website forwarding) and they all work ok.

So the order for site entries on MacOS 10.4 Server differs from MacOS 10.5 Server. You can see that in the
sites folder inside the Apache folder (/etc/httpd/ on 10.4 and /etc/apache2/ on 10.5). Sites are loaded by including sites/*.conf and the order is determined by the name of the conf-files (10.5 example):

-rw-r--r-- 1 root wheel 1659 Nov 1 17:12 sites/0000_any_80_my.site.com.conf
-rw-r--r-- 1 root wheel 1857 Nov 1 17:12 sites/0001_any_80_default.conf
-rw-r--r-- 1 root wheel 566 Nov 1 17:12 sites/virtual_host_global.conf


So it seems on 10.5 the catch-all sites are loaded last.