nginx 支持以下命令行参数:
-? | -h — 打印命令行参数的帮助。
[root@S0 sbin]# ./nginx -? nginx version: nginx/1.16.1 Usage: nginx [-?hvVtTq] [-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 -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: /usr/local/nginx/) -c filename : set configuration file (default: conf/nginx.conf) -g directives : set global directives out of configuration file
-c file — 使用可选的配置文件替换默认配置文件。默认配置文件路径为 $nginx_home/conf/nginx.cfg,我们可以使用 -c 指定一个配置文件路径。如下:
[root@S0 nginx]# ./nginx -c /usr/test/nginx.cfg
-g directives — 设置全局配置指令,例如:
[root@S0 nginx]# ./nginx -g "pid /var/run/nginx.pid; worker_processes `sysctl -n hw.ncpu`;"
-p prefix — 设置 nginx 路径前缀,即保存服务器文件的目录 (默认值为/usr/local/nginx)。
[root@S0 nginx]# ./nginx -p /opt/nginx
-q — 在测试配置文件期间静默输出,即不输出非错误消息。如果配置文件存在错误,将输出错误信息。如下:
# 配置文件没有问题 [root@S0 sbin]# ./nginx -tq # 配置文件有问题 [root@S0 sbin]# ./nginx -tq nginx: [emerg] unexpected ";" in /usr/local/nginx/conf/nginx.conf:14 nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed
-s signal — 向主进程(master)发送一个信号。参数信号可以是:
stop — 快速关闭,即使当前有正在处理的请求,也立刻关闭。对应 kill 的 TERM, INT 信号
quit — 优雅的关闭;如果当前有正在处理的请求,则等待请求处理完成后才关闭。对应 kill 的 QUIT 信号
reload — 重新加载配置,使用新配置启动新工作进程,优雅地关闭旧工作进程。对应 kill 的 HUP 信号
reopen — 重新打开日志文件。对应 kill 的 USR1 信号
实例:优雅的关闭 nginx
[root@S0 sbin]# ./nginx -quit # 等价 [root@S0 sbin]# kill -QUIT $(cat /usr/local/nginx/logs/nginx.pid)
-t — 测试配置文件:nginx检查配置的语法是否正确,然后尝试打开配置中引用的文件。
[root@S0 sbin]# ./nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
-T — 与-t相同,但另外将配置文件转储到标准输出(1.9.2)。
[root@S0 sbin]# ./nginx -T nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful # configuration file /usr/local/nginx/conf/nginx.conf: #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; ...
-v — 打印 nginx 版本。实例:
[root@S0 sbin]# ./nginx -v nginx version: nginx/1.16.1
-V — 打印nginx版本、编译器版本和配置参数。实例:
[root@S0 sbin]# ./nginx -V nginx version: nginx/1.16.1 built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) configure arguments: