权限 – Systemd无法在重新启动时启动Nginx,但它可以手动运行

每次重启时都是我的情况:

$systemctl --Failed
UNIT          LOAD   ACTIVE SUB    DESCRIPTION
Nginx.service loaded Failed Failed A high performance web server and a reverse proxy server
...
$Nginx -t
Nginx: the configuration file /etc/Nginx/Nginx.conf Syntax is ok
2014/01/18 05:44:47 [emerg] 254#0: open() "/run/Nginx.pid" Failed (13: Permission denied)
Nginx: configuration file /etc/Nginx/Nginx.conf test Failed
$cd /run
$ls -al | grep Nginx
$sudo systemctl start Nginx
$ls -al | grep Nginx
-rw-r--r--  1 root     root        4 Jan 18 06:27 Nginx.pid

我不明白Nginx.pid在创建之前可能会有不正确的权限,或者解决这个问题的方法.

我正在使用Arch而且我已经看到了与chroot-jail相关的类似问题,但我没有在chroot中安装Nginx.

解决方法:

问题似乎是您正在使用非特权用户来测试Nginx配置.测试发生时,它会尝试创建/run/Nginx.pid,但会失败,这会导致配置测试失败.尝试以root身份运行Nginx.

$sudo Nginx -t

要么

$su - -c "Nginx -t"

这样,Nginx父进程将具有与systemctl运行时相同的权限.

如果这样可以在测试时解决错误,但在从systemctl运行时不会解决,您可能需要检查this page on investigating systemd errors.

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...