Nginx alongside Apache on OSX

The other day I wanted to experiment with the superfast nginx server on osx for static files, and to use the built-in apache webserver as power unit to process the dynamic content.

Although not very hard to setup, there are some thing you should bear in mind:

Anyhow, let’s get on with it. Please not that I did not come up with all this myself, I found a lot of information scattered through different tutorials, which will be listed below. All credits to those authors!

Installation

brew install nginx

Installation done! On to the configuration

Configuration

Nginx

First, let’s set up nginx so it uses the somewhat cleaner “sites-enabled/sites-available” structure. Some might already seen it on apache2 or somewhere else, and I find it cleaner than putting all your virtual hosts in one (or several) file. This way, for each site you add you create the config file in the sites-available folder, then symlink it in the sites-enabled folder and just have nginx to load all the files in the sites-enabled folder. That way, whenever you temporarly want do disable a virtual host, you can just remove the symlink, and not have to remove the actual config file (you might want to keep it for future reference).

sudo nginx

Apache

Hosts & Go!

Now just update your hosts file ( /etc/hosts ) to include your newly created server:
127.0.0.1 dropbox.local

And point your browser to http://dropbox.local. You should see the directory listing of all your folders, or if you planted a site there, it should run! If you do run into errors, first check out both the nginx and apache error logs in the Console, it might help you.

Credits

Big thanks to the following persons for their great articles and posts on forums: