启动时没有在启动时加载nginx

时间:2014-12-18 18:53:14

标签: nginx plist homebrew launchd

我用自制软件安装NGINX然后我得到了信息并按照说明加载了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

问题是我重新启动时没有加载nginx。

plist看起来像这样:

<?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>                                                                                                                                                                                                                                                

2 个答案:

答案 0 :(得分:9)

这对我有用:

sudo cp /usr/local/opt/nginx/*.plist /Library/LaunchDaemons
sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.nginx.plist
  

这方面的诀窍是Mac OSX除了“root”之外不会放任何东西   或“系统”级服务使用低于1024的端口号。

在此处阅读更多内容:http://derickbailey.com/2014/12/27/how-to-start-nginx-on-port-80-at-mac-osx-boot-up-log-in/

答案 1 :(得分:1)

我偶然发现了你的问题,因为我遇到了同样的问题。有三件事让我有所帮助:

  • 将plist文件的所有权更改为root:wheelsudo chown root:wheel /usr/local/opt/nginx/*.plist
  • /Library/LaunchAgents而不是~/Library/LaunchAgents中创建符号链接,因为您可能在端口80上运行nginx,这需要root权限。
  • 从plist中删除<string>-g</string><string>daemon off;</string>行(在使用sudo launchctl load /Library/LaunchAgents/homebrew.mxcl.nginx.plist加载之前)

我不确定为什么这两行是无效的,但我发现通过尝试添加/usr/local/opt/nginx/bin/nginx -g daemon off;来发现它,它也是失败。