Serving Multiple Web Sites on OS X 10.7 Lion with the Server.app.
OS X server provides functionality to host and serve multiple virtual websites from the same host over a single (or multiple) IP address, it can run the same confgurations like a regular Linux webserver as it uses Apache under the hood, you can set this up using the command line or by using some server tools that Apple provide. This tutorial uses Server.app and Server Admin, Server app is a paid for tool downloadable at the Apple store, Server Admin is a free download, link below.
To get this running you need to have successfully configured your DNS with a fully qualified domain name for the host and have a successful output when you run the command below – this step is critical as a misconfigured DNS is really going to stuff things up:
sudo changeip -checkhostname
Starting The Webserver
To get the webserver going with the default website on the localhost
– Log into your server with Server.app.
– Enable the web server from the web service and if using php, turn it on here also
Creating the Additional DNS Zones
To serve multiple websites first up is to configure the DNS of the additional zones on your local server, you can do this using the 10.7 Server Admin tools dns service.
– Create the zone – – assign the local server as the new zones’ nameserver – in the example below the local server is server.example.com it is both the FQDN and nameserver of the local server and is also the nameserver for the newly added dns zone of seo-hub.net
– Create a record for the new zone – – assign it the same IP address as the local server in this example the record is the domain seo-hub.net
– Create a ‘www’ alias if required – so here we are resolving the ‘www‘ component so either using ‘www’ or not will resolve the domain to seo-hub.net
Add the Zone
Add the A record or Machine Record
Add the Alias (its on thr drop-down below ‘Add Record’)
Set up Additional WebSites
Go Back to Server.app to add the site and set the web root.
By default the web root in Lion Server is:
/Library/Server/Web/Data/Sites/
To host multiple sites create a new directory per site in the Sites folder. You set that in Server.app
When adding the domain name – you will get a green light if the domain has successfully been pointed to your local nameserver verifying that DNS is correct
Set the IP address, port number and web document root by going to the ‘Other’ and creating a new web root folder and lastly set the access privileges.
One odd quirk is that if you also want to serve the website with a ‘www’ prefix (which you probably would want covered) you need to add an additional domain name site with the ‘www’ prefix and point the site files folder to the same one as the domain without the ‘www’
Add a www domain and point the document root to the same domain without the ‘www’
Thats it – if you are serving the sites to the outside world don’t forget to delegate the added domains nameservers to your local server’s public IP address at the domain’s name registrar and then port forward http/https traffic from your router to your webservers internal IP address..
Also remember if using SSL that a unique IP address is required per SSL/TLS domain.
OS X Client Machine Without Server App
If the Server app is installed on your Mac this method to serve virtual hosts is preferred, as appose to a OSX client without server app – on a machine without the server app – virtual hosting is still possible. You need to edit the Apache httpd.config to allow for it. Open the file:
/etc/apache2/httpd.conf
and uncomment the include line on vhosts:
#Include /private/etc/apache2/extra/httpd-vhosts.conf
Once that is done you can add in Apache directives on virtual hosts as described here in the configuration file in the above path.
Footnote
This set up has been completed without any altering of the httpd.conf file.
A number of uers have reported that they can only get virtual hosts to run by adding a file with an Apache directive in /etc/apache2/sites/
Named 00000_MoreTestingRequired.conf with the content:
NameVirtualHost *:80
Restart Apache via Server.app and it has all come good.
However I note what should happen is that in /etc/apache2/sites/ a generated file named virtual_host_global.conf should appear with the content:
# This file is auto-generated by the web configuration # mechanism whenever settings are saved. # The Listen and NameVirtualHost directives are generated # based on the VirtualHost directive inside # each site configuration file found in this directory. # Listen *:443 NameVirtualHost *:443 Listen *:80 NameVirtualHost *:80
So if you are not getting the latter result try the above fix to see if it solves.
Since this guide I have not really used the later Mountain Lion 10.8 server instead I use the regular client to serve virtual hosts from Apache.