Here are three ways to solve Nginx errors: nginx: [error] invalid PID number “” in “/run/nginx.pid”
Problem Description
When executing the -s reload command on nginx, an error occurs:
[MyHome@MyMachine ~]$ sudo nginx -s reload
nginx: [error] invalid PID number "" in "/run/nginx.pid"
Solution
Method 1: Reload the configuration file nginx.conf, and then execute reload
Generally this method is more commonly used
[root@vm00004 ~]$ # nginx.conf 可能不在 /etc/nginx/ 下,具体视 nginx 的安装路径而定
[root@vm00004 ~]$ sudo nginx -c /etc/nginx/nginx.conf
[root@vm00004 ~]$ sudo nginx -s reload
Method 2: Directly write the PID of the nginx main process to "/run/nginx.pid"
[root@vm00004 ~]$ # 下面的命令得到 nginx 主进程的PID:19386
[root@vm00004 ~]$ ps -aux | grep "nginx: master process"
root 19386 0.0 0.0 70060 7308 ? Ss 15:36 0:00 nginx: master process nginx
myname 20740 0.0 0.0 116800 1048 pts/0 S+ 23:31 0:00 grep --color=auto nginx: master process
[root@vm00004 ~]$ sudo echo 19386 > /run/nginx.pid
[root@vm00004 ~]$ sudo nginx -s reload
Method 3: Kill the main process of nginx and then restart nginx
Try not to use it. nginx will be shut down for a period of time, and there may be other problems when restarting that cause it to fail to start. This may affect the use of some services in the production environment on a large scale.
[root@vm00004 ~]$ sudo killall nginx
[root@vm00004 ~]$ sudo nginx