自制Nginx未运行,但表示已在brew服务中运行

自制Nginx未运行,但表示已在brew服务中运行,nginx,homebrew,osx-elcapitan,Nginx,Homebrew,Osx Elcapitan,我有OSX El Capitan。我通过自制安装了Nginx Full。我应该能够启动和停止服务 brew服务Nginx全面启动 我运行了这个命令,它的启动似乎没有问题。我使用检查正在运行的服务 brew服务列表 表示Nginx完整服务正在运行。当我跑的时候 htop 要查看运行Nginx的所有内容,Nginx不会显示,服务器也不会处理请求 试着用“sudo”启动它,即使公式上说 默认端口已在/usr/local/etc/nginx/nginx.conf中设置为8080,以便 nginx可以在没

我有OSX El Capitan。我通过自制安装了Nginx Full。我应该能够启动和停止服务

brew服务Nginx全面启动

我运行了这个命令,它的启动似乎没有问题。我使用检查正在运行的服务

brew服务列表

表示Nginx完整服务正在运行。当我跑的时候

htop

要查看运行Nginx的所有内容,Nginx不会显示,服务器也不会处理请求

试着用“sudo”启动它,即使公式上说

默认端口已在/usr/local/etc/nginx/nginx.conf中设置为8080,以便 nginx可以在没有sudo的情况下运行

这对我很有用:

sudo brew服务启动nginx

由于错误,nginx无法启动,但brew服务未与您进行通信。 正如其他用户所建议的那样,用sudo运行它只是掩盖了问题。如果您直接运行
nginx
,您可能会看到,实际上存在导致nginx中止的配置或权限问题。就我而言,这是因为它无法写入错误日志:

nginx: [alert] could not open error log file: open() "/usr/local/var/log/nginx/error.log" failed (13: Permission denied)
2020/04/02 13:11:53 [warn] 19989#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/etc/nginx/nginx.conf:2
2020/04/02 13:11:53 [emerg] 19989#0: open() "/usr/local/var/log/nginx/error.log" failed (13: Permission denied)
最后一个错误导致nginx无法启动。您可以通过以下方式使自己成为日志的所有者:

sudo chown-R$(whoami)/usr/local/var/log/nginx/

这将导致随后的配置错误写入错误日志,即使homebrew服务目前未在stderr/stdout中报告这些错误


我打开了一个关于此的问题:

首先停止它,然后使用
sudo
。切勿使用sudo强制启动。下面是alexw的答案,这非常有效。与其用sudo强制它,不如修复根本问题,并在自己的用户下运行它。谢谢。我遇到了一个类似的问题,但与博士后。我怎样才能找出错误的原因?永远不要使用sudo来强制启动。下面是alexw的答案,因为端口80!非常感谢。
nginx: [alert] could not open error log file: open() "/usr/local/var/log/nginx/error.log" failed (13: Permission denied)
2020/04/02 13:11:53 [warn] 19989#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/etc/nginx/nginx.conf:2
2020/04/02 13:11:53 [emerg] 19989#0: open() "/usr/local/var/log/nginx/error.log" failed (13: Permission denied)