nginx---进程开启、关闭和重载配置文件

环境:

centOS6.4 32位


原文地址:http://nginx.org/en/docs/control.html

TERM, INTfast shutdown
QUITgraceful shutdown 当请求处理完毕后才关闭进程
HUPchanging configuration, keeping up with a changed time zone (only for FreeBSD and Linux), starting new worker processes with a new configuration, graceful shutdown of old worker processes
USR1re-opening log files 
USR2upgrading an executable file
WINCHgraceful shutdown of worker processes

启动进程

# /usr/local/nginx/sbin/nginx

[root@localhost ~]# /usr/local/nginx/sbin/nginx
[root@localhost ~]# ps aux | grep nginx
root      6015  0.0  0.1   3472   516 ?        Ss   14:34   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    6016  0.0  0.1   3656   864 ?        S    14:34   0:00 nginx: worker process
root      6018  0.0  0.1   4356   732 pts/0    S+   14:34   0:00 grep nginx

关闭进程

[root@localhost ~]# ps aux | grep nginx
root      6015  0.0  0.1   3472   516 ?        Ss   14:34   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nobody    6016  0.0  0.1   3656   864 ?        S    14:34   0:00 nginx: worker process
root      6018  0.0  0.1   4356   732 pts/0    S+   14:34   0:00 grep nginx

[root@localhost ~]# kill -QUIT 6015
[root@localhost ~]# ps aux | grep nginx
root      6020  0.0  0.1   4356   732 pts/0    S+   14:37   0:00 grep nginx

在不关闭进程的情况下,重载配置文件

[root@localhost logs]# kill -HUP 6022


# cd /usr/local/nginx/logs

# ll

-rw-r--r--. 1 root root 2619 Sep 22 13:46 access.log
-rw-r--r--. 1 root root  224 Sep 22 13:35 error.log
-rw-r--r--. 1 root root    5 Sep 22 13:34 nginx.pid

# mv access.log access-111.log

# ll

-rw-r--r--. 1 root root 2619 Sep 22 13:46 access-111.log
-rw-r--r--. 1 root root  224 Sep 22 13:35 error.log
-rw-r--r--. 1 root root    5 Sep 22 13:34 nginx.pid

重新访问页面后

# ll

-rw-r--r--. 1 root root 4479 Sep 22 14:23 access-111.log
-rw-r--r--. 1 root root  224 Sep 22 13:35 error.log
-rw-r--r--. 1 root root    5 Sep 22 13:34 nginx.pid

访问日志名改变了,但还是继续写入了

重新启动服务或者重载配置文件以及使用USR1 都会新建日志文件

[root@localhost logs]# rm -rf access-111.log
[root@localhost logs]# ll
total 8
-rw-r--r--. 1 root root 224 Sep 22 13:35 error.log
-rw-r--r--. 1 root root   5 Sep 22 14:39 nginx.pid

[root@localhost logs]# kill -quit 6022
[root@localhost logs]# ps aux | grep nginx
root      6038  0.0  0.1   4356   732 pts/0    S+   14:44   0:00 grep nginx

[root@localhost nginx]# ./sbin/nginx
[root@localhost nginx]# ps aux | grep nginx
root      6041  0.0  0.1   3472   516 ?        Ss   14:44   0:00 nginx: master process ./sbin/nginx
nobody    6042  0.0  0.1   3656   864 ?        S    14:44   0:00 nginx: worker process
root      6044  0.0  0.1   4356   732 pts/0    S+   14:44   0:00 grep nginx
[root@localhost nginx]# ll logs/
total 8
-rw-r--r--. 1 root root   0 Sep 22 14:44 access.log
-rw-r--r--. 1 root root 224 Sep 22 13:35 error.log
-rw-r--r--. 1 root root   5 Sep 22 14:44 nginx.pid

[root@localhost nginx]# rm -rf logs/access.log

[root@localhost nginx]# ll logs/
total 8
-rw-r--r--. 1 root root 224 Sep 22 13:35 error.log
-rw-r--r--. 1 root root   5 Sep 22 14:44 nginx.pid

[root@localhost nginx]# ps aux | grep nginx
root      6041  0.0  0.1   3472   516 ?        Ss   14:44   0:00 nginx: master process ./sbin/nginx
nobody    6042  0.0  0.1   3656   864 ?        S    14:44   0:00 nginx: worker process
root      6050  0.0  0.1   4356   728 pts/0    S+   14:49   0:00 grep nginx
[root@localhost nginx]#
[root@localhost nginx]# kill -HUP 6041
[root@localhost nginx]# ll logs/
total 8
-rw-r--r--. 1 root root   0 Sep 22 14:50 access.log
-rw-r--r--. 1 root root 224 Sep 22 13:35 error.log
-rw-r--r--. 1 root root   5 Sep 22 14:44 nginx.pid

[root@localhost nginx]# rm -rf logs/access.log
[root@localhost nginx]# ll logs/
total 8
-rw-r--r--. 1 root root 224 Sep 22 13:35 error.log
-rw-r--r--. 1 root root   5 Sep 22 14:44 nginx.pid
[root@localhost nginx]# kill -USR1 6041
[root@localhost nginx]# ll logs/
total 8
-rw-r--r--. 1 nobody root   0 Sep 22 14:51 access.log
-rw-r--r--. 1 nobody root 224 Sep 22 13:35 error.log
-rw-r--r--. 1 root   root   5 Sep 22 14:44 nginx.pid


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值