open()“/run/nginx.pid”失败(13:权限被拒绝)

Tor*_*xO7 5 permissions nginx arch-linux nextcloud

目前,我已经设置了一个 nextcloud 服务器nginx并使用 启用了它sudo systemctl enable nginx.service。当我重新启动时,我收到一条错误消息,抱怨代理服务器,如果我查看一下sudo systemctl status nginx.service,我会收到以下消息:

nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/etc/systemd/system/nginx.service; enabled; vendor preset: disabled)
     Active: failed (Result: exit-code) since Sat 2020-11-14 12:20:55 CET; 16min ago

Nov 14 12:20:55 TORNAX-ARCH systemd[1]: Starting A high performance web server and a reverse proxy server...
Nov 14 12:20:55 TORNAX-ARCH nginx[473]: 2020/11/14 12:20:55 [warn] 473#473: could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_si>
Nov 14 12:20:55 TORNAX-ARCH nginx[473]: 2020/11/14 12:20:55 [emerg] 473#473: bind() to 192.168.178.35:443 failed (99: Unknown error)
Nov 14 12:20:55 TORNAX-ARCH systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
Nov 14 12:20:55 TORNAX-ARCH systemd[1]: nginx.service: Failed with result 'exit-code'.
Nov 14 12:20:55 TORNAX-ARCH systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Run Code Online (Sandbox Code Playgroud)

如果我跑步nginx -t,我会得到这个:

2020/11/14 12:37:40 [warn] 68391#68391: could not build optimal types_hash, you should increase either types_hash_max_size: 1024 or types_hash_bucket_size: 64; ignoring types_hash_bucket_size
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2020/11/14 12:37:40 [emerg] 68391#68391: open() "/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)

当我寻找有关此open() "/run/nginx.pid" failed (13: Permission denied)错误的解决方案时,我只获得 docker + nginx 的解决方案,如下所示:

手动重新启动服务后它可以工作,但当我运行时sudo systemctl restart nginx.service我仍然收到.open() "/run/nginx.pid" failed (13: Permission denied)nginx -t

我做错了什么或者我可以做什么来解决这个问题?

小智 11

sudo nginx -t

\n

在我看来,这个评论应该是一个答案。

\n

Run nginx -t as root. This is a red herring. \xe2\x80\x93 Michael Hampton Nov 15 at 0:27

\n


小智 2

这可能是一个错误。“此行为是一个已知错误,由 nginx 和 systemd 之间的竞争条件引起。Systemd 期望在 nginx 有时间创建 PID 文件之前填充该文件。” https://www.cloudinsidr.com/content/heres-fix-nginx-error-failed-read-pid-file-linux/

编辑

无论如何,如果网站再次关闭,请按照以下步骤进行修复:

分步指南

  1. 在 /etc/systemd/system/ 中创建一个名为 nginx.service.d 的目录:
mkdir -p /etc/systemd/system/nginx.service.d
Run Code Online (Sandbox Code Playgroud)
  1. 将以下内容添加到/etc/systemd/system/nginx.service.d/override.conf
[Service]
ExecStartPost=/bin/sleep 0.1
Run Code Online (Sandbox Code Playgroud)
  1. 重新加载 systemd 管理器配置:
[Service]
ExecStartPost=/bin/sleep 0.1
Run Code Online (Sandbox Code Playgroud)
  1. 重新启动 NGINX:
systemctl daemon-reload
Run Code Online (Sandbox Code Playgroud)

复制+粘贴上面的命令

systemctl restart nginx
Run Code Online (Sandbox Code Playgroud)

错误报告链接

https://bugs.launchpad.net/ubuntu/+source/nginx/+bug/1581864