Knowing the test-then-reload routine prevents taking a site down with a typo.
Install from your distribution (apt install nginx), from nginx.org's own package repositories for newer versions, or run the official nginx Docker image. Typical file locations on Linux:
/etc/nginx/nginx.conf: the main configuration file./etc/nginx/conf.d/*.conf(and on Debian/Ubuntusites-enabled/): per-site files included from the main file./var/log/nginx/access.loganderror.log: logs./usr/share/nginx/htmlor/var/www/html: default content.
The command-line tool controls everything:
nginx -t: test the configuration syntax and referenced files without touching the running server. Always run it before reloading.nginx -T: test and print the full effective configuration, includes expanded. Great for debugging.nginx -s reload(orsystemctl reload nginx): graceful reload. The master process re-reads the configuration, starts new workers, and old workers finish their current requests before exiting. No connections are dropped.nginx -s quitfor graceful shutdown,nginx -Vfor the version and compiled-in modules.
If the new configuration is invalid, a reload keeps the old configuration running and logs the error, but a full restart would fail to start at all. That's one more reason to prefer reload and to test first.
Example
sudo apt install nginx
nginx -v # nginx version: nginx/1.30.6
sudo nginx -t
# nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
# nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo nginx -T | grep -n server_name # see the effective config
sudo nginx -t && sudo systemctl reload nginx
curl -sI http://localhost/ | head -2
# HTTP/1.1 200 OK
# Server: nginx/1.30.6
tail -f /var/log/nginx/error.logRemember
- nginx -t tests, nginx -T tests and prints the merged config
- reload is graceful: new workers start, old ones drain
- Logs live in /var/log/nginx by default
Watch out for
- Restarting instead of reloading: a broken config then leaves no server running.