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

简介:

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

1
2
[root@web01 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服务对应的进程

1
2
[root@web01 conf] # ps -ef|grep nginx
root       1437   1313  0 10:36 pts /1     00:00:00  grep  nginx

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

1
2
[root@web01 conf] # lsof -i :80
[root@web01 conf] #
1
2
[root@web01 conf] # netstat -lntup|grep nginx
[root@web01 conf] #
1
2
[root@web01 conf] # netstat -lntup|grep 80
[root@web01 conf] #


启动nginx服务后再查看:

1
[root@web01 conf] # /application/nginx/sbin/nginx

查看nginx进程是否存在:

1
2
3
4
5
[root@web01 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
[root@web01 conf] #

查看端口是否存在:

1
2
3
4
[root@web01 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)
1
2
3
4
[root@web01 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
1
2
3
4
5
6
[root@web01 conf] # netstat -lntup|grep 80
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      1444 /nginx          
[root@web01 conf] # netstat -lntup|grep 81
tcp        0      0 0.0.0.0:81                  0.0.0.0:*                   LISTEN      1444 /nginx          
[root@web01 conf] # netstat -lntup|grep 82
tcp        0      0 0.0.0.0:82                  0.0.0.0:*                   LISTEN      1444 /nginx


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

1
2
[root@web01 conf] # /application/nginx/sbin/nginx -s reload
[root@web01 conf] #
本文转自sandshell博客51CTO博客,原文链接http://blog.51cto.com/sandshell/1957768如需转载请自行联系原作者

sandshell
相关文章
|
11天前
|
应用服务中间件 网络安全 nginx
快速上手!使用Docker和Nginx部署Web服务的完美指南
快速上手!使用Docker和Nginx部署Web服务的完美指南
|
11天前
|
应用服务中间件 网络安全 nginx
【Nginx】Nginx启动显示80端口占用问题的解决方案
【Nginx】Nginx启动显示80端口占用问题的解决方案
51 1
|
17天前
|
应用服务中间件 nginx
树莓派安装Nginx服务结合内网穿透实现无公网IP远程访问
树莓派安装Nginx服务结合内网穿透实现无公网IP远程访问
|
4月前
|
负载均衡 Ubuntu 应用服务中间件
【Linux】Web服务之Nginx服务
【Linux】Web服务之Nginx服务
41 0
|
11天前
|
存储 Ubuntu 应用服务中间件
【Nginx】centos和Ubuntu操作系统下载Nginx配置文件并启动Nginx服务详解
【Nginx】centos和Ubuntu操作系统下载Nginx配置文件并启动Nginx服务详解
16 1
|
8天前
|
弹性计算 运维 Shell
|
13天前
|
机器学习/深度学习 网络协议 数据安全/隐私保护
远程访问本地jupyter notebook服务 - 无公网IP端口映射
远程访问本地jupyter notebook服务 - 无公网IP端口映射
|
2月前
|
前端开发 应用服务中间件 nginx
nginx中配置不输入端口(指定地址)访问项目的方法
nginx中配置不输入端口(指定地址)访问项目的方法
35 0
|
2月前
|
NoSQL 关系型数据库 MySQL
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
Docker安装详细步骤及相关环境安装配置(mysql、jdk、redis、自己的私有仓库Gitlab 、C和C++环境以及Nginx服务代理)
235 0
|
2月前
|
安全 应用服务中间件 nginx