
nginx 支持以下命令行参数-? | -h — 打印命令行参数的帮助。[rootS0 sbin]# ./nginx -?nginx version: nginx/1.16.1 Usage: nginx[-?hvVtTq][-s signal][-c filename][-p prefix][-g directives]Options: -?,-h:thishelp-v:show version andexit-V:show version and configure optionsthenexit-t:testconfiguration andexit-T:testconfiguration, dump it andexit-q:suppress non-error messages during configuration testing-ssignal:send signal to a master process: stop, quit, reopen, reload-pprefix:setprefix path(default: /usr/local/nginx/)-cfilename:setconfigurationfile(default: conf/nginx.conf)-gdirectives:setglobal directives out of configurationfile-c file — 使用可选的配置文件替换默认配置文件。默认配置文件路径为 $nginx_home/conf/nginx.cfg我们可以使用 -c 指定一个配置文件路径。如下[rootS0 nginx]# ./nginx -c /usr/test/nginx.cfg-g directives — 设置全局配置指令例如[rootS0 nginx]# ./nginx -g pid /var/run/nginx.pid; worker_processes sysctl -n hw.ncpu;-p prefix — 设置 nginx 路径前缀即保存服务器文件的目录 (默认值为/usr/local/nginx)。[rootS0 nginx]# ./nginx -p /opt/nginx-q — 在测试配置文件期间静默输出即不输出非错误消息。如果配置文件存在错误将输出错误信息。如下# 配置文件没有问题[rootS0 sbin]# ./nginx -tq# 配置文件有问题[rootS0 sbin]# ./nginx -tqnginx:[emerg]unexpected;in/usr/local/nginx/conf/nginx.conf:14 nginx: configurationfile/usr/local/nginx/conf/nginx.conftestfailed-s signal — 向主进程master发送一个信号。参数信号可以是stop — 快速关闭即使当前有正在处理的请求也立刻关闭。对应 kill 的 TERM, INT 信号quit — 优雅的关闭如果当前有正在处理的请求则等待请求处理完成后才关闭。对应 kill 的 QUIT 信号reload — 重新加载配置使用新配置启动新工作进程优雅地关闭旧工作进程。对应 kill 的 HUP 信号reopen — 重新打开日志文件。对应 kill 的 USR1 信号实例优雅的关闭 nginx[rootS0 sbin]# ./nginx -quit# 等价[rootS0 sbin]# kill -QUIT $(cat /usr/local/nginx/logs/nginx.pid)-t — 测试配置文件:nginx检查配置的语法是否正确然后尝试打开配置中引用的文件。[rootS0 sbin]# ./nginx -tnginx: the configurationfile/usr/local/nginx/conf/nginx.conf syntax is ok nginx: configurationfile/usr/local/nginx/conf/nginx.conftestis successful-T — 与-t相同但另外将配置文件转储到标准输出(1.9.2)。[rootS0 sbin]# ./nginx -Tnginx: the configurationfile/usr/local/nginx/conf/nginx.conf syntax is ok nginx: configurationfile/usr/local/nginx/conf/nginx.conftestis successful# configuration file /usr/local/nginx/conf/nginx.conf:#user nobody;worker_processes1;#error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;#pid logs/nginx.pid;events{worker_connections1024;}http{include mime.types;...-v — 打印 nginx 版本。实例[rootS0 sbin]# ./nginx -vnginx version: nginx/1.16.1-V — 打印nginx版本、编译器版本和配置参数。实例[rootS0 sbin]# ./nginx -Vnginx version: nginx/1.16.1 built by gcc4.4.720120313(Red Hat4.4.7-23)(GCC)configure arguments: