04_Nginx命令行参数,控制信号,Nginx启动、停止、重启命令,04_nginxnginx




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

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的版本,编译器版本和配置参数

[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 发送一个信号给主进程,这些参数可以以下的参数中的一个:

./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

从容关闭工作进程

尽管你不币自己操作工作进程,但是,它们也支持一些信号:

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.pidnginx.conf中的pid命令设置的参数,用来存放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二进制,不会停止处理请求

 

 

相关内容

    暂无相关文章