关于nginx的启动和停止、平滑重启
一、nginx的启动
/usr/local/nginx/sbin/nginx -c/usr/local/nginx/conf/nginx.conf
-c 指定配置文件的路径
配置文件修改后的检查命令
/usr/local/nginx/sbin/nginx -t -c/usr/local/nginx/conf/nginx.conf
这个我试验的结果好象是只检查nginx.conf的语法错误,但不会启动nginx
ps -ef | grep nginx
root 7193 1 0 10:45? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c/usr/local/nginx/conf/nginx.conf
nobody 7211 7193 0 10:50? 00:00:00 nginx: workerprocess
nobody 7212 7193 0 10:50? 00:00:00 nginx: workerprocess
nobody 7213 7193 0 10:50? 00:00:00 nginx: workerprocess
nobody 7214 7193 0 10:50? 00:00:00 nginx: workerprocess
nobody 7215 7193 0 10:50? 00:00:00 nginx: workerprocess
nobody 7216 7193 0 10:50? 00:00:00 nginx: workerprocess
nobody 7217 7193 0 10:50? 00:00:00 nginx: workerprocess
nobody 7218 7193 0 10:50? 00:00:00 nginx: workerprocess
wujian 7222 6895 0 10:51pts/0 00:00:00 grep --color=auto nginx
其中的master的主进程,主进程号会写入/usr/local/nginx/logs/nginx.pid
二、平滑重启 重新加载配置文件
/usr/local/nginx/sbin/nginx -t -c/usr/local/nginx/conf/nginx.conf先检查配置文件
sudo kill -HUP nginx主进程号
另外一种sudo kill -HUP `/usr/local/nginx/logs/nginx.pid`经多次试验未能成功
bash: /usr/local/nginx/logs/nginx.pid:权限不够
Usage:
kill pid... Send SIGTERM to every process listed.
kill signal pid... Send a signal to every process listed.
kill -s signal pid... Send asignal to every process listed.
kill-l List all signal names.
kill-L List all signal names in a nice table.
kill -lsignal Convert between signal numbers and names.
查看nginx.pid有读写权限,增加可执行权限,依然不能够,以此为记!!
sudo kill -HUP `cat /usr/local/nginx/logs/nginx.pid` ok!
经过查看发现用这种方式重启未改变进程号,资料上显示nginx接收到HUP信号后,会尝试先解析配置文件,如果成功就应用新的配置文件。此外需要验证,以此为记!!
三、重容停止nginx
sudo kill -QUIT nginx主进程号
sudo kill -QUIT`/usr/local/nginx/logs/nginx.pid`
sudo kill -QUIT `cat /usr/local/nginx/logs/nginx.pid` ok!
四、快速停止
sudo kill -INT nginx主进程号
sudo kill -INT`/usr/local/nginx/logs/nginx.pid`
sudo kill -INT `cat /usr/local/nginx/logs/nginx.pid` ok!
或
sudo kill -TERM nginx主进程号
sudo kill -TERM`/usr/local/nginx/logs/nginx.pid`
sudo kill -TERM `cat /usr/local/nginx/logs/nginx.pid` ok!
五、强制停止所有nginx
sudo pkill -9 nginx
sudo killall nginx