一.啓動html
cd usr/local/nginx/sbin ./nginx
二.重啓nginx
更改配置重啓nginxpost
kill -HUP 主進程號或進程號文件路徑
或者使用ui
cd /usr/local/nginx/sbin ./nginx -s reload
判斷配置文件是否正確 this
nginx -t -c /usr/local/nginx/conf/nginx.conf
或者url
cd /usr/local/nginx/sbin ./nginx -t
三.關閉spa
查詢nginx主進程號.net
ps -ef | grep nginx
從容中止 kill -QUIT 主進程號code
快速中止 kill -TERM 主進程號htm
強制中止 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