天天看點

04_Nginx指令行參數,控制信号,Nginx啟動、停止、重新開機指令



nginx支援一下指令行參數

-? | -h   列印出指令行參數的幫助

[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

  -s signal     : send signal to a master process: stop, quit, reopen, reload

-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

-v顯示nginx的版本,編譯器版本和配置參數

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

-s signal 發送一個信号給主程序,這些參數可以以下的參數中的一個:

./nginx –s stop

快速關閉

./nginx –s quit

優雅關閉

./nginx –s reload

重新加載配置檔案,使用一個新的worker程序啟動一個新的worker程序,優雅的關閉舊的worker程序。

./nginx –s reopen

重新打開日志檔案

nginx控制信号

可以使用信号系統來控制主程序。預設,nginx将其主程序的pid寫入到/usr/local/nginx/nginx.pid檔案中。通常傳遞參數給./configure或使用pid指令,來改變檔案的位置。

主程序可以處理以下的信号:

term,int

quit

從容關閉

hup

重載配置

用新的配置開始新的工作程序從容關閉舊的工作程序。

usr1

usr2

平滑更新可執行程式

winch

從容關閉工作程序

盡管你不币自己操作工作程序,但是,它們也支援一些信号:

nginx啟動、停止、重新開機指令

nginx啟動

conf                    html          nginx               scgi_params           win-utf

fastcgi.conf            koi-utf       nginx.bak           scgi_params.default

fastcgi_params          logs          nginx.conf.default  uwsgi_params

fastcgi_params.default  mime.types    proxy_temp          uwsgi_params.default

[root@localhost nginx]# ./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     18389 14028  0 15:40 pts/0    00:00:00 grep 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     18447 14028  0 15:42 pts/0    00:00:00 grep nginx

nginx快速停止指令,立刻關閉nginx程序

ps -ef | grep nginx

kill –term 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     18557 14028  0 15:46 pts/0    00:00:00 grep nginx

如果以上指令不管用,可以強制停止:

kill -9 nginx主程序号

如果嫌麻煩可以不用檢視程序号,直接使用指令進行操作

其中/usr/local/nginx/nginx.pid為nginx.conf中的pid指令設定的參數,用來存放nginx主程序号的檔案

kill –信号類型(hup|term|quit) `cat /usr/local/nginx/nginx.pid`

例如:

kill -quit `cat/usr/local/nginx/nginx.pid`

nginx重新開機指令:

1簡單型,先關閉程序,修改你的配置後,重新開機程序。

./nginx

2 重新加載配置檔案,不重新開機程序,不會停止處理請求

3 平滑更新nginx二進制,不會停止處理請求