Nginx Commands You Should Know

By 

Updated on

7 min read

Start, Stop, Restart Nginx

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:

Terminal
sudo systemctl start nginx

On success, the command does not produce any output.

If your system does not use systemd, start the service through the older service wrapper:

Terminal
sudo service nginx start

Instead of starting Nginx by hand after every reboot, set it to start on system boot:

Terminal
sudo systemctl enable nginx

You can combine enabling and starting into a single command with --now:

Terminal
sudo systemctl enable --now nginx

Stopping 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:

Terminal
sudo systemctl stop nginx
sudo service nginx stop

If 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:

Terminal
sudo systemctl restart nginx
sudo service nginx restart

You 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:

Terminal
sudo systemctl reload nginx
sudo service nginx reload

Reload 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:

Terminal
sudo nginx -t

The output of a valid configuration looks like this:

output
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If 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:

Terminal
sudo nginx -T

Pipe it to less for easier reading, or to grep when you need to confirm that a specific directive is active:

Terminal
sudo nginx -T | grep server_name

Controlling 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 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 the log files. Use this after rotating logs so Nginx writes to the new files.
Terminal
sudo nginx -s reload

Viewing Nginx Status

To check whether Nginx is running, use systemctl status :

Terminal
sudo systemctl status nginx

The output looks something like this:

output
● 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:

Terminal
nginx -v
output
nginx 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:

Terminal
nginx -V

This 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:

Terminal
sudo tail -f /var/log/nginx/error.log

On 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”:

Terminal
sudo journalctl -u nginx

Add -f to follow new entries live, or -n 50 to see only the last 50 lines.

Quick Reference

ActionCommand
Start Nginxsudo systemctl start nginx
Stop Nginxsudo systemctl stop nginx
Restart Nginxsudo systemctl restart nginx
Reload configurationsudo systemctl reload nginx
Enable on bootsudo systemctl enable nginx
Disable on bootsudo systemctl disable nginx
Show statussudo systemctl status nginx
Test configurationsudo nginx -t
Dump full configurationsudo nginx -T
Graceful shutdownsudo nginx -s quit
Reopen log filessudo nginx -s reopen
Print versionnginx -v
Print build flagsnginx -V
Read service logssudo 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 .

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

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