Nginx Commands You Should Know

Nginx, pronounced “engine x”, is a free, open-source, high-performance HTTP and reverse proxy server that handles the load of some of the largest sites on the Internet. It can run as a standalone web server and as a reverse proxy for Apache and other web servers.
If you are a developer or system administrator, chances are that you are dealing with Nginx on a regular basis. This guide covers the most important and frequently used Nginx commands, including starting, stopping, restarting, and reloading Nginx, along with commands for testing the configuration and reading the logs.
Before You Begin
The commands in this guide assume you are logged in as root or as a user with sudo privileges. They work on any modern Linux distribution that ships Nginx as a systemd service, including Ubuntu , Debian, Fedora, RHEL, and derivatives.
Starting Nginx
Starting Nginx is straightforward. Run the following command:
sudo systemctl start nginxOn success, the command does not produce any output.
If your system does not use systemd, start the service through the older service wrapper:
sudo service nginx startInstead of starting Nginx by hand after every reboot, set it to start on system boot:
sudo systemctl enable nginxYou can combine enabling and starting into a single command with --now:
sudo systemctl enable --now nginxStopping Nginx
Stopping Nginx shuts down every Nginx worker process, even if there are open connections. To stop the service, run one of the following commands:
sudo systemctl stop nginx
sudo service nginx stopIf you want a graceful shutdown that lets in-flight requests finish first, use the signal interface described later in this guide.
Restarting Nginx
A restart is a quick stop followed by a start. Use it when reload cannot apply the change you made, for example when you change a listen directive or a system-level option:
sudo systemctl restart nginx
sudo service nginx restartYou may also want to see our dedicated guide on how to start, stop, and restart Nginx .
Reloading Nginx
You need to reload or restart Nginx whenever you change its configuration. The reload command loads the new configuration, starts new worker processes with it, and gracefully shuts down the old workers when their active connections finish:
sudo systemctl reload nginx
sudo service nginx reloadReload is preferable to restart for most configuration changes because it avoids dropped connections.
Testing the Nginx Configuration
Before reloading or restarting, test the configuration for syntax and system errors. A broken config will refuse to start the service and can take your site offline:
sudo nginx -tThe output of a valid configuration looks like this:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successfulIf the configuration is broken, nginx -t prints the failing line and a short explanation. Fix the error, test again, and only then reload.
Dumping the Effective Configuration
When nginx.conf includes files from /etc/nginx/conf.d/ or sites-enabled/, it can be hard to see what Nginx is actually running. The -T option tests the configuration and prints the full, merged content to standard output:
sudo nginx -TPipe it to less for easier reading, or to grep when you need to confirm that a specific directive is active:
sudo nginx -T | grep server_nameControlling Nginx with nginx -s
The Nginx binary accepts signals through the -s option. These are useful on systems without systemd and when you want to trigger a specific behavior without going through the service manager:
nginx -s reload- Reload the configuration, the same assystemctl 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 the log files. Use this after rotating logs so Nginx writes to the new files.
sudo nginx -s reloadViewing Nginx Status
To check whether Nginx is running, use systemctl status
:
sudo systemctl status nginxThe output looks something like this:
● nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2026-04-15 09:12:04 UTC; 2min 17s ago
Docs: man:nginx(8)
Process: 1043 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 1052 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 1053 (nginx)
Tasks: 3 (limit: 4613)
Memory: 4.2M
CPU: 18ms
CGroup: /system.slice/nginx.service
├─1053 "nginx: master process /usr/sbin/nginx -g daemon on; master_process on;"
├─1054 "nginx: worker process"
└─1055 "nginx: worker process"The Active: line tells you whether the service is running. Below it, you will see the master and worker processes along with their PIDs.
Checking the Nginx Version
Sometimes you need to know your Nginx version to debug an issue or to check whether a feature is available:
nginx -vnginx version: nginx/1.24.0 (Ubuntu)The -V option (uppercase) prints the version along with the build flags, including every compiled-in module and the OpenSSL version:
nginx -VThis is the fastest way to check whether a module is part of your Nginx build. If you are debugging certificates or TLS handshakes, pair it with the openssl command
to inspect the live certificate served by Nginx.
Viewing Nginx Logs
Nginx writes two log files by default: access log at /var/log/nginx/access.log and error log at /var/log/nginx/error.log. Follow the error log when you debug a failing request:
sudo tail -f /var/log/nginx/error.logOn systemd-based distributions, journalctl shows the startup and service-level messages that do not appear in the Nginx log files. This is where you will find the reason behind “job for nginx.service failed”:
sudo journalctl -u nginxAdd -f to follow new entries live, or -n 50 to see only the last 50 lines.
Quick Reference
| Action | Command |
|---|---|
| Start Nginx | sudo systemctl start nginx |
| Stop Nginx | sudo systemctl stop nginx |
| Restart Nginx | sudo systemctl restart nginx |
| Reload configuration | sudo systemctl reload nginx |
| Enable on boot | sudo systemctl enable nginx |
| Disable on boot | sudo systemctl disable nginx |
| Show status | sudo systemctl status nginx |
| Test configuration | sudo nginx -t |
| Dump full configuration | sudo nginx -T |
| Graceful shutdown | sudo nginx -s quit |
| Reopen log files | sudo nginx -s reopen |
| Print version | nginx -v |
| Print build flags | nginx -V |
| Read service logs | sudo journalctl -u nginx |
Troubleshooting
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
Another process already listens on port 80. Most often this is Apache on a fresh server. Stop it with sudo systemctl stop apache2 (or httpd on Fedora, RHEL, and derivatives), then start Nginx. Use sudo ss -ltnp | grep :80 to identify the process holding the port.
nginx -t reports a configuration error
Fix the reported file and line number before reloading. Reloading with a broken config leaves the old workers running and masks the problem until the next full restart.
systemctl status nginx shows failed
Run sudo journalctl -u nginx -n 50 to read the last 50 service log entries. Nginx prints the reason for the failed start there, such as a missing SSL certificate file or an invalid directive.
Changes to nginx.conf do not take effect
Reload applies the full effective configuration, including files brought in with include. If you edit a file that Nginx does not load from nginx.conf, reloading has no effect. Run sudo nginx -T to confirm your file is part of the effective configuration.
FAQ
What is the difference between sudo nginx -s reload and sudo systemctl restart nginx?sudo nginx -s reload loads the new configuration and lets existing worker processes finish their active requests before exiting, so there are no dropped connections. sudo systemctl restart nginx stops and starts the service, which briefly interrupts traffic. Use reload for configuration changes and restart only when reload cannot apply the change.
Does nginx -t need sudo?
Usually yes, because the test reads files that are owned by root such as SSL keys and snippets under /etc/nginx/. Running it without sudo often fails with a permission error even when the configuration itself is valid.
How do I start Nginx automatically at boot?
Run sudo systemctl enable nginx. To enable and start in one step on a fresh installation, use sudo systemctl enable --now nginx.
How do I check which Nginx modules are compiled in?
Run nginx -V. The command prints the build flags, including every --with-*_module option passed at compile time.
Conclusion
The commands above cover day-to-day Nginx operation: starting and stopping the service, reloading after a configuration change, testing the config before it hits production, and reading the logs when something goes wrong. For a deeper look at common deployment patterns, see our guide on using Nginx as a reverse proxy .
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page