我正在开始观察我的NGINX error.log文件:警告......可能是一个愚蠢的想法,并会导致我崩溃我的服务器,因为我解决了发生的任何错误,但是,嘿,我们是书呆子和这就是为什么我们在这里。
每次重新启动服务器时,我都会注意到[warn]和[emerg]弹出窗口,显示:
[warn] 8041#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
[emerg] 8041#0: open() "/run/nginx.pid" failed (13: Permission denied)
我的nginx.conf文件的顶部是:
user www-data;
worker_processes auto;
pid /run/nginx.pid;
对我来说,给我看了几件事。
错误告诉我NGINX没有访问/run/nginx.pid的权限,这导致我看到了所述文件的用户权限。
sudo ls -la /run/nginx.pid
揭示了:
-rw-r--r-- 1 root root 5 Jun 18 05:34 /run/nginx.pid
然后尝试:
ps -ef | grep nginx
产生
root 5914 1 0 05:34 ? 00:00:00 nginx: master process /u
www-data 5917 5914 0 05:34 ? 00:00:00 nginx: worker process
划伤头
现在,有人可以告诉我为什么,或者NGINX如何设法创建具有root所有权的主进程,现在工作进程是由www-data拥有的?
或者更重要的是,任何人都有一些关于如何应对这个[emerg]错误的建议?
我的第一个想法是尝试更改/run/nginx.pid文件的所有权并查看NGINX是如何喜欢它的,但我觉得即使我这次手动执行此操作,当我重新启动服务器时,我会遇到同样的问题。
我的第二个想法是,我可以在NGINX中定义我的工作流程启动的其他地方。
感谢。
修改
/etc/systemd/system/multi-user.target.wants/nginx.service
文件的内容是:
[Unit]
Description=A high performance web server and a reverse proxy server
After=network.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -q -g 'daemon on; master_process on;'
ExecStart=/usr/sbin/nginx -g 'daemon on; master_process on;'
ExecReload=/usr/sbin/nginx -g 'daemon on; master_process on;' -s reload
ExecStop=/usr/sbin/nginx -s quit
[Install]
WantedBy=multi-user.target
答案 0 :(得分:0)
我今天在Centos 7服务器上遇到了同样的错误。
nginx.pid"失败(13:许可被拒绝)
对我而言,事实证明SELinux存在问题。我做了以下工作让它再次运作:
systemctl stop nginx
touch /var/run/nginx.pid
chcon -u system_u -t httpd_var_run_t nginx.pid
systemctl start nginx
正在运行
ls -Z nginx.pid
应输出
-rw-R - R--。 root root system_u:object_r:httpd_var_run_t:s0 nginx.pid
答案 1 :(得分:0)
就我而言,我得到了一个
"/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应用程序本地域。