Home / Localhost / nginx commands

nginx commands: test config, reload, restart, stop

Test your nginx config with nginx -t, then reload safely, and know the difference between reload, restart, stop and quit.

Always test before you reload. nginx -t checks the configuration file, and nginx -s reload applies it without dropping connections. If the new config is wrong, nginx keeps running with the old one.

Change the config safely

  1. Edit your nginx config (for example with our reverse proxy generator).
  2. Run sudo nginx -t to test it. Fix anything it reports.
  3. Run sudo nginx -s reload, or sudo systemctl reload nginx on systemd systems.
  4. Open the site and check it. Look at the error log if it fails.

Commands you can copy

Test the config
sudo nginx -t
Test and print the config
sudo nginx -T
Reload (graceful)
sudo nginx -s reload
Reload with systemd
sudo systemctl reload nginx
Fast stop
sudo nginx -s stop
Graceful stop
sudo nginx -s quit
Reopen log files
sudo nginx -s reopen
Use another config file
sudo nginx -c /path/to/nginx.conf -t
Show version and build options
nginx -V
Find nginx processes
ps -ax | grep nginx

What each one does

nginx -t
Checks the syntax, then tries to open the files the configuration refers to. -T does the same and also prints the configuration. -q hides non-error messages while testing. A line such as test is successful means it is safe to reload.
reload
The master process checks the new configuration. If it is fine, it starts new workers and tells old workers to finish their current requests and exit, so visitors are not cut off. If the check fails, nginx rolls back and keeps working with the old configuration.
stop vs quit
stop is a fast shutdown. quit is graceful: workers finish current requests first. nginx’s own guide says to run these as the same user that started nginx.
restart
There is no restart signal in nginx’s own commands. systemctl restart nginx stops and starts the service, which drops open connections. Prefer reload for config changes.
Config test passes but the site is down
Look at the error log. A 502 Bad Gateway means the app behind nginx is not reachable, and a 403 usually means file permissions.
Address already in use
Another program or an old nginx holds the port. Find it with the port finder.
Log rotation
Rename the log file, then run nginx -s reopen so nginx starts writing to a new one.

Questions about nginx commands

Should I use reload or restart?
Reload for configuration changes. It is graceful and falls back to the old config if the new one is invalid. Restart only when reload is not enough.
Does nginx -t change anything?
No. It only checks the configuration.
Where is the nginx config file?
Run nginx -t. It prints the path of the main file it tested, usually /etc/nginx/nginx.conf on Linux.
Why does nginx -s reload say it cannot find the pid file?
nginx is not running, or you are not the user that started it. Start it first, or use sudo.

Updated 2026-10-24

Config generators for this

Related pages