Skip to content

Nginx Command Set

Quick reference for the nginx executable command-line options. See also the official command-line documentation.

nginx -? / -h

Instruction:

Print help for command-line parameters.

Example:

nginx -h
nginx -?

nginx -c file

Instruction:

Use an alternative configuration file instead of the default.

Example:

nginx -c /app/nginx/custom_nginx.conf
nginx -t -c /usr/local/etc/nginx/nginx.conf

nginx -e file

Instruction:

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

Example:

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

Supplementary explanation:

Writes errors to the path given on the command line, overriding error_log in the configuration file (or the default stderr). Useful for debugging and one-off tests. Remember that this overrides the configured error_log for that process.

nginx -g directives

Instruction:

Set global configuration directives on the command line. Multiple directives are separated by semicolons.

Example:

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

Supplementary explanation:

Applies main-context directives at startup without editing the config file. Handy for temporary overrides or quick experiments. Does not replace a full config reload for production changes—use nginx -t then nginx -s reload after editing the real file.

nginx -p prefix

Instruction:

Set the nginx prefix path—the base directory for default config, logs, and related files (default is usually the install prefix, e.g. /usr/local/nginx).

Example:

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

Supplementary explanation:

Changes where nginx looks for relative paths (e.g. default conf/nginx.conf, logs/). Common when running multiple instances or testing a new layout without touching the system install.

Note

Combine with -c when the config lives outside the default prefix. Always run nginx -t before starting or reloading.

nginx -q

Instruction:

Suppress non-error messages during configuration testing (since 1.28).

Example:

nginx -t -q

Supplementary explanation:

Only errors are printed during -t / -T. Useful in scripts and CI when a silent success exit code is enough.

nginx -s signal

Instruction:

Send a signal to the master process. signal must be one of:

  • stop — fast shutdown
  • quit — graceful shutdown (finish in-flight requests)
  • reload — reload configuration; start new workers with the new config and gracefully stop old workers
  • reopen — reopen log files (often used after log rotation)

Example:

nginx -s reload
nginx -s quit
nginx -s reopen

Supplementary explanation:

Requires a running nginx instance and appropriate permissions (often root or the same user that started nginx). After editing config, always run nginx -t before nginx -s reload.

nginx -t

Instruction:

Test the configuration file: check syntax and attempt to open files referenced in the configuration.

Example:

nginx -t

# nginx: the configuration file /app/nginx/conf/nginx.conf syntax is ok
# nginx: configuration file /app/nginx/conf/nginx.conf test is successful
# Example failure (e.g. bind without permission):
# 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

Instruction:

Same as -t, but also dump the merged configuration to standard output (since 1.9.2).

Example:

nginx -T

Supplementary explanation:

Helpful to verify which files were included and how include directives resolved. Output can be large on complex deployments.

nginx -v

Instruction:

Print the nginx version.

Example:

nginx -v
# nginx version: nginx/1.26.3

nginx -V

Instruction:

Print nginx version, compiler version, and configure arguments.

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 --with-http_v2_module ...

Supplementary explanation:

Use before opening a support ticket or comparing binaries across servers—confirms which modules were compiled in (e.g. --with-stream, --with-http_v3_module).