Install nginx with Homebrew on Mac OS X

I needed to install nginx to check my last project’s behavior behind a reverse proxy. This post isn’t about how to configure nginx for production – you’ll find that on Google (and you may use Linux over Mac 😉 ). This post is only about the installation part, like the previous ones as a reminder for future me when I’ll make this install again.

Install nginx

brew update
brew install nginx

Check if it works

  • nginx
  • go to http://localhost:8080
  • nginx -s stop

Version your nginx config with git

This part is optional, but it comes very handy to have your nginx folder config versioned, so that you wont have to make *.bak files 😉 …

Don’t worry, versionning the /usr/local/etc/nginx folder won’t mess with your homebrew git repo, if nano /usr/local/.gitignore you’ll see that basically, anything but the Library folder is not tracked.

cd /usr/local/etc/nginx
git init
git add .
git commit -m "original config"

There you are safe, you can mess all you want with your nginx conf …

Logs

You’ll find the error and access logs here : /usr/local/var/log/nginx/

You’ll find the file containing the nginx’s pid here : /usr/local/var/run/nginx.pid

Notes

Reminder : Homebrew will set the port to 8080 by default in the config so that you could run nginx without sudo. If you bind your server to the port 80, you’ll have to sudo nginx.

Leave a Reply

Your email address will not be published. Required fields are marked *