The Complete 2026 Guide to Nginx Commands
This article provides a comprehensive, step‑by‑step reference of essential Nginx commands—including service control, graceful reload, log reopening, configuration validation, compile‑time options, process inspection, log monitoring, and status metrics—complete with example usages and explanations for production environments.
1. Basic Service Control Commands
The most important commands to start, stop, and restart Nginx are: nginx or systemctl start nginx Starts the Nginx master and worker processes. nginx -s stop Immediately kills worker processes, which may drop requests. nginx -s quit Waits for current requests to finish before exiting.
Recommended for production because it shuts down gracefully. systemctl restart nginx Equivalent to a stop followed by a start.
2. Smooth Reload (Zero‑Downtime Update)
nginx -s reloadCore mechanism:
Does not stop the service.
Worker processes are switched smoothly.
Configuration updates are applied without downtime.
3. Reopen Log Files
nginx -s reopenUsed for log rotation and to prevent log loss.
4. Configuration Check Commands
nginx -tExample output:
nginx: configuration file /etc/nginx/nginx.conf test is successfulTo check a specific configuration file: nginx -t -c /etc/nginx/nginx.conf Purpose: verify multi‑environment configurations.
5. View Compile Parameters
nginx -VShows compiled modules, path information, and version details.
6. Process Management
List Nginx processes: ps -ef | grep nginx Typical structure shows a master process and one or more worker processes.
Show master PID: cat /run/nginx.pid or cat /var/run/nginx.pid Manually kill a process (use with caution): kill -9 <pid> May cause connection interruptions.
Does not close gracefully.
7. Log Viewing (Troubleshooting Core)
Real‑time access log: tail -f /var/log/nginx/access.log Real‑time error log: tail -f /var/log/nginx/error.log Filter error messages:
grep "error" /var/log/nginx/error.log8. Status and Performance Metrics
Enable stub_status in the Nginx configuration:
location /nginx_status {
stub_status;
}Query the status endpoint: curl http://localhost/nginx_status Typical output includes active connections, accepts, handled, requests, and the numbers of reading, writing, and waiting connections.
These commands together form a practical reference for operating and troubleshooting Nginx in production environments.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Architect Chen
Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
