【问题标题】:Failed to read PID from file /run/nginx.pid but the website works properly无法从文件 /run/nginx.pid 读取 PID,但网站运行正常
【发布时间】:2019-01-08 14:07:27
【问题描述】:

当我检查 Nginx 的状态时

sudo service nginx status

Aug 01 12:35:07 iz2ze9wve43n2nyuvmsfx5z systemd[1]: Starting The nginx HTTP and reverse proxy server...
....
Aug 01 12:35:07 iz2ze9wve43n2nyuvmsfx5z systemd[1]: Failed to read PID from file /run/nginx.pid: Invalid argument
Aug 01 12:35:07 iz2ze9wve43n2nyuvmsfx5z systemd[1]: Started The nginx HTTP and reverse proxy server.

它报告“无法从文件/run/nginx.pid中读取PID:无效参数”

但是,我的网站运行正常,

我的 custom_nginx.conf

server {
    listen 80;
    server_name *.example.com  39.105.51.**;
    charset utf-8;

    location / {
                uwsgi_read_timeout 30;
        uwsgi_pass 127.0.0.1:8200;
        include uwsgi_params;
   }

    location /media/ {
        alias /usr/share/nginx/html/;
                autoindex on;
   }
    location /static/ {
        alias /root/forum/dst_static/;
   }
}

我可以毫无错误地访问 www.example.com 和 39.105.51.**。
我应该忽略它,什么样的错误在等着我?

【问题讨论】:

  • 你不应该忽略它。由于缺少访问权限,即/run/,可能会发生此类错误。也可能是该目录不存在,但在/var/ 下为/var/run。以后的脚本可能会失败,即重新启动或停止服务,如果它们依赖于从 PID 文件中读取的 PID。
  • 非常感谢您的cmets,请您转发回答。 @U880D

标签: django nginx uwsgi


【解决方案1】:

您似乎遇到了 Nginx 和 systemd 之间的已知竞争条件(错误)。它似乎在低资源机器上很普遍,特别是如果它们只有一个 CPU。

基本上发生的事情是 systemd 期望在 Nginx 分叉时填充 PID 文件。但是在低资源机器上,这发生在 Nginx 分支有时间创建它之前。所以你会记录一个错误。

这只不过是一种烦恼,所以如果你不想要,就没有必要做任何事情。如果您真的想停止它,那么Ubuntu bug report 上记录了解决方法:

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

应用后,尝试重启Nginx,看看是否仍然出现。

systemctl restart nginx

您不应再收到该消息。

【讨论】:

    猜你喜欢
    • 2017-06-24
    • 2017-07-21
    • 2023-02-05
    • 1970-01-01
    • 2013-12-20
    • 2021-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多