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

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

目前,我已经使用 设置了一个 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.

如果我跑步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

当我寻找有关此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

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

答案1

这可能是一个错误。“此行为是一个已知错误,由 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
  1. 添加以下内容/etc/systemd/system/nginx.service.d/override.conf
[Service]
ExecStartPost=/bin/sleep 0.1
  1. 重新加载 systemd 管理器配置:
systemctl daemon-reload
  1. 重新启动NGINX:
systemctl restart nginx

复制 + 粘贴上述命令

mkdir -p /etc/systemd/system/nginx.service.d
echo "[Service]\nExecStartPost=/bin/sleep 0.1\n" > /etc/systemd/system/nginx.service.d/override.conf
systemctl daemon-reload
systemctl restart nginx

错误报告链接

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

答案2

sudo nginx -t

我认为这个评论应该是一个答案。

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

相关内容