Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Our nginx configuration for Mac OS X

tree: 1cb65f6004

Getting Started

As our production environment is moving from Apache to Nginx, it makes more sense for our development environments to closely mirror that environment. It's going to be a bit of a journey to get there, so let's get started.

(Most of the following assumes you already have Xcode installed on your system. If not, go grab it from [[]] or the Mac App Store, though the latter costs $4.99.)

Step 1: Install Homebrew

If you're system is not new and you already have a /usr/local, your permissions may get in the way. Correct that by running:

[[ ! -d /usr/local ]] && sudo mkdir /usr/local
sudo chown -R $USER /usr/local

Install Homebrew:

ruby -e "$(curl -fsSL"

If you did have an existing /usr/local, you can see if there are any problems from what you already have in there by running:

brew doctor

Step 2: Install RVM

bash < <(curl -s

Then add the following to your ~/.bash_profile:

'[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

Step 3: Install Ruby Enterprise Edition and Passenger

. $HOME/.rvm/scripts/rvm
rvm install --force ree
rvm use ree
gem install passenger

Step 4: Install Nginx

rvm use ree
brew install nginx --with-passenger

Install the start-up plist:

if [ ! -e ~/Library/LaunchAgents ]; then
    mkdir ~/Library/LaunchAgents

cp /usr/local/Cellar/nginx/`ls -1 /usr/local/Cellar/nginx| tail -n 1`/org.nginx.nginx.plist ~/Library/LaunchAgents

Step 5: Install MongoDB

If you previously had MongoDB installed you will need to unload mongodb and remove the launch daemon. Correct that by running:

sudo launchctl unload /Library/LaunchDaemons/org.mongodb.mongod.plist
sudo rm -r /Library/LaunchDaemons/org.mongodb.mongod.plist

Install MongoDB:

brew install mongodb

Read the Caveats presented after installation about installing or upgrading the launch daemon.

Check that MongoDB is running:


Step 6: Install MySQL

brew install mysql

Note the instructions for copying the .plist file if you want to have MySQL automatically start when you log in.

Step 7: Install PHP (optionally, but recommended) and spawn-fcgi

brew create

When an editor is opened up with the "formula", replace it with the contents of [[]].

If libpng is somehow broken (like Jamie's)

brew install

Next, Install PHP

brew install php --with-mysql

Then install spawn-fcgi:

brew install spawn-fcgi

Download a launchctl plist file to ensure this PHP server is running:

cd ~/Library/LaunchAgents
curl > net.lighttpd.spawn-fcgi.plist
launchctl load -w ~/Library/LaunchAgents/net.lighttpd.spawn-fcgi.plist

Step 8: Back to nginx

Let's now replace the stock config with what we've got in this repo:

cd /usr/local/etc
mv nginx nginx.orig
# you might want to fork this repo so you can make your own changes...
# if so, go here: [[]]
git clone

# all configs are going to point to /usr/local/sites, so let's link this
# up to your home...
cd /usr/local
ln -s ~/Sites sites

Now start it up with launchctl:

launchctl load -w ~/Library/LaunchAgents/org.nginx.nginx.plist

Step 8(a): Port 80 Forwarding (optional, but recommended)

Nginx runs under your own user, so it can't use a privileged port. Instead it runs on port 8080. You may want to have it run on port 80, and if so you can add a simple firewall script to forward the port. (This is totally optional.)

cd /Library/LaunchDaemons
sudo curl -O
sudo launchctl load -w com.coverallcrew.firewall.plist

If you want an easy way to restart nginx, add the following to your ~/.bash_profile file:

alias restart-nginx="kill \`cat /usr/local/var/run/\`"


If you look in /usr/local/etc/nginx/upstreams, you will see all of the "upstreams", or "proxies" we have defined. Note that the attendease API is set to run on port 4000, and so to start that up on that port, run:

cd /usr/local/sites/attendease
rails s -p 4000
Something went wrong with that request. Please try again.