`
wu423
  • 浏览: 9200 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

记录Nginx如何启动、停止、重启、升级操作命令

阅读更多

 

也许你不知道什么是Nginx,Nginx是一个WEB服务器,如IIS那样,现在好多门户都在使用了Nginx作为WEB服务器了,Nginx在Linux系统下跑很优秀,强过其它的WEB服务端,还可以做负载均衡,很不错吧。

那下面主要总结一下Nginx的基本操作。

启动操作

命令:
nginx -c /usr/nginx/conf/nginx.conf
-c参数指定了要加载的nginx配置文件路径。

停止操作
停止操作是通过向nginx进程发送信号(什么是信号请参阅linux文章)来进行的
步骤1:查询nginx主进程号
ps -ef | grep nginx
在进程列表里面找master进程,它的编号就是主进程号了。
步骤2:发送信号
从容停止Nginx:
kill -QUIT 主进程号
快速停止Nginx:
kill -TERM 主进程号
强制停止Nginx:
pkill -9 nginx

另外,若在nginx.conf配置了pid文件存放路径则该文件存放的就是Nginx主进程号,如果没指定则放在nginx的logs目录下。有了pid文件,我们就不用先查询Nginx的主进程号,而直接向Nginx发送信号了,命令如下:
kill -信号类型 '/usr/nginx/logs/nginx.pid'

平滑重启
如果更改了配置就要重启Nginx,要先关闭Nginx再打开?不是的,可以向Nginx发送信号,平滑重启。
平滑重启命令:
kill -HUP 住进称号或进程号文件路径

注意,修改了配置文件后最好先检查一下修改过的配置文件是否正确,以免重启后Nginx出现错误影响服务器稳定运行。判断Nginx配置是否正确命令如下:
nginx -t -c /usr/nginx/conf/nginx.conf

平滑升级
如果服务器正在运行的Nginx要进行升级、添加或删除模块时,我们需要停掉服务器并做相应修改,这样服务器就要在一段时间内停止服务,Nginx可以在不停机的情况下进行各种升级动作而不影响服务器运行。
步骤1:
如果升级Nginx程序,先用新程序替换旧程序文件,编译安装的话新程序直接编译到Nginx安装目录中。
步骤2:执行命令
kill -USR2 旧版程序的主进程号或进程文件名
此时旧的Nginx主进程将会把自己的进程文件改名为.oldbin,然后执行新版Nginx。新旧Nginx会同市运行,共同处理请求。
这时要逐步停止旧版Nginx,输入命令:
kill -WINCH 旧版主进程号
慢慢旧的工作进程就都会随着任务执行完毕而退出,新版的Nginx的工作进程会逐渐取代旧版工作进程。

此时,我们可以决定使用新版还是恢复到旧版。
不重载配置启动新/旧工作进程
kill -HUP 旧/新版主进程号
从容关闭旧/新进程
kill -QUIT 旧/新主进程号
如果此时报错,提示还有进程没有结束就用下面命令先关闭旧/新工作进程,再关闭主进程号:
kill -TERM 旧/新工作进程号

这样下来,如果要恢复到旧版本,只需要上面的几个步骤都是操作新版主进程号,如果要用新版本就上面的几个步骤都操作旧版主进程号就行了。

上面就是Nginx的一些基本的操作,希望以后Nginx能有更好的方法来处理这些操作,最好是Nginx的命令而不是向Nginx进程发送系统信号。

.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}
.adslot-overlay {position: absolute; font-family: arial, sans-serif; background-color: rgba(0,0,0,0.65); border: 2px solid rgba(0,0,0,0.65); color: white !important; margin: 0; z-index: 2147483647; text-decoration: none; box-sizing: border-box; text-align: left;}.adslot-overlay-iframed {top: 0; left: 0; right: 0; bottom: 0;}.slotname {position: absolute; top: 0; left: 0; right: 0; font-size: 13px; font-weight: bold; padding: 3px 0 3px 6px; vertical-align: middle; background-color: rgba(0,0,0,0.45); text-overflow: ellipsis; white-space: nowrap; overflow: hidden;}.slotname span {text-align: left; text-decoration: none; text-transform: capitalize;}.revenue {position: absolute; bottom: 0; left: 0; right: 0; font-size: 11px; padding: 3px 0 3px 6px; vertial-align: middle; text-align: left; background-color: rgba(0,0,0,0.45); font-weight: bold; text-overflow: ellipsis; overflow: hidden; white-space: nowrap;}.revenue .name {color: #ccc;}.revenue .horizontal .metric {display: inline-block; padding-right: 1.5em;}.revenue .horizontal .name {padding-right: 0.5em;}.revenue .vertical .metric {display: block; line-height: 1.5em; margin-bottom: 0.5em;}.revenue .vertical .name, .revenue .vertical .value {display: block;}.revenue .square .metric, .revenue .button .metric {display: table-row;}.revenue .square .metric {line-height: 1.5em;}.revenue .square .name, .revenue .square .value, .revenue .button .value {display: table-cell;}.revenue .square .name {padding-right: 1.5em;}.revenue .button .name {display: block; margin-right: 0.5em; width: 1em; overflow: hidden; text-overflow: clip;}.revenue .button .name:first-letter {margin-right: 1.5em;}a.adslot-overlay:hover {border: 2px solid rgba(58,106,173,0.9);}a.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}a.adslot-overlay:hover .revenue {border-top: 1px solid rgba(81,132,210,0.9); background-color: rgba(58,106,173,0.9);}div.adslot-overlay:hover {cursor: not-allowed; border: 2px solid rgba(64,64,64,0.9);}div.adslot-overlay:hover .slotname {border-bottom: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}div.adslot-overlay:hover .revenue {border-top: 1px solid rgba(128,128,128,0.9); background-color: rgba(64,64,64,0.9);}
分享到:
评论

相关推荐

    Nginx 启动、停止、重启、升级操作命令收集

    启动操作 命令: nginx -c /usr/nginx/conf/nginx.conf -c参数指定了要加载的nginx配置文件路径。 停止操作 停止操作是通过向nginx进程发送信号(什么是信号请参阅linux文章)来进行的 步骤1:查询nginx主进程号 ps...

    Nginx 常用启动、停止、重启命令.pdf

    "Nginx 常用启动、停止、重启命令" Nginx 是一个流行的开源 Web 服务器,需要通过命令来启动、停止和重启。在这篇文章中,我们将讨论 Nginx 的常用启动、停止和重启命令。 启动 Nginx 启动 Nginx 有多种方式,...

    Nginx启动、重启失败的一般解决方法和步骤

    Nginx启动或重启失败,一般是因为配置文件出错了,我们可以使用nginx -t方法查看配置文件出错的地方。 也可以通过查看Nginx日志文件定位到Nginx重启失败的原因,Nginx日志文件的路径一般在:/var/log/nginx目录下 ...

    nginx命令参数用法详细介绍

     启动nginx命令说明:需要注意,由于nginx默认端口也是80端口,如果此时你的机器上开启了Apache或者IIS服务,切忌在启动nginx之前务必关闭IIS或Apache服务,否则nginx启动命令不会成功。  nginx命令:停止nginx  ...

    window下nginx启动脚本

    nginx配置修改后运行此脚本启动nginx。 其脚本的作用往往是简化了启动的便利

    nginx常用bat批处理命令

    nginx常用bat批处理命令,放在nginx同级目录下使用,可快速的重启、停止、关闭nginx。 quit.bat(退出Nginx) reload.bat(重启Nginx) stop.bat(停止Nginx)

    windows 环境下nginx 启动,停止,重启脚本

    windows 环境下nginx 启动,停止,重启脚本 解决windows 环境下 双击nginx.exe重启后不会停止上一次进程问题。

    centos实时监测nginx 挂机自动重启服务

    如果服务器中nginx挂掉,我们如何第一时间启动它?人工重启?no。 该脚本定时检测nginx状态,挂机自动重启nginx。 如果服务器中nginx挂掉,我们如何第一时间启动它?人工重启?no。 该脚本定时检测nginx状态,...

    Centos7环境下Nginx版本升级方式及步骤

    此手册主要用于记录个人进行nginx升级的步骤和心得,介绍了2种升级方式。 YUM upgrade升级:本方式适用于使用rpm安装nginx的方式,优点是升级操作简单便捷,缺点是无法升级到指定版本,默认升级至YUM安装支持的...

    Windows下Nginx的启动停止等基本操作命令详解

    在Windows下使用Nginx,我们需要掌握一些基本的操作命令,今天为大家分享几个Windows下操作Nginx的基本命令

    windows下Nginx启动、关闭、重启bat工具

    NULL 博文链接:https://xml.iteye.com/blog/1608347

    Nginx启动.bat

    window下Nginx启动bat脚本若中文乱码,则新建脚本文件时改为ANSI编码格式即可 稳定版:nginx-1.15.12:https://download.csdn.net/download/luxiukang/11171445 最新版:nginx-1.16.0:...

    windows 注册Nginx为服务,自动重启

    包含注册文件及自动化工具,将文件解压缩放c盘直接用cmd命令行运行即可

    详解linux中nginx启动 重启 关闭命令

    启动操作 nginx -c /usr/local/nginx/conf/nginx.conf -c参数指定了要加载的nginx配置文件路径 停止操作 停止操作是通过向nginx进程发送信号来进行的 步骤1:查询nginx主进程号 ps -ef | grep nginx 在进程列表...

    windows+nginx+php带启动/停止脚本

    windows+nginx+php带启动/停止脚本 ,需要自己修改压缩包里的start.bat,stop.bat 和nginx.conf文件内的路径设置成你自己的就OK了。

    Linux中安装Nginx以及启动、关闭和重启命令.pdf

    Linux中安装Nginx以及启动、关闭和重启命令.pdf 学习资料 复习资料 教学资源

    一句简单命令重启nginx

    最近我的多个VPS经常出现502错误,经常需要重启nginx,但网上的很多教程都需要繁琐的启动脚本,远不如apache的重启命令那么简单。

    03Nginx常用操作命令.pdf

    Nginx常用操作命令

Global site tag (gtag.js) - Google Analytics