Launchd not loading nginx on startup
Asked Answered
W

2

5

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>                                                                                                                                                                                                                                                
Wenn answered 18/12, 2014 at 18:53 Comment(0)
W
11

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/

Wenn answered 24/8, 2015 at 16:19 Comment(0)
E
1

I stumbled upon your question because I was having the same issue. Three things helped me make it work:

  • change ownership of plist file to root:wheel (sudo chown root:wheel /usr/local/opt/nginx/*.plist)
  • create the symlink in /Library/LaunchAgents instead of ~/Library/LaunchAgents, because you probably run nginx on port 80, which requires root privileges.
  • Remove the <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.

Emmaline answered 24/8, 2015 at 7:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.