我用自制软件安装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>
答案 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)
我偶然发现了你的问题,因为我遇到了同样的问题。有三件事让我有所帮助:
root:wheel
(sudo chown root:wheel /usr/local/opt/nginx/*.plist
)/Library/LaunchAgents
而不是~/Library/LaunchAgents
中创建符号链接,因为您可能在端口80上运行nginx,这需要root权限。<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;
来发现它,它也是失败。