Which command do I need?
| Goal | systemd | nginx signal | Drops connections? |
|---|---|---|---|
| Start | systemctl start nginx | run nginx | n/a |
| Apply a config change | systemctl reload nginx | nginx -s reload | No |
| Full restart | systemctl restart nginx | stop, then start | Yes, briefly |
| Stop gracefully | systemctl stop nginx | nginx -s quit | Finishes open requests |
| Stop at once | systemctl kill nginx | nginx -s stop | Yes |
| Reopen log files | n/a | nginx -s reopen | No |
On a systemd distribution, prefer the systemctl forms, so systemd keeps an accurate view of the service. The nginx -s signals are handy inside containers and on FreeBSD, where the service is controlled with service nginx reload instead.
What happens during a reload?
The master process reads the new configuration and checks it. If it is valid, the master starts new worker processes with the new settings and tells the old workers to stop accepting connections and exit once their current requests finish. Visitors see nothing. If the new configuration is broken, the master logs the error and keeps the old workers running, so a reload is safe even when you make a mistake. That is why it is the right tool for nearly every change: new server blocks, certificates, upstream addresses or cache settings.
You can watch it happen: run ps -o pid,etime,cmd -C nginx before and after; worker process ids change while the master id stays the same.
When is a restart actually needed?
A restart stops every process and starts fresh. Use it after upgrading the nginx package if you want the new binary immediately (Debian and Ubuntu packages handle that during the upgrade; check with nginx -v and the master's start time), after changing settings the master reads only at startup, such as a different user or certain module loads, or when workers are stuck on a hung upstream and will not drain. On a busy server a restart drops open connections for a moment, so schedule it.
nginx can also swap its binary with no downtime using the USR2 and WINCH signals. Few people need that on a single machine; a scheduled restart during quiet hours is simpler.
How do I test the config before applying it?
sudo nginx -t sudo nginx -t -c /etc/nginx/nginx.conf.next
The first checks the live configuration; the second checks an alternative file without touching the running service. Chain test and reload so a failed test stops the reload: sudo nginx -t && sudo systemctl reload nginx. To see the full merged config with every include expanded, use sudo nginx -T | less.
How do I make nginx start at boot?
sudo systemctl enable nginx systemctl is-enabled nginx
The Ubuntu and Debian packages enable it on install; the nginx.org and Enterprise Linux packages do not. After a panel reboot, systemctl status nginx confirms it came back up. For a quick check that sites answer after any restart, run curl -so /dev/null -w '%{http_code}\n' -H 'Host: www.example.net' http://127.0.0.1/.
Why will nginx not start?
Read the reason first: journalctl -u nginx -n 40 --no-pager. The usual causes:
- Address already in use. Another program holds port 80 or 443, often Apache or a second nginx started by hand. Find it with
sudo ss -ltnp 'sport = :443'and stop it. - Certificate file not found. A server block points at a missing or unreadable key. Fix the path or comment the block out, then test again.
- Permission denied on a socket or root folder. The nginx user cannot read the files. On Rocky and AlmaLinux, also check SELinux with
ausearch -m avc -ts recent. - Unknown directive. A module is not loaded or a directive belongs to a newer version than the one installed.
How does this fit with log rotation and backups?
logrotate rotates /var/log/nginx/*.log daily and sends USR1 to the master afterward (the same as nginx -s reopen), so nginx writes into the new files without a reload. If you copy logs off the box for analysis, grab the rotated .1 and .gz files, which are no longer being written. Back up /etc/nginx together with your site files; with config in git and a backup copy elsewhere (see Back up data with rsync), a reinstall from the panel and a restore gets a web server back fast.
New to nginx? Start with Install nginx on Ubuntu 22.04. If logs show a lot of probing, Set up fail2ban can ban the noisiest scanners automatically.
Budget Machines for Web Serving
| Server | Processor | Cores / threads | Memory | Storage | Network | Per month | Smallest order |
|---|---|---|---|---|---|---|---|
| E1 | Intel Xeon E3-1240 v3 | 4 / 8 | 16 GB DDR3 | 2x 240 GB SSD | 2x 1 Gbps | $30.52 | $91.56 (3 months) |
| S1 | Intel Xeon E-2276G | 6 / 12 | 64 GB DDR4 | 1x 1 TB NVMe | 2x 10 Gbps | $53.32 | $53.32 (1 month) |
| S3 | Intel Xeon E-2356G | 6 / 12 | 64 GB DDR4 | 2x 1 TB NVMe | 2x 10 Gbps | $80.38 | $80.38 (1 month) |
| S8 | Intel Xeon E-2388G | 8 / 16 | 128 GB DDR4 | 1x 1 TB NVMe | 2x 10 Gbps | $103.13 | $103.13 (1 month) |
Keep Reading
Install nginx on Ubuntu 22.04
Install nginx on Ubuntu 22.04 from the archive or the upstream repository, add a server block and open the firewall in a few minutes.
OpenKill a process
Stop processes the right way: find them, send TERM before KILL, use systemctl for services, and handle zombies and stuck D-state tasks.
OpenBack up data with rsync
Build dated, space-saving snapshot backups with rsync and hard links, pull them from a second machine and test restores.
OpenLet's Encrypt with nginx
Get free TLS certificates for nginx with certbot, choose the nginx or webroot method, and confirm automatic renewal works.
OpenFAQ
Quick Answers
No. A reload starts new workers with the new config and lets old ones finish their requests. A restart stops every process and starts again, which cuts open connections.
Yes. nginx keeps the old workers running and logs the error. Run nginx -t first anyway, so you see the problem right away.
Use systemctl stop nginx or nginx -s quit. Both let workers finish current requests before exiting.
Run systemctl status nginx, or ps -C nginx to see the master and worker processes.
Use service nginx start, stop, reload or configtest, and enable it with sysrc nginx_enable=YES.