I can't open the PID file /var/run/*.pid

Recently, customers started complaining that after restarting the server, the sites only work for a minute.
It was found out that the problem is in the Nginx web server. It may occur after updating the OS or changing the version of the web server.
The Point is that after a reboot, the Nginx process automatically terminates.
Let's Look at the problem in more detail based on CentOS 7.

Checking the state of Nginx:

service nginx status

As a result, we received the status "activating (start)". Which is quite strange, since Nginx is in the process of starting, but something prevents it from starting.

We also got the line from the output of the previous command: "I can't open the PID file /var/run/nginx.pid (yet?)".
In these cases, you need to check whether the file exists, its path, and access rights. Interestingly, in the directory "/var/run/" the file was located and it could be opened from under the user, but once a minute the file was deleted.
The fact is that "/var/run/" is a link to the "/run/" directory (this was prompted by the line "Too many levels of symbolic links" from the web server status output).

The solution was quite simple.

1. You need to change the location directory of this file from "/var/run/nginx.pid" on "/run/nginx.pid" in the following configuration files:

/etc/nginx/nginx.conf 

/lib/systemd/system/nginx.service

2. Then run the command to make the changes in systemd take effect:

systemctl daemon-reload

3. Restart Nginx:

service nginx restart

4. Again check the state of Nginx:

service nginx status

The Output should be with the following line: "Active: active (running)", which tells us that the web server is running.


P.S.:

The PID file can be cursed in the same way fail2ban and mysqld. The treatment procedure is similar: you need to change the directory of the PID file from "/var/run/" to just "/run/" in the configuration files (program configuration and systemd/).