Wizard
Wizard

Reputation: 22113

Failed to read PID from file /run/nginx.pid but the website works properly

When I check the status of 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.

It report that "Failed to read PID from file /run/nginx.pid: Invalid argument"

However, my website runs properly,

my 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/;
   }
}

I could visit www.example.com and 39.105.51.** without error.
Should I ignore it, what kind of error is waiting for me ahead?

Upvotes: 1

Views: 6193

Answers (1)

Jeremy Davis
Jeremy Davis

Reputation: 750

It seems likely that you're hitting a known race condition (bug) between Nginx and systemd. It seems to be prevalent on low resource machines, particularly if they only have a single CPU.

Essentially what happens is that systemd is expecting the PID file to be populated, by the time that Nginx has forked. But on low resources machines, that happens before the Nginx fork has had the time to create it. So you get an error logged.

It's nothing more than an annoyance, so there's no need to do anything about it if you don't want. If you'd really like to stop it, then there is workaround documented on the 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

After applying that, try restarting Nginx and see if it still occurs.

systemctl restart nginx

You should no longer get that message.

Upvotes: 1

Related Questions