您的位置:首页 > 运维架构 > Nginx

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

2014-09-23 22:03 369 查看
环境:

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: