Access Sym-Linked Directory in OS X Sites
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
-
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>
-
Edit httpd.conf under /private/etc/apache2 to uncomment the line under “# Virtual hosts”:
# Virtual hosts Include /private/etc/apache2/extra/httpd-vhosts.conf
-
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>
-
Create a symlink to the HTML pages directory generated by Sphinx or Jekyll.
$ ln -s /path/to/generated/html/pages ~/Sites/<sitename>
-
Restart Apache.
-
The contents are now accessible via http://localhost/<sitename>.
-
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.