测试Nginx负载均衡功能,在修改完配置文件后,重启Nginx失败,报错如下。(Nginx编译安装)
[root@web01 conf]# nginx -s reload
nginx: [error] invalid PID number "" in "/app/nginx-1.16.0/logs/nginx.pid"
再次检查一遍Nginx配置文件是否编写正确
[root@web01 conf]# nginx -t
nginx: the configuration file /app/nginx-1.16.0/conf/nginx.conf syntax is ok
nginx: configuration file /app/nginx-1.16.0/conf/nginx.conf test is successful
配置文件格式无误。
然后看nginx的PID文件
[root@web01 conf]# cat /app/nginx-1.16.0/logs/nginx.pid
该文件为空。
然后检查端口号,Nginx服务是否开启。
[root@web01 conf]# netstat -lntup|grep 80
Nginx服务关闭,因此需要先开启Nginx服务。
由于本文服务器已经设置环境变量,如下
[root@web01 conf]# tail -1 /etc/profile
export PATH=/app/nginx/sbin:$PATH
因此直接输入nginx即可开启服务。
[root@web01 conf]# nginx
[root@web01 conf]# netstat -lntup|grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2657/nginx: master
[root@web01 conf]# cat /app/nginx-1.16.0/logs/nginx.pid
2657
此时Nginx服务可以正常重启。
本文围绕测试Nginx负载均衡功能时,修改配置文件后重启失败的问题展开。通过检查配置文件格式、PID文件、端口号及服务开启状态,发现Nginx服务关闭,因服务器设置了环境变量,直接输入nginx开启服务后,Nginx可正常重启。

被折叠的 条评论
为什么被折叠?



