欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

nginx服务和对应端口的那些事

程序员文章站 2022-05-07 08:13:02
...

优雅平滑重启nginx服务发现报错:

[[email protected] conf]# /application/nginx/sbin/nginx -s reload
nginx: [error] open() "/application/nginx-1.6.3//logs/nginx.pid" failed (2: No such file or directory)
    经过查看nginx服务未启动导致的,-s reload平滑优雅重启必须在nginx服务启动的状态才可以重启,就好像电脑还没有开机,你根本找不到重启的按钮。重启是建立在已经启动的状态的。



    判断nginx服务器是否启动?

1 根据nginx服务对应的进程是否存在判断,如下图查看没有nginx服务对应的进程

[[email protected] conf]# ps -ef|grep nginx

root       1437   1313  0 10:36 pts/1    00:00:00 grep nginx

2 根据nginx服务对应的端口是否存在监听

[[email protected] conf]# lsof -i :80
[[email protected] conf]#
[[email protected] conf]# netstat -lntup|grep nginx
[[email protected] conf]#
[[email protected] conf]# netstat -lntup|grep 80
[[email protected] conf]#

启动nginx服务后再查看:

[[email protected] conf]# /application/nginx/sbin/nginx
查看nginx进程是否存在:

[[email protected] conf]# ps -ef|grep nginx

root       1444      1  0 10:40 ?        00:00:00 nginx: master process /application/nginx/sbin/nginx
www        1445   1444  0 10:40 ?        00:00:00 nginx: worker process        
root       1456   1313  0 10:40 pts/1    00:00:00 grep nginx

[[email protected] conf]#
查看端口是否存在:
[[email protected] conf]# lsof -i :80

COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   1444 root    6u  IPv4  12531      0t0  TCP *:http (LISTEN)
nginx   1445  www    6u  IPv4  12531      0t0  TCP *:http (LISTEN)

[[email protected] conf]# netstat -lntup|grep nginx

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1444/nginx          
tcp        0      0 0.0.0.0:81                  0.0.0.0:*                   LISTEN      1444/nginx          
tcp        0      0 0.0.0.0:82                  0.0.0.0:*                   LISTEN      1444/nginx

[[email protected] conf]# netstat -lntup|grep 80

tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1444/nginx    

[[email protected] conf]# netstat -lntup|grep 81
tcp 0 0 0.0.0.0:81 0.0.0.0:* LISTEN 1444/nginx
[[email protected] conf]# netstat -lntup|grep 82

tcp        0      0 0.0.0.0:82                  0.0.0.0:*                   LISTEN      1444/nginx

目前nginx服务已经确定好启动了,那么继续执行优雅平滑重启,就不会报错。

[[email protected] conf]# /application/nginx/sbin/nginx -s reload
[[email protected] conf]#

相关标签: nginx nginx