Hosting Multiple Websites on OS X Server

This article takes a look at how to host multiple sites in different directories on OS X Server (I have tested this on OS X 10.11 and Server.app version 5, it may well work on other versions but I can not verify this). To make these changes it is recommended that you backup the files being changed first. You will also need your favourite text editor, mine is TextWrangler.

This article assumes that you have already added your website to Server.app and set it to look at the directory in the GUI. The following needs to be done to get the directory resolving via a web browser.

Firstly you want to navigate to the following folder:

/etc/apache2/

Copy the following file to your desktop:

httpd.conf

Open the file in your text editor of choice and find the following line:

#Include /private/etc/apache2/extra/httpd-vhosts.conf

Uncomment the line so it looks like this:

Include /private/etc/apache2/extra/httpd-vhosts.conf

Save the file and move it back to the apache2 folder.

Next navigate to:

/etc/apache2/extra/

And copy the following file to your desktop:

httpd-vhosts.conf

Once open in your text editor, scroll to the end of the file and add the following (being sure to edit the paths to the path of your web directory:

<VirtualHost *:80>
DocumentRoot "/Path/On/Your/Server/Web/Directory"
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "/Path/On/Your/Server/Web/Directory"
ServerName fqdn.of.server
ErrorLog "/private/var/log/apache2/dummy-host.example.com-error_log"
<Directory "/Path/On/Your/Server/Web/Directory">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

You can multiple of these for however many sites you want to add. Save the file and move it back to the directory overwriting the original file.

Next navigate to:

/etc/

And copy the following file to your Desktop:

hosts

Open the file and at the end of it add the record of the site you want to add, e.g:

127.0.0.1 fqdn.of.server

Save it and move it back to the folder overwriting the original.

Restart the websites service in Server.app if it is already running. Open your web browser and type in the address of the website you have added, it should resolve as expected.

 

Print Friendly
  • Tony Simek

    Very helpful research as always! Thank you!