问题描述
刚开始安装的时候不行, 后来改成开发版也不行:
brew install nginxbrew upgrade --devel nginx
通过 launchctl 命令来启动, 还试过多次 unload 和 load:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.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>
监听 log 有看到报错, 但看不岀来具体信息:
➤➤ tail -f /var/log/system.log
Feb 20 18:28:14 Air com.apple.launchd.peruser.501[244] (homebrew.mxcl.nginx[1200]): Exited with code: 1
另外手动 sudo nginx 或者配置文件里的路径又是对的,对照 GitHub 上 Homebrew 的代码, 我的 Nginx 配置又不应该错的...https://github.com/Homebrew/homebrew/blob/master/Library/Formula/nginx.rb#L138
现在看文件的权限是:
➤➤ ls -l /usr/local/opt/nginx/bin/nginx-r-xr-xr-x 1 chen admin 675992 Feb 11 10:16 /usr/local/opt/nginx/bin/nginx➤➤ l -l /usr/local/Cellar/nginx/1.5.8/bin/nginx-r-xr-xr-x 1 chen admin 675992 Feb 11 10:16 /usr/local/Cellar/nginx/1.5.8/bin/nginx
visudo 里写的权限是:
32 33 # User privilege specification 34 root ALL=(ALL) ALL 35 %admin ALL=(ALL) ALL 36 37 # Uncomment to allow people in group wheel to run all commands 38 # %wheelALL=(ALL) ALL 39 40 # Same thing without a password 41 # %wheelALL=(ALL) NOPASSWD: ALL 42 chen ALL=(ALL) NOPASSWD: ALL
求指点...
chmod u+s 不成功..
➤➤ sudo chmod u+s /usr/local/Cellar/nginx/1.5.8/bin/nginx➤➤ ps aux | grep nginxnobody 7254 0.0 0.0 2458140 916 ?? S 7:49PM 0:00.00 nginx: worker processroot 7253 0.0 0.0 2448924 360 ?? Ss 7:49PM 0:00.00 nginx: master process nginxchen 7293 0.0 0.0 2432784 604 s002 S+ 7:52PM 0:00.00 grep nginx➤➤ sudo nginx -s stop➤➤ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plisthomebrew.mxcl.nginx: Already loaded➤➤ launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist➤➤ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist➤➤ ps aux | grep nginxchen 7316 0.0 0.0 2432784 608 s002 S+ 7:52PM 0:00.00 grep nginx➤➤ sudo nginxnginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)➤➤ nginxnginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)➤➤ sudo chmod u-s /usr/local/Cellar/nginx/1.5.8/bin/nginx➤➤ nginxnginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)➤➤ sudo nginx➤➤
问题解答
回答1:估计是nginx执行权限问题,参见这篇文章。
sudo chown root:wheel /usr/local/Cellar/nginx/1.2.6/sbin/nginxsudo chmod u+s /usr/local/Cellar/nginx/1.2.6/sbin/nginx