April 28, 2014
For the longest time I couldn’t get the piece to work, but I finally figured it out using launchctl as a somewhat basis for troubleshooting. I used homebrew to install nginx which is easier and works for the most part. First the instructions on how to install nginx using homebrew:
brew update && brew install nginx
Next what you want to do is have launchctl start nginx automatically for you. You can do this in several ways, but I’ll cover two:
For this option you will symbolic link the .plist file included with nginx to have launchctl launch nginx using the proper permissions. Then use launchctl to list the resulting loaded file
sudo ln -sfv /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
Homebrew places a symbolic link of the nginx folder inside opt making it easier for symbolic links, at least in my opinion anyways. The reasoning to remember for this is:
sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
sudo chown root:wheel /Library/LaunchDaemons/homebrew.mxcl.nginx.plist - Credit to <a href="http://localhost:4000/blog/2014/04/28/start-nginx-at-launch-on-mavericks/#comment-1767708094">Burak</a>
The reasoning behind this:
/Libraryis the system Library folder, rather than the user
~/Libraryfolder. It’s used because it needs system access, and it’s easier for all users to access it.
Next what you want to do is have launchctl load the file for you automatically:
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
-woption, otherwise it won’t load.
To troubleshoot the file loading use this:
sudo launchctl list | grep 'homebrew'
You should get a list that shows homebrew.mxcl.nginx
If you don’t care about automatic use the normal commands for it:
sudo nginx -s stop sudo nginx sudo nginx -s reload
This actually took me a bit to figure out, so I decided to make a post for future reference.
Written by Stephen Quick, a software developer based in Houston, Texas.