04_Nginx命令行参数,控制信号,Nginx启动、停止、重启命令
Nginx支持一下命令行參數(shù)
-? | -h?? 打印出命令行參數(shù)的幫助
| [root@localhost nginx]# ./nginx -? nginx version: nginx/1.8.0 Usage: nginx [-?hvVtq] [-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 ? -q??????????? : suppress non-error messages during configuration testing ? -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: /usr/local/nginx/nginx.conf) ? -g directives : set global directives out of configuration file |
| [root@localhost nginx]# ./nginx -h nginx version: nginx/1.8.0 Usage: nginx [-?hvVtq] [-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 ? -q??????????? : suppress non-error messages during configuration testing ? -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: /usr/local/nginx/nginx.conf) ? -g directives : set global directives out of configuration file |
?
-c file? 使用可用的配置文件而不是默認的文件
| [root@localhost nginx]# pwd /usr/local/nginx [root@localhost nginx]# ls client_body_temp??????? fastcgi_temp? mime.types.default? sbin????????????????? uwsgi_temp conf??????????????????? html????????? nginx?????????????? scgi_params?????????? win-utf fastcgi.conf???? ???????koi-utf?????? nginx.bak?????????? scgi_params.default fastcgi.conf.default??? koi-win?????? nginx.conf????????? scgi_temp fastcgi_params????????? logs????????? nginx.conf.default? uwsgi_params fastcgi_params.default? mime.types??? proxy_temp??????? ??uwsgi_params.default [root@localhost nginx]# ./nginx -c nginx.conf [root@localhost nginx]# |
-t 不運行,而僅僅測試配置文件。Nginx將檢查配置文件的語法的正確性,并嘗試打開配置文件中所有引用的文件。
| [root@localhost nginx]# ./nginx -t nginx: the configuration file /usr/local/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/nginx.conf test is successful |
-v顯示nginx的版本
| [root@localhost nginx]# ./nginx -v nginx version: nginx/1.8.0 |
-V顯示nginx的版本,編譯器版本和配置參數(shù)
| [root@localhost nginx]# ./nginx -V nginx version: nginx/1.8.0 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC) built with OpenSSL 1.0.1c 10 May 2012 TLS SNI support enabled configure arguments: --sbin-path=/usr/local/nginx/nginx --conf-path=/usr/local/nginx/nginx.conf --pid-path=/usr/local/nginx/nginx.pid --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_stub_status_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-http_spdy_module --with-ipv6 --with-pcre=../pcre-8.37 --with-zlib=../zlib-1.2.8 --with-openssl=../openssl-1.0.1c --user=nginx --group=nginx [root@localhost nginx]# |
-s signal 發(fā)送一個信號給主進程,這些參數(shù)可以以下的參數(shù)中的一個:
| ./nginx –s stop | 快速關閉 |
| ./nginx –s quit | 優(yōu)雅關閉 |
| ./nginx –s reload | 重新加載配置文件,使用一個新的worker進程啟動一個新的worker進程,優(yōu)雅的關閉舊的worker進程。 |
| ./nginx –s reopen | 重新打開日志文件 |
?
Nginx控制信號
可以使用信號系統(tǒng)來控制主進程。默認,nginx將其主進程的pid寫入到/usr/local/nginx/nginx.pid文件中。通常傳遞參數(shù)給./configure或使用pid指令,來改變文件的位置。
主進程可以處理以下的信號:
| TERM,INT | 快速關閉 |
| QUIT | 從容關閉 |
| HUP | 重載配置 用新的配置開始新的工作進程從容關閉舊的工作進程。 |
| USR1 | 重新打開日志文件 |
| USR2 | 平滑升級可執(zhí)行程序 |
| WINCH | 從容關閉工作進程 |
盡管你不幣自己操作工作進程,但是,它們也支持一些信號:
| TERM,INT | 快速關閉 |
| QUIT | 從容關閉 |
| USR1 | 重新打開日志文件 |
?
Nginx啟動、停止、重啟命令
Nginx啟動
| [root@localhost nginx]# pwd /usr/local/nginx [root@localhost nginx]# ls client_body_temp??????? fastcgi_temp? mime.types.default? sbin????????????????? uwsgi_temp conf??????????????????? html?????? ???nginx?????????????? scgi_params?????????? win-utf fastcgi.conf??????????? koi-utf?????? nginx.bak?????????? scgi_params.default fastcgi.conf.default??? koi-win?????? nginx.conf????????? scgi_temp fastcgi_params????????? logs????????? nginx.conf.default ?uwsgi_params fastcgi_params.default? mime.types??? proxy_temp????????? uwsgi_params.default [root@localhost nginx]# ./nginx [root@localhost nginx]# |
Nginx從容停止命令,等待所有請求結束后關閉服務:
ps –ef | grep nginx
kill –QUIT nginx主進程號
| [root@localhost nginx]# ps -ef | grep nginx root???? 18252???? 1? 0 15:35 ???????? 00:00:00 nginx: master process ./nginx nginx??? 18253 18252? 0 15:35 ???????? 00:00:00 nginx: worker process nginx??? 18254 18252? 0 15:35 ???????? 00:00:00 nginx: worker process root???? 18304 14028? 0 15:37 pts/0??? 00:00:00 grep nginx [root@localhost nginx]# kill -QUIT 18252 |
| [root@localhost nginx]# ps -ef | grep nginx root???? 18389 14028? 0 15:40 pts/0??? 00:00:00 grep nginx [root@localhost nginx]# ./nginx [root@localhost nginx]# ps -ef | grep nginx root???? 18393???? 1? 0 15:40 ???????? 00:00:00 nginx: master process ./nginx nginx??? 18394 18393? 0 15:40 ???????? 00:00:00 nginx: worker process nginx??? 18395 18393? 0 15:40 ???????? 00:00:00 nginx: worker process root???? 18399 14028? 0 15:40 pts/0??? 00:00:00 grep nginx [root@localhost nginx]# kill -QUIT `cat /usr/local/nginx/nginx.pid` [root@localhost nginx]# ps -ef | grep nginx root???? 18447 14028? 0 15:42 pts/0??? 00:00:00 grep nginx [root@localhost nginx]# |
?
Nginx快速停止命令,立刻關閉nginx進程
ps -ef | grep nginx
kill –TERM nginx主進程號
| [root@localhost nginx]# ./nginx [root@localhost nginx]# ps -ef | grep nginx root???? 18503???? 1? 0 15:44 ???????? 00:00:00 nginx: master process ./nginx nginx??? 18504 18503? 0 15:44 ???????? 00:00:00 nginx: worker process nginx??? 18505 18503? 0 15:44 ???????? 00:00:00 nginx: worker process root???? 18508 14028? 0 15:44 pts/0??? 00:00:00 grep nginx [root@localhost nginx]# kill -TERM 18503 [root@localhost nginx]# ps -ef | grep nginx root???? 18557 14028? 0 15:46 pts/0??? 00:00:00 grep nginx [root@localhost nginx]# |
如果以上命令不管用,可以強制停止:
Kill -9 nginx主進程號
?
如果嫌麻煩可以不用查看進程號,直接使用命令進行操作
其中/usr/local/nginx/nginx.pid為nginx.conf中的pid命令設置的參數(shù),用來存放nginx主進程號的文件
Kill –信號類型(HUP|TERM|QUIT) `cat /usr/local/nginx/nginx.pid`
例如:
kill -QUIT `cat/usr/local/nginx/nginx.pid`
?
nginx重啟命令:
1簡單型,先關閉進程,修改你的配置后,重啟進程。
kill -QUIT `cat/usr/local/nginx/nginx.pid`
./nginx
?
2 重新加載配置文件,不重啟進程,不會停止處理請求
3 平滑更新nginx二進制,不會停止處理請求
?
?
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的04_Nginx命令行参数,控制信号,Nginx启动、停止、重启命令的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 02_Nginx基本配置与参数说明 +
- 下一篇: 超频三有锂电概念吗 18年收购了锂电材料