Parameters and Signals

Like any other servers, Nginx has its operational instructions (parameters and signals).

The existence of these instructions makes it very convenient for us to manipulate the various configurations of Nginx. We can manipulate Nginx’s status, running path, test configuration files, etc. We can also reload Nginx’s configuration file at its runtime; this feature is handy for minor changes to Nginx while it’s running.

1. Parameters

Parameters can be used to manipulate Nginx to accomplish some basic tasks. With these parameters, we can: use a configuration file instead of the default one, change the global configuration directives, set the directory that keeps server files, test the configuration file syntaxes’ correctness, view Nginx’s versions and its configured parameters.

Configuration file

1
nginx -c file

Use an alternative configuration file instead of the default one.

Global configuration directive

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

This command assigns the worker_processes directive to the amount of logic CPUs, and save it to the configuration of the master related to the specified process id.

Server directory

1
nginx -p path

This command sets the root directory of Nginx server files.

Syntax Validating

1
nginx -t

This command searches the syntaxes correctness of all the configuration files. If we want to print the configuration files’ contents on the screen when testing, we can use -T parameter instead, so I think this upper-case parameter is not that useful, If you used it, you’d feel the same way.

Nginx version

1
nginx -v

The -v parameter only shows the version of Nginx. If we want to see not only the version of Nginx but also the version of the GCC compiler built it, we can use -V instead, and this upper-case parameter also shows the configured arguments of Nginx.

Syntax Validating with or without error

1
nginx -t -q

The -q parameter hides the non-error messages while testing the syntaxes of Nginx’s configuration files.

Signal Sending

1
nginx -s behavior_of_nginx

2. Signal Usages

Nginx allows us to change its processes status through sending a signal to its master process, and the signals we use often are: stop, quit, reload, reopen.

Fast Shutdown

1
nginx -s stop

The stop signal terminates all Nginx related processes immediately, especially the master and worker processes.

Graceful Shutdown

1
nginx -s quit

The quit signal waits for worker processes to finish serving current requests before terminates them.

Reopen Log File

1
nginx -s reopen

The reopen signal asks Nginx to try to reopen a log file, and it creates one if the log file doesn’t exist. Without this instruction, Nginx keeps writing logs to the original log file, even if we rename it by using mv command.

Reload Configuration Files

1
nginx -s reload

The reload signal is a frequently used signal; it reloads all Nginx configuration files at runtime.

References: Nginx Beginner’s Guide

If you think the content of this article has helped you, and if you would like some more high-quality materials in the near future, please give me some modest support.

Buy me a coffeeBuy me a coffee