跳转至

Nginx Command Set

nginx -?

Instruction:

Print help for command-line parameters.

Example:

nginx -h

nginx -h

Instruction:

Print help for command-line parameters.

Example:

nginx -h

nginx -c file

Instruction:

Use an alternative configuration file instead of a default file.

Example:

nginx -c /app/nginx/custom_nginx.conf

nginx -e file

Instruction:

Use an alternative error log file to store the log instead of a default file (1.19.5). The special value stderr selects the standard error file.

Example:

nginx -e /app/nginx/custom_error.log
nginx -t -c /usr/local/etc/nginx/nginx.conf -e /tmp/nginx_errors.log

Supplementary explanation:

用于将错误日志输出到指定的文件中,而不是使用配置文件中定义的日志路径或默认的标准错误输出(通常是终端)。 常见用途是调试、测试、临时记录日志,风险会覆盖配置文件中 error_log 的设置。

nginx -g

Instruction:

Set global configuration directives, for example, nginx -g "pid /var/run/nginx.pid; worker_processes sysctl -n hw.ncpu;"

Example:

nginx -g "worker_processes 4; error_log /var/log/nginx/error.log warn;";

Supplementary explanation:

nginx -g 在启动 Nginx 时指定全局配置指令。覆盖或设置一些全局的配置参数。用于临时更改配置或者在命令行上快速测试某些配置,不重载配置文件。

nginx -p prefix_path

Instruction:

Set nginx path prefix, i.e. a directory that will keep server files (default value is /usr/local/nginx).

Example:

nginx -p /home/user/nginx_test/ -c /path/to/custom/nginx.conf

Supplementary explanation:

nginx -p prefix 是 Nginx 提供的一个命令行参数,用于指定 Nginx 运行时的前缀路径(prefix path)。这个前缀路径主要用于确定 Nginx 查找其默认配置文件、日志文件以及其他相关文件(如 MIME 类型定义文件等)的基础目录。默认情况下,Nginx 的前缀路径通常是安装目录,但是通过 -p 参数,你可以临时改变这一基础目录来指向任何你希望的位置。

  • 测试新配置而不影响现有服务

nginx -q

Instruction:

Suppress non-error messages during configuration testing.

Example:

nginx -q

# @since 1.28

在配置测试期间抑制非错误消息。

-s signal

Send a signal to the master process. The argument signal can be one of:

  • stop — Shut down quickly
  • quit — Shut down gracefully
  • reload — Reload configuration, start the new worker process with a new configuration, gracefully shut down old worker processes. reopen — reopen log files

Example:

nginx -s

nginx -t

Test the configuration file: nginx checks the configuration for correct syntax, and then tries to open files referred in the configuration.

Example:

nginx -t

# nginx: the configuration file /app/nginx/conf/nginx.conf syntax is ok
# nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
# nginx: configuration file /app/nginx/conf/nginx.conf test failed

nginx -T

Same as -t, but additionally dump configuration files to standard output (1.9.2).

Example:

nginx -T

# nginx: the configuration file /app/nginx/conf/nginx.conf syntax is ok
# nginx: [emerg] bind() to 0.0.0.0:80 failed (13: Permission denied)
# nginx: configuration file /app/nginx/conf/nginx.conf test failed

nginx -v

Print nginx version.

Example:

nginx -v

# nginx version: nginx/1.26.3

nginx -V

Print nginx version, compiler version, and configure parameters.

Example:

nginx -V

# nginx version: nginx/1.26.3
# built by gcc 13.3.0 (Ubuntu 13.3.0-6ubuntu2~24.04) 
# built with OpenSSL 3.0.13 30 Jan 2024
# TLS SNI support enabled
# configure arguments: --prefix=/app/nginx --user=ubuntu --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-stream --with-stream_ssl_module --with-http_gzip_static_module --with-http_realip_module