Introduction

Say you have a bunch of static HTML pages generated using Sphinx, Jekyll etc. Whenever the contents are updated, instead of having to copy them over to the ~/Sites directory, it might be a good idea to just create a symbolic link at ~/Sites and pointing it at the output directory of your Sphinx/Jekyll project directory.

The Steps

  1. Edit <username>.conf under /private/etc/apache2/users to add FollowSymLinks directive:

     <Directory "/Users/<username>/Sites/">
         Options Indexes MultiViews FollowSymLinks
         AllowOverride None
         Order allow,deny
         Allow from all
     </Directory>
    
  2. Edit httpd.conf under /private/etc/apache2 to uncomment the line under “# Virtual hosts”:

     # Virtual hosts
     Include /private/etc/apache2/extra/httpd-vhosts.conf
    
  3. Edit httpd-vhosts.conf under /private/etc/apache2/extra to define the virtual directory:

     <VirtualHost *:80>
         DocumentRoot "/Users/<username>/Sites"
         ServerName localhost
     </VirtualHost>
    
     <VirtualHost *:80>
     	<Directory /Users/<username>/Sites/<sitename>
         	Options +FollowSymLinks +SymLinksIfOwnerMatch
         	AllowOverride All
     	</Directory>
     	DocumentRoot "/Users/<username>/Sites/<sitename>"
     </VirtualHost>
    
  4. Create a symlink to the HTML pages directory generated by Sphinx or Jekyll.

     $ ln -s /path/to/generated/html/pages ~/Sites/<sitename>
    
  5. Restart Apache.

  6. The contents are now accessible via http://localhost/<sitename>.

  7. Done.

Serving Jekyll Site with Built-in Apache Server

I have some difficulties serving static files from Jekyll on OS X built-in Apache server, which apparently isn’t as straightforward as creating a symlink to the _site directory. Some googling also didn’t turn up much information. KIV for now.

Reference



Published

25 July 2012

Tags


Table of Contents