测试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服务可以正常重启。