X
Popular Searches

How to Gracefully Restart nginx (And Why)

NGINX Logo
NGINX

After you make configuration changes to your web server or other service, you generally have to restart the process to get it to recognize the updated settings. The problem is that the regular restart first kills the process and all of the worker processes, and then starts it all up again — which will (briefly) make your website go offline.

The solution is to use the graceful restart feature to get the web server process to read in the new configuration changes without taking the server down. Luckily nginx, Apache, PHP-FPM, and many other services support this.

What actually happens is that nginx starts a new process with a new set of worker processes that accept requests, and the old worker processes are instructed to gracefully shut down. So any new visitors that come to your site won’t have to wait for the whole thing to restart.

Restart nginx Gracefully

There are multiple ways to do this, depending on what operating system you are using, but the one method that works on every platform is to just pass the reload signal to the nginx process directly. The -s argument to nginx is for passing a “signal” and that signal is “reload”.

nginx -s reload

This will only work if the nginx sbin directory is in your path, so realistically you’ll need to use the full path like this:

/usr/local/nginx/sbin/nginx -s reload

It’s worth noting that you should probably test the nginx configuration before you pass the reload command — you can do that with “nginx -t”.

You can also reload using the service command on distributions that support it (like Ubuntu or Debian). So the command would be this:

service nginx reload

Pretty simple.

Lowell Heddings Lowell Heddings
Lowell is the founder and CEO of LifeSavvy Media. He’s been running the show since creating How-To Geek back in 2006. Over the last decade, Lowell has personally written more than 1000 articles which have been viewed by over 250 million people. Prior to starting How-To Geek, Lowell spent 15 years working in IT doing consulting, cybersecurity, database management, and programming work. Read Full Bio »

The above article may contain affiliate links, which help support CloudSavvy IT.