Nginx is a high-performance web server and reverse proxy trusted by some of the largest sites on the internet. This guide covers the commands you reach for every day: starting and stopping the service, reloading configuration without dropping connections, testing config before it goes live, and reading the logs when something breaks.
These commands assume root or sudo access on a modern Linux distribution running Nginx as a systemd service.
Start Nginx:
bashsudo systemctl start nginx # start the servicesudo systemctl enable nginx # enable start on bootsudo systemctl enable --now nginx # enable and start in one step
On systems without systemd, use sudo service nginx start as a fallback.
Stop Nginx terminates every worker process immediately, even if connections are still open. For a graceful stop that lets in-flight requests finish first, use nginx -s quit instead (covered in the signals section below):
bashsudo systemctl stop nginx
Restart Nginx when reload cannot apply a change — for example, when you modify a listen directive or a system-level option:
bashsudo systemctl restart nginx
Reload Nginx for most configuration changes. It loads the new config, starts fresh worker processes, and gracefully shuts down the old workers once their active connections finish — no dropped connections:
bashsudo systemctl reload nginx
Reload is the right command for nearly every configuration change. Only fall back to restart when reload cannot apply the update.
Always test before reloading or restarting. A broken config will prevent Nginx from starting and can take your site offline:
bashsudo nginx -t
Valid output:
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
If the configuration is broken, nginx -t prints the failing file, line number, and a short explanation. Fix the error and test again before reloading.
Dump the full effective configuration with -T (uppercase). When nginx.conf includes files from conf.d/ or sites-enabled/, it can be hard to see what Nginx is actually running. -T tests the configuration and prints the complete merged result:
bashsudo nginx -Tsudo nginx -T | grep server_name # confirm a specific directive is active
Note: nginx -t usually requires sudo. It reads SSL key files and root-owned snippets under /etc/nginx/. Running it without sudo often fails with a permission error even when the configuration itself is valid.
The Nginx binary accepts signals through -s. These are useful on systems without systemd or when you need behavior the service manager does not expose:
| Signal | Effect |
|---|---|
nginx -s reload | Reload configuration (same as systemctl reload nginx) |
nginx -s stop | Fast shutdown: workers terminate immediately |
nginx -s quit | Graceful shutdown: workers finish active requests before exiting |
nginx -s reopen | Close and reopen log files after log rotation |
quit vs stop: quit is graceful; stop drops active connections immediately. Use nginx -s reopen after rotating logs — without it, Nginx keeps writing to the old renamed file instead of the new one.
Check service status:
bashsudo systemctl status nginx
The Active: line shows whether Nginx is running. Below it, you see the master process PID and the worker PIDs.
Check the version:
bashnginx -v # version only: nginx/1.24.0 (Ubuntu)nginx -V # version + all build flags, compiled modules, and OpenSSL version
-V (uppercase) is the fastest way to check whether a specific module is part of your Nginx build.
Read the logs:
bashsudo tail -f /var/log/nginx/error.log # follow error log livesudo journalctl -u nginx # startup and service-level messagessudo journalctl -u nginx -n 50 # last 50 entries
Nginx writes to /var/log/nginx/access.log and /var/log/nginx/error.log. For startup failures like “job for nginx.service failed”, the reason appears in journalctl -u nginx — not in the Nginx log files themselves.
Use nginx -t before every reload, reload instead of restart for config changes, nginx -T | grep to verify a directive is active, and journalctl -u nginx when the service fails to start. Leave a comment below if you run into any issues.