nginx.conf和nginx.pid的用户和权限 [英] nginx.conf and nginx.pid users and permissions

查看:456
本文介绍了nginx.conf和nginx.pid的用户和权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正开始在以下级别查看我的NGINX error.log文件:警告...这可能是一个愚蠢的主意,当我找出发生的任何错误时,这会导致我的服务器崩溃,但是,嘿,我们很讨厌这就是为什么我们在这里.

I'm embarking on watching my NGINX error.log files at level: warn... probably a silly idea and will cause me to crash my server as I work out any bugs happening, but hey, we're nerds and this is why we're here.

每次启动服务器时,我都会看到[警告]和[emerg]弹出窗口,显示为:

I'm noticing a [warn] and an [emerg] pop up every time I restart my server, which shows:

[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文件的顶部显示为:

The top of my nginx.conf file reads:

user www-data;
worker_processes auto;
pid /run/nginx.pid;

对我来说,向我展示了一些东西.

Which to me, shows me a few things.

  1. 我正在与以下用户一起运行NGINX:www-data.
  2. 自动调整允许的工作进程数.
  3. 我的PID文件/信息存储在/run/nginx.pid中.

该错误告诉我NGINX没有访问/run/nginx.pid的权限,这使我看到了该文件的用户权限.

The error tells me that NGINX doesn't have permission to access /run/nginx.pid, which led me to see the user permissions for said file.

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如何设法创建具有根所有权的主进程,而现在辅助进程由www-data拥有?

Now, can somebody out there tell me why, or how the hell NGINX has managed to create the master process with root ownership, and now the worker processes are owned by www-data?

或更重要的一点是,有人对我要解决的[emerg]错误有何建议?

Or more to the point, anybody have some suggestions on what to do about this [emerg] error I'm getting?

我的第一个想法是尝试更改/run/nginx.pid文件的所有权,并查看NGINX的喜欢程度,但是我有一种感觉,即使这次是手动执行此操作,当我重新启动服务器时,我会遇到同样的问题.

My first thought is to just try and change the ownership of the /run/nginx.pid file and see how NGINX likes it, but I kind of feel that even if I do that manually this time, when I restart the server, I'll run into the same problem.

我的第二个想法可能是我在NGINX中定义了我的工作进程启动的其他地方.

My second thought is maybe there is somewhere else that I define my worker process initiation within NGINX..

谢谢.

EDIT

EDIT

/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

推荐答案

我今天在Centos 7服务器上遇到了相同的错误.

I got the same error on my Centos 7 server today.

nginx.pid"失败(13:权限被拒绝)

nginx.pid" failed (13: Permission denied)

对我来说,事实证明这是SELinux的问题.我做了以下操作以使其再次起作用:

For me, it turned out to be a problem with SELinux. I did the following to make it work again:

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--.根根system_u:object_r:httpd_var_run_t:s0 nginx.pid

-rw-r--r--. root root system_u:object_r:httpd_var_run_t:s0 nginx.pid

这篇关于nginx.conf和nginx.pid的用户和权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆