Nginx Commands

Complete Nginx commands reference — 25 commands across 3 categories. Quick reference cheat sheet for Linux & Unix.

nginx has almost no interactive interface — it is driven by a dozen command-line switches and a handful of signals to the master process — so this page is short but every row on it matters in an outage. The two things worth knowing cold are how to test a configuration before applying it and the difference between a fast stop and a graceful one.

Command Line Switches (12)

ShortcutAction
nginx -hprint help for command-line parameters
nginx -c fileuse an alternative configuration file instead of a default file
nginx -e fileuse an alternative error log file to store the log instead of a default file (1.19.5)
nginx -g directivesset global configuration directives, for example, nginx -g "pid /var/run/nginx.pid
nginx -l portenable nginx control REST API on a specified port or UNIX-domain socket (1.29.8). This
nginx -p prefixset nginx path prefix, i.e. a directory that will keep server files
nginx -qsuppress non-error messages during configuration testing
nginx -s signalsend a signal to the master process. The argument signal can be one of: stop - shut down
nginx -ttest the configuration file: nginx checks the configuration for correct syntax, and then tries
nginx -Tsame as -t, but additionally dump configuration files to standard output (1.9.2)
nginx -vprint nginx version
nginx -Vprint nginx version, compiler version, and configure parameters

Process Signals (6)

ShortcutAction
kill -TERMFast shutdown
kill -QUITGraceful shutdown
kill -HUPChanging configuration, keeping up with a changed time zone (only for FreeBSD and Linux)
kill -USR1Re-opening log files
kill -USR2Upgrading an executable file
kill -WINCHGraceful shutdown of worker processes

Additional Commands (7)

ShortcutAction
nginx -s reloadReload config
nginx -s stopStop server
nginx -s quitGraceful stop
systemctl status nginxCheck status
systemctl restart nginxRestart
tail -f /var/log/nginx/access.logAccess log
tail -f /var/log/nginx/error.logError log
📄 View Printable Cheat Sheet — Download as PDF or print · 🧩 Combine with other tools

Related Shortcut Pages

Docker systemctl / systemd Linux Ansible Vagrant Proxmox VE

Search 18,500+ shortcuts across 268 platforms

Explore All Platforms Practice Shortcuts
📜 Every shortcut on this page is taken from the official Nginx documentation — nginx.org

Test first, then reload

nginx -t parses the configuration and reports the first error with a file and line number; running it before every reload is the difference between a typo and a site outage, because a reload with a broken config is refused and the old workers keep serving. nginx -T does the same and dumps the fully resolved configuration, includes and all, which is the quickest way to answer "which server block is actually handling this host". nginx -s reload then applies the change: the master process starts new workers with the new config and lets the old ones finish their connections.

Stopping gracefully versus now

nginx -s quit and kill -QUIT on the master PID stop nginx gracefully, letting in-flight requests complete. nginx -s stop and kill -TERM drop everything immediately. kill -WINCH gracefully shuts down only the workers, which is used during binary upgrades together with kill -USR2, the signal that starts a new master from an upgraded executable while the old one keeps running. kill -USR1 reopens log files after logrotate moves them, without touching connections.

Everyday operations

On systemd hosts systemctl status nginx shows whether the service is up and the last few log lines, and systemctl restart nginx is the blunt instrument when a reload is not enough. tail -f /var/log/nginx/error.log is the first command to run when a site returns 502s — upstream connection errors land there — and tail -f /var/log/nginx/access.log confirms whether requests are arriving at all. nginx -V (capital V) lists compiled-in modules and configure flags, which settles "is the brotli module even built in" arguments.

Frequently asked questions

What is the difference between nginx -s reload and systemctl restart nginx?

reload keeps serving while new workers start with the new config. restart stops the process and starts it again, dropping connections for a moment.

Why did my reload silently do nothing?

If nginx -t fails, the reload is refused and the running configuration stays. Check the error log or run nginx -t yourself to see the message.

How do I find which config file nginx is using?

nginx -V prints the compiled-in default path, and nginx -T dumps the configuration actually loaded, including every included file.

Which signal do I use after log rotation?

USR1 (kill -USR1 on the master PID) reopens the log files. Most logrotate configs for nginx already send it.

🤖 Ask AI about Nginx shortcuts

Open your assistant with this page preloaded as the source — great for follow-up questions like "which of these work in other apps?"

ChatGPT Claude Perplexity Gemini Grok
🔧 Spotted an error or a missing shortcut? Suggest an edit on GitHub — every accepted fix goes live on this page, the API and the CLI.