nginx 命令行参数

2016-07-09  本文已影响1848人  C86guli

编译自:
http://nginx.org/en/docs/switches.html

nginx 支持以下的命令行参数:

执行:nginx -h(这里的 nginx 被配置为拥有与 yum 安装相同的编译参数,prefix=/etc/nginx)

命令行选项:

-?,-h : this help
-v : show version and exit
-V : show version and configure options then exit
-t : test configuration and exit
-T : test configuration, dump it 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: /etc/nginx/)
-c filename : set configuration file (default: /etc/nginx/nginx.conf)
-g directives : set global directives out of configuration file

-p prefix : 设置 nginx prefix 路径,这是存储 nginx 服务文件的路径,默认为 /etc/nginx

-c filename : 不使用默认配置文件,使用指定的配置文件(default: /etc/nginx/nginx.conf)

-g directives : 在配置文件之外设置全局指令,例如:

nginx -g "pid /var/run/nginx.pid; worker_processes `sysctl -n hw.ncpu`;"

-s signal (stop, quit, reopen, reload)

可参考《nginx 新手指引》的 nginx 启动、停止、重新加载配置小节:

nginx 启动、停止、重新加载配置
-------------------------------

执行 nginx 命令启动 nginx。启动 nginx 之后,可使用如下命令:
    nginx -s stop  快速关闭 nginx
    nginx -s quit  优雅的关闭 nginx
    nginx -s reload  重新加载配置
    nginx -s reopen  重新打开日志文件


优雅地关闭 nginx,这是说 nginx 主进程会等待 worker 进程完成当前用户请求的处理。
    执行:nginx -s quit (以启动 nginx 时的用户身份执行该命令)

更改配置之后,必须执行重新加载配置的命令,或者重新启动 nginx,以使得配置生效:
    nginx -s reload 

当主进程接收到 reload 信号,它会检查配置文件的语法,然后尝试应用该配置。如果成功,主进程
启动新的 worker 进程,并发送消息给原来的 worker 进程要求他们关闭。如果加载配置失败,主进程
会对改动进行回滚,继续以原来的配置进行工作。当原来的 worker 进程接收到消息要他们关闭,他们会
停止接收新的连接,并继续处理当前的请求直到完成。完成之后,原来的 worker 进程将会退出。

版权信息
本文编译自 nginx.org 的部分,遵循其原来的 licence 声明: 2-clause BSD-like license

上一篇 下一篇

猜你喜欢

热点阅读