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

Ryn*_*ett 5 permissions 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
Run Code Online (Sandbox Code Playgroud)

我不明白nginx.pid在它被创建之前怎么会有不正确的权限,或者人们会怎么做来解决这个问题。

我正在使用 Arch 并且我看到了与 chroot-jail 相关的类似问题,但我没有在 chroot 中安装 nginx。

小智 8

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

$ sudo nginx -t

或者

$ su - -c "nginx -t"

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

如果这在测试时解决了错误,但在从 systemctl 运行时没有解决,您可能需要检查此页面以了解systemd 错误