Skip to content
Log In Sign Up info@muvcloud.com

The Short Answer

sudo nginx -t && sudo systemctl reload nginx

The reload runs only if the test passes. The commands are the same on Ubuntu, Debian, AlmaLinux, and Rocky Linux.

All the Service Commands

CommandWhat it does
systemctl start nginxStarts Nginx
systemctl stop nginxStops it
systemctl restart nginxStops, then starts
systemctl reload nginxApplies a new configuration
systemctl status nginxShows state and recent log lines
systemctl enable nginxStarts it at boot

Put sudo in front of every command except status.

Reload or Restart?

  • Reload: the master process reads the new configuration and checks it. If it is valid, new worker processes start, and the old ones stop accepting connections, finish their current requests, and then exit, so no request in progress is cut off. If it is invalid, Nginx logs the error and keeps serving with the old configuration.
  • Restart: every process stops, open connections are cut, and Nginx starts again. If the configuration is broken, the start fails and the site stays down until you fix it.

Reload after configuration changes and new certificates. Restart only when Nginx does not respond or a reload did not help.

Always Test First

sudo nginx -t

A valid configuration gives two lines that end in "syntax is ok" and "test is successful". An error gives an [emerg] line with the file and line number, often a missing semicolon or brace. Fix it and test again. sudo nginx -T tests and also prints the whole configuration; see where is the Nginx configuration file.

The nginx -s Signals

CommandEffect
nginx -s reloadReloads the configuration
nginx -s reopenReopens the log files
nginx -s quitStops after current requests
nginx -s stopStops at once

Run them with sudo, as the same user that started Nginx. On a systemd server, prefer systemctl for starting and stopping, so systemd keeps track of the service. nginx -s reopen is useful after moving log files; see Nginx logs.

Check That It Runs

systemctl is-active nginx
ps -o pid,user,cmd -C nginx

The second command lists one master process owned by root and the worker processes, which run as www-data on Debian and Ubuntu and as nginx on AlmaLinux and Rocky Linux. After a reload the worker process IDs change.

Start at Boot

sudo systemctl enable --now nginx
systemctl is-enabled nginx

Debian and Ubuntu enable Nginx when it is installed. AlmaLinux and Rocky Linux do not, so run the first line once there. More about services in how to list services with systemctl.

When Nginx Will Not Start

sudo journalctl -u nginx -n 50 --no-pager

The journal shows why the start failed; see journalctl. The usual causes:

  • A configuration error: sudo nginx -t names the file and line.
  • Port already in use: another web server, often Apache, holds port 80 or 443. sudo ss -tlnp | grep -E ':(80|443) ' shows which program it is.
  • A missing certificate file: a server block points to a certificate path that does not exist.
  • SELinux and an unusual port: on AlmaLinux and Rocky Linux Nginx may only listen on ports labeled for web servers. sudo semanage port -l | grep http_port_t lists them, and sudo semanage port -a -t http_port_t -p tcp with the port number adds one. The command comes from the policycoreutils-python-utils package.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations