15 Essential Nginx Commands Explained
This article provides a concise, step‑by‑step guide to the fifteen most frequently used Nginx commands, showing how to check versions, start, stop, reload, test configurations, view logs, monitor connections and ports, and troubleshoot common errors on Linux systems.
1. View Nginx version nginx -v Output example: nginx version: nginx/1.26.0. This command confirms the installed version and verifies successful installation.
Check current version
Validate Nginx installation
2. View detailed version information nginx -V Typical output includes the build compiler, configure arguments and enabled modules, e.g.:
nginx version: nginx/1.26.0
built by gcc 11.2.0
configure arguments: --with-http_ssl_module --with-http_v2_module ...Inspect compile parameters
List supported modules
Show installation path
3. Start Nginx nginx Starts the Nginx service using the default configuration file.
Launch Nginx service
Read default configuration
4. Start with a specific configuration file nginx -c /usr/local/nginx/conf/nginx.conf Useful for multi‑environment deployments.
Use a custom configuration file
Common in multi‑environment setups
5. Test configuration syntax nginx -t Checks the configuration for syntax errors; must be run before going live.
Detect syntax errors
Required before production deployment
Recommended workflow:
nginx -t
nginx -s reload6. View full configuration nginx -T Outputs the entire effective configuration, including files brought in by include directives.
Diagnose configuration overrides
Inspect final effective settings
7. Graceful reload nginx -s reload Reloads configuration without dropping existing connections.
Hot‑update configuration
Zero‑downtime for users
8. Fast stop nginx -s stop Immediately terminates the Nginx process; generally not recommended for production.
Forceful shutdown
Stops all worker processes instantly
9. Graceful shutdown nginx -s quit Waits for active requests to finish before stopping; preferred for production.
Allow in‑flight requests to complete
Then terminate processes
10. Reopen log files nginx -s reopen Used after log rotation to make Nginx start writing to the new log file.
Regenerate log files after rotation
11. View Nginx processes ps -ef | grep nginx Typical output shows the master process and worker processes with their PIDs.
Identify master process
Count worker processes
12. Check listening ports netstat -ntlp | grep nginx or ss -ntlp | grep nginx Shows ports (e.g., 0.0.0.0:80) that Nginx is listening on.
Verify listening ports
Confirm service status
13. View access log tail -f access.log Real‑time monitoring; use tail -100 access.log for the latest 100 lines or wc -l access.log to count page views.
Analyze traffic
Detect abnormal requests
14. View error log tail -f error.log Common errors include 502 Bad Gateway, 504 Gateway Timeout, and connection refusals.
Typical troubleshooting steps:
Identify user‑reported error
Check error.log Locate the failing backend service
Fix the underlying issue
15. Check connection counts netstat -an | grep ESTABLISHED | wc -l Shows total established connections. netstat -an | grep :80 | wc -l Shows connections on port 80. ss -s Displays TCP socket statistics.
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.
