Operations 5 min read

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.

Architect Chen
Architect Chen
Architect Chen
The Complete 2026 Guide to Nginx Commands

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 reload

Core mechanism:

Does not stop the service.

Worker processes are switched smoothly.

Configuration updates are applied without downtime.

3. Reopen Log Files

nginx -s reopen

Used for log rotation and to prevent log loss.

4. Configuration Check Commands

nginx -t

Example output:

nginx: configuration file /etc/nginx/nginx.conf test is successful

To check a specific configuration file: nginx -t -c /etc/nginx/nginx.conf Purpose: verify multi‑environment configurations.

5. View Compile Parameters

nginx -V

Shows 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.log

8. 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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

operationslinuxNginxWeb Servercommand-lineServer Management
Architect Chen
Written by

Architect Chen

Sharing over a decade of architecture experience from Baidu, Alibaba, and Tencent.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.