Nginx的启动、关闭和重启

Nginx的启动关闭和重启

nginx可以通过信号指令控制进程,常用的信号有:

QUIT:处理完当前请求后关闭进程

HUP:重新加载配置,也就是关闭原有的进程,开启新的进程,此操作不会中断用户的访问请求,所以又称为平滑重启nginx

USR1:用于nginx的日志切换,也就是重新打开一个日志文件,每天要生成一个新的日志文件时,可以使用该信号控制。

USR2:平滑升级可执行程序

WINCH :从容关闭工作进程

常用的方法控制有:

①  kill –XXX主进程号

 

[root@localhost run]# ps -ef |grep nginx

root     2771     1  0 10:34 ?        00:00:00 nginx: master process/opt/nginx/sbin/nginx

503      2772  2771  0 10:34 ?        00:00:00 nginx: worker process

503      2773  2771  0 10:34 ?        00:00:00 nginx: worker process

503       2774 2771  0 10:34 ?        00:00:00 nginx: worker process

503      2775  2771  0 10:34 ?        00:00:00 nginx: worker process

root     3575  2730  0 12:08 pts/1    00:00:00 grep nginx

[root@localhost run]# kill -QUIT2771

[root@localhost run]# ps -ef |grep nginx

root     3578  2730  0 12:09 pts/1    00:00:00 grep nginx

[root@localhost run]#/opt/nginx/sbin/nginx

[root@localhost run]# ps -ef |grep nginx

root     3580     1  0 12:09 ?        00:00:00 nginx: master process/opt/nginx/sbin/nginx

503      3581  3580  0 12:09 ?        00:00:00 nginx: worker process

503      3582  3580  0 12:09 ?        00:00:00 nginx: worker process

503      3583  3580  0 12:09 ?        00:00:00 nginx: worker process

503      3584  3580  0 12:09 ?        00:00:00 nginx: worker process

root     3588  2730  0 12:10 pts/1    00:00:00 grep nginx

[root@localhost run]# kill -HUP3580

[root@localhost run]# ps -ef |grep nginx

root     3580     1  0 12:09 ?        00:00:00 nginx: master process/opt/nginx/sbin/nginx

503      3590  3580  0 12:10 ?        00:00:00 nginx: worker process

503      3591  3580  0 12:10 ?        00:00:00 nginx: worker process

503      3592  3580  0 12:10 ?        00:00:00 nginx: worker process

503      3593  3580  0 12:10 ?        00:00:00 nginx: worker process

root     3596  2730  0 12:10 pts/1    00:00:00 grep nginx

[root@localhost run]# kill -WINCH3580

[root@localhost run]# ps -ef |grep nginx

root     3580     1  0 12:09 ?        00:00:00 nginx: master process/opt/nginx/sbin/nginx

 

② kill -信号类型`cat /安装目录/logs/nginx.pid`

使用该方法时需要nginx.conf配置了pid文件存放路径则该文件存放的就是Nginx主进程号,如果没指定则放在nginxlogs目录下。有了pid件,我们就不用先查询Nginx的主进程号,而直接向Nginx发送信号了,命令如下:

kill -信号类型`cat /安装目录/logs/nginx.pid` ,本人将nginx安装于/opt/nginx目录下 

[root@localhost conf]# cd /opt/nginx/logs/

[root@localhost logs]# ls

access.log error.log  nginx.pid

[root@localhost logs]# ps -ef |grep nginx

root     3580     1  0 12:09 ?        00:00:00 nginx: master process/opt/nginx/sbin/nginx

503      3680  3580  0 12:28 ?        00:00:00 nginx: worker process

503      3681  3580  0 12:28 ?        00:00:00 nginx: worker process

503      3682  3580  0 12:28 ?        00:00:00 nginx: worker process

503      3683  3580  0 12:28 ?        00:00:00 nginx: worker process

root     3687  2730  0 12:28 pts/1    00:00:00 grep nginx

[root@localhost logs]# kill -HUP`cat /opt/nginx/logs/nginx.pid`

[root@localhost logs]# ps -ef |grep nginx

root     3580     1  0 12:09 ?        00:00:00 nginx: master process/opt/nginx/sbin/nginx

503      3689  3580  0 12:28 ?        00:00:00 nginx: worker process

503      3690  3580  0 12:28 ?        00:00:00 nginx: worker process

503      3691  3580  0 12:28 ?        00:00:00 nginx: worker process

503      3692  3580  0 12:28 ?        00:00:00 nginx: worker process

root     3694  2730  0 12:28 pts/1    00:00:00 grep nginx

[root@localhost logs]#

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值