How to restart NGINX on Linux

Modified on Mon, 16 Dec, 2024 at 7:13 PM

NGINX is a popular web hosting and reverse proxy software for Linux systems. Like many other applications and services, it occasionally needs to be restarted. Restarting is especially common when updates are made to configuration files. You will always need to restart or reload NGINX for changes to take effect.


In this article, we will go over a couple of different command line options to restart and reload an NGINX server. Additionally, you will learn how to check the NGINX configuration file for errors before restarting NGINX. After all, you don't want to load a configuration that contains errors.


In this tutorial you will learn:


  • How to do a NGINX reload (no effect on client connections)
  • How to fully restart NGINX


Using systemctl, there are two different options to restart NGINX:


  • reload - reloads the configuration file but does not fully exit NGINX or close current connections
  • restart - fully restarts NGINX, which also closes connections and reloads the configuration file


Those commands will also check the configuration file for errors and alert you if they are found, but in a production environment it is always a good idea to check the configuration file for possible syntax errors before reloading or restarting NGINX.


Use the following command in the terminal to do that:

$ sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


Once NGINX confirms that the configuration file is OK, use one of the following commands to make the configuration changes take effect.


Method 1: Reload the NGINX web server gracefully:

$ sudo systemctl reload nginx


Method 2: Completely restart the NGINX web server:

$ sudo systemctl restart nginx


You can also use systemctl to check the current status of NGINX (i.e. to see if it is up and running or if the process is stopped) with the following command:

$ sudo systemctl status nginx

In this tutorial, we learned two different commands to restart NGINX on Linux. Always choose the command that is most appropriate for your situation, and be sure to check your configuration file for syntax errors before doing so.



Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article