重载
修改了配置文件后,直接重新启动nginx,使用reload
命令
./nginx -s reload
其中,-s
有发送信息的作用。
热部署
重新编译了nginx的可执行程序后,可以通过不杀掉程序进行升级。首先备份原来的程序:
cp nginx nginx.old
之后,把新的可执行文件替换到原来的旧文件,替换后查看原来进程的pid号:
ps -ef | grep nginx
root 14459 1 0 21:33 ? 00:00:00 nginx: master process ./nginx
nobody 14590 14459 0 21:33 ? 00:00:00 nginx: worker process
root 14637 12131 0 21:34 pts/0 00:00:00 grep --color=auto nginx
这里可以知道nginx运行的pid号为14459,执行命令:
kill -USR2 14459
再次通过ps观看可以发现,新的master进程和旧的master进程同时在运行,但是请求会逐渐过渡到新的master进程中
root 14459 1 0 21:33 ? 00:00:00 nginx: master process ./nginx
nobody 14590 14459 0 21:33 ? 00:00:00 nginx: worker process
root 17398 14459 0 21:54 ? 00:00:00 ng