Nginx 启动错误 Failed to read PID from /run/nginx.pid

问题原因

Nginx 启动需要时间,而 systemd 在 Nginx 启动前去读取其 pid file,导致错误。

解决方法

让systemd 在执行完 ExecStart 指令后等待一点点时间。建立如下目录,

/etc/systemd/system/nginx.service.d

在其中新建文件 override.conf,输入如下内容 (这里设置为等待 1s,可酌情调整时间),

[Service]
ExecStartPost=/bin/sleep 1

然后重新启动 Nginx,

$ sudo systemctl daemon-reload
$ sudo systemctl restart nginx.service

(完)

参考网友博客:https://my.oschina.net/u/2357619/blog/1609622

原文地址:https://www.cnblogs.com/gaowengang/p/14582757.html