我正在通过brew使用nginx,它似乎已配置并正常工作-到了一定程度。我有多个主机文件(大约20个站点),并且几乎所有主机文件都可以正常工作,但是添加的任何新站点都将无法工作。
所有旧的主机文件似乎都可以正常加载,例如在端口80上使用服务器名称site.test
,但是在我的Web浏览器中添加的所有新主机文件都返回“找不到服务器”。
经过大量的故障排除和Google搜索之后,我终于发现我的设置中有些奇怪的东西,而正是这篇帖子触发了它:nginx.conf and nginx.pid users and permissions。尽管它似乎无法解决我的确切问题。
运行nginx -t
会得到:
nginx: [warn] the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/etc/nginx/nginx.conf:1
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/usr/local/var/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /usr/local/etc/nginx/nginx.conf test failed
但是,当我运行sudo nginx -t
时,我得到了:
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
我都杀死了nginx,并用brew优雅地停止了它,并用sudo重新启动了它,但是我似乎在nginx.pid中遇到了同样的问题。
启动nginx时,我使用:sudo brew services start nginx
运行ps aux | grep nginx
,返回:
Media32 7444 0.0 0.0 4339424 2016 ?? S 12:16pm 0:00.01 nginx: worker process
Media32 7443 0.0 0.0 4339424 1836 ?? S 12:16pm 0:00.00 nginx: worker process
root 7440 0.0 0.0 4297440 4876 ?? Ss 12:16pm 0:00.01 nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;
这应该是正确的,因为在nginx.conf中将我的用户设置为user Media32 staff
。
我可以提供任何其他必需的代码,但是现在我在此方面已经感到迷茫了好几天,我们将不胜感激。
更新
我似乎已经解决了这一问题,方法是编辑/etc/hosts
并添加新主机文件的记录,即。 127.0.0.1 site.test
,然后在重新加载nginx后可以正常工作,但是我从来没有做过此事,有人可以阐明为什么需要和不需要吗?
答案 0 :(得分:0)
除了将/ private / etc / hosts中的任何新主机设置为
的事实 127.0.0.1 mysite.test
是在本地添加新主机域的规则,
就我而言,我得到了一个
the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /usr/local/etc/nginx/nginx.conf:2
"/usr/local/var/run/nginx.pid" failed (13: Permission denied)
bind() to 0.0.0.0:80 failed (48: Address already in use)
,工作解决方案由以下步骤组成:
停止根进程
sudo nginx -s stop
检查进程是否停止
ps aux | grep nginx
重启过程
sudo nginx -s reload
给我错误
nginx: [error] open() “/usr/local/var/run/nginx.pid” failed (2: No such file or directory)
probabil .pid由错误的root用户启动,因为我在/usr/local/etc/nginx/nginx.conf中取消注释了.pid路径的行,然后我再次对其进行了评论
以用户身份而不是root身份启动nginx
brew services start nginx
运行命令的结果
ps aux | grep nginx
youruser 89212 0.0 0.0 4268280 644 s002 S+ 2:46PM 0:00.00 grep nginx
youruser 89179 0.0 0.0 4302204 1776 ?? S 2:45PM 0:00.00 nginx: worker process
youruser 89178 0.0 0.0 4275372 4368 ?? S 2:45PM 0:00.01 nginx: master process /usr/local/opt/nginx/bin/nginx -g daemon off;
可以看到,nginx进程以预期的用户而不是root身份启动,并且进程之间的冲突消失了,我可以访问PHP应用程序本地域。
答案 1 :(得分:0)
我已经在macOS Catalina中解决了这个问题。
sudo brew services stop nginx
sudo chmod 777 /usr/local/var/run/nginx.pid
sudo brew services start nginx
nginx -t