码迷,mamicode.com
首页 > 其他好文 > 详细

nginx启动、重启、关闭

时间:2016-08-19 23:46:44      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:

一.启动

cd usr/local/nginx/sbin
./nginx

 

二.重启

更改配置重启nginx

kill -HUP 主进程号或进程号文件路径

或者使用

cd /usr/local/nginx/sbin
./nginx -s reload

判断配置文件是否正确 

nginx -t -c /usr/local/nginx/conf/nginx.conf

或者

cd /usr/local/nginx/sbin
./nginx -t

 

三.关闭

查询nginx主进程号

ps -ef | grep nginx

从容停止 kill -QUIT 主进程号

快速停止 kill -TERM 主进程号

强制停止 kill -9 nginx

若nginx.conf配置了pid文件路径,如果没有,则在logs目录下

kill -信号类型 ‘/usr/local/nginx/logs/nginx.pid‘

 

四.升级

1.先用新程序替换旧程序文件

2.kill -USR2 旧版程序的主进程号或者进程文件名

        此时旧的nginx主进程会把自己的进程文件改名为.oldbin,然后执行新版nginx,此时新旧版本同时运行

3.kill -WINCH 旧版本主进程号

4.不重载配置启动新/旧工作进程

        kill -HUP 旧/新版本主进程号

        从容关闭旧/新进程,kill -QUIT 旧/新进程号

        快速关闭旧/新进程,kill -TERM 旧/新进程号

 

五.实际应用中经常使用

实际应用中经常是关闭,再启动,nginx的启动命令是:

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

-c制定配置文件的路径,不加-nginx会自动加载默认路径的配置文件。

以上是通用的启动命令,研究了一下nginx帮助后发现,有-s参数可对nginx服务进行管理:

# /usr/local/nginx/sbin/nginx -h
nginx version: nginx/0.7.63
Usage: nginx [-?hvVt] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-s signal : send signal to a master process: stop, quit, reopen, reload 
-p prefix : set prefix path (default: /usr/local/nginx/)
-c filename : set configuration file (default: conf/nginx.conf)
-g directives : set global directives out of configuration file

于是可通过执行如下命令重启nginx

# /usr/local/nginx/sbin/nginx -s reload

 

nginx启动、重启、关闭

标签:

原文地址:http://www.cnblogs.com/flyingeagle/p/5789308.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!