I installed NGINX with homebrew then I got info and followed the instructions to load the launchd plist
$ brew info nginx
nginx: stable 1.6.2, devel 1.7.7, HEAD
...
To load nginx:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist
Or, if you don't want/need launchctl, you can just run:
nginx
The problem is nginx doesn't load when I restart.
The plist looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>homebrew.mxcl.nginx</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/nginx/bin/nginx</string>
<string>-g</string>
<string>daemon off;</string>
</array>
<key>WorkingDirectory</key>
<string>/usr/local</string>
</dict>
</plist>
This is what worked for me:
sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
The trick to this is that Mac OSX won’t let anything other than “root” or “system” level services use a port number below 1024.
Read more here: http://derickbailey.com/2014/12/27/how-to-start-nginx-on-port-80-at-mac-osx-boot-up-log-in/
I stumbled upon your question because I was having the same issue. Three things helped me make it work:
root:wheel
(sudo chown root:wheel /usr/local/opt/nginx/*.plist
)/Library/LaunchAgents
instead of ~/Library/LaunchAgents
, because you probably run nginx on port 80, which requires root privileges.<string>-g</string>
and <string>daemon off;</string>
lines from the plist (before loading it with sudo launchctl load /Library/LaunchAgents/homebrew.mxcl.nginx.plist
)I'm not sure why those two lines are invalid, but I found out by trying to execute the /usr/local/opt/nginx/bin/nginx
with -g daemon off;
added to it, it also failed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With