Installing Nginx On OSX

joseph misiti
Computer Science,  Math, and Statistics
2 min readApr 17, 2013

I am developing Django sites on my local machine and wanted to use Nginx as a front-end proxy to serve static content. Nginx needs to run on port 80, and proxy all non-static requests to Django's default development server, while runs on port of 8000. This is how you go about installing it:

1. If you havn't installed it already, install homebrew. Once homebrew is installed, use it to install nginx on your local machine:

$ brew install nginx

2. After nginx is successfully installed, perform the sbin copy operations found here:

http://wiki.summercode.com/running_homebrewed_nginx_with_sudo_on_mac_os_x

3. The nginx.conf file you need to modify should be living in this directory:

/usr/local/etc/nginx

Now, modify your nginx conf. All of the paths should be absolute paths to the directories on your local machine. Here is an example of my nginx.conf:

https://gist.github.com/3880234

This nginx.conf is used to serve my website (www.socialq.com) locally.

3. After you have modified your nginx.conf, you need to update your sudo permissions so that you are not prompted for a password when you type sudo. This is because running anything on port 80 requires root permissions.To change these permissions follow these steps:

$ sudo visudo

Find the following lines in your file

# User privilege specification

root ALL=(ALL) ALL

%admin ALL=(ALL) ALL

And change them to look like this:

# User privilege specification

root ALL=(ALL) ALL

%admin ALL=(ALL) NOPASSWD:ALL

<YOUR-USER-NAME> ALL=(ALL) NOPASSWD:ALL

This will remove the password prompt and set your username to the appropriate permissions.

4. Finally, create an nginx plist so you can start and stop nginx from the command line:

$ vi ~/Library/LaunchAgents/org.nginx.plist

Here is an example of my plist:

https://gist.github.com/3880270

5. You can now start/stop nginx with the following commands:

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

$ launchctl unload -w ~/Library/LaunchAgents/org.nginx.plist

--

--