Nginx is a high-performance web server commonly used for serving websites, reverse proxying, and load balancing. Whether you’re updating configuration files or applying security patches, you’ll often need to reload or restart Nginx. This guide explains the difference between reloading and restarting, and how to perform each action safely on a virtual server or private server
Action | Description |
---|---|
Reload | Gracefully reloads configuration without killing active connections. Preferred after config edits. |
Restart | Stops and restarts Nginx completely. Used for deeper changes or full resets. |
Tip: Always run a configuration test before reloading to avoid downtime due to errors.
Before reloading or restarting, check that your config is valid:
sudo nginx -t
If everything is OK, you’ll see:
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
Use this when you change settings in /etc/nginx/nginx.conf or add/edit virtual hosts.
sudo systemctl reload nginx
sudo service nginx reload
This tells Nginx to re-read its config without interrupting ongoing connections.
Use this when Nginx is unresponsive or after major updates.
sudo systemctl restart nginx
sudo service nginx restart
This stops and starts Nginx, so it interrupts all current sessions. Use with caution on production servers.
You can also send a HUP signal manually:
sudo kill -HUP $(cat /var/run/nginx.pid)
This works the same as a reload and is useful in custom scripting.
sudo tail -n 50 /var/log/nginx/error.log
Reloading is safe for live servers and should be your default option after configuration changes. Restarting is useful for full resets or if Nginx becomes unstable. In either case, always test your config before applying changes.