Launchd does not load nginx on startup
I installed NGINX with homebrew, then got info and followed instructions to download the launcher plugin
$ 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
Problem: nginx won't load on reboot.
Plis 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>
source to share
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 is that Mac OSX does not allow anything other than "root", or the "system" service level uses a port number below 1024.
More details here: http://derickbailey.com/2014/12/27/how-to-start-nginx-on-port-80-at-mac-osx-boot-up-log-in/
source to share
I came across your question because I had the same problem. Three things helped me get it working:
- change ownership of plist file to
root:wheel
(sudo chown root:wheel /usr/local/opt/nginx/*.plist
) - create a symbolic link in
/Library/LaunchAgents
instead~/Library/LaunchAgents
, because you are probably running nginx on port 80 which requires root privileges. - Remove lines
<string>-g</string>
and<string>daemon off;</string>
from plist (before uploadingsudo launchctl load /Library/LaunchAgents/homebrew.mxcl.nginx.plist
)
I'm not sure why these two lines are not valid, but I found that I tried to execute appended to it /usr/local/opt/nginx/bin/nginx
with -g daemon off;
, it also failed.
source to share