nginx啟動、重啟、關閉
一.啟動
cd usr/local/nginx/sbin ./nginx
二.重啟
更改配置重啟nginx
kill -HUP 主進程號或進程號文件路徑
或者使用
cd /usr/local/nginx/sbin ./nginx -s reload
判斷配置文件是否正確
nginx -t -c /usr/local/nginx/conf/nginx.conf
或者
cd /usr/local/nginx/sbin ./nginx -t
三.關閉
查詢nginx主進程號
ps -ef | grep nginx
從容停止 kill -QUIT 主進程號
快速停止 kill -TERM 主進程號
強制停止 kill -9 nginx
若nginx.conf配置了pid文件路徑,如果沒有,則在logs目錄下
kill -信號類型 '/usr/local/nginx/logs/nginx.pid'
四.升級
1.先用新程序替換舊程序文件
2.kill -USR2 舊版程序的主進程號或者進程文件名
此時舊的nginx主進程會把自己的進程文件改名為.oldbin,然后執行新版nginx,此時新舊版本同時運行
3.kill -WINCH 舊版本主進程號
4.不重載配置啟動新/舊工作進程
kill -HUP 舊/新版本主進程號
從容關閉舊/新進程,kill -QUIT 舊/新進程號
快速關閉舊/新進程,kill -TERM 舊/新進程號
五.實際應用中經常使用
實際應用中經常是關閉,再啟動,nginx的啟動命令是:
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
-c制定配置文件的路徑,不加-nginx會自動加載默認路徑的配置文件。
以上是通用的啟動命令,研究了一下nginx幫助后發現,有-s參數可對nginx服務進行管理:
# /usr/local/nginx/sbin/nginx -h nginx version: nginx/0.7.63 Usage: nginx [-?hvVt] [-s signal] [-c filename] [-p prefix] [-g directives] Options: -?,-h : this help -v : show version and exit -V : show version and configure options then exit -t : test configuration and exit -s signal : send signal to a master process: stop, quit, reopen, reload -p prefix : set prefix path (default: /usr/local/nginx/) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file
於是可通過執行如下命令重啟nginx
# /usr/local/nginx/sbin/nginx -s reload