How to restart or reload NGINX on Ubuntu 20.04 server

We will show all the main commands which we can use on the Ubuntu 20.04/18.04/16.04 server for restarting and reloading NGINX web server services. Furthermore, the article will also show the method to get the NGINX configuration file path to know any error.

Nginx is the well-known web server that is using by various web hosting services, even as a reverse proxy. It is popular because of its lightweight and cache capabilities, this is one of the main reasons why people prefer it. It can be used with Varnish Cache to implement a high Cache enabled webserver. However, that is not what we here for.

Many times after installing Nginx in a production environment, we don’t need to fully restart it, unlike other services because the various web applications rely on it. Well, in case you want to reload or restart NGINX after modifying some files, web application path, or any other settings, here are the commands for that.

Steps to reload or restart NGINX server on Ubuntu

The below-given steps will work on Debian, Ubuntu 20.04/18.04/17.04/16.04, Linux Mint, and other similar operating systems. To follow the commands given here you need user access on a server with sudo rights.

To check Nginx Confgiuration file

The command that will not only show the path of configuration file but also checks and let us know everything in it is error-free.  In case if there is an error on that then before restarting the NGINX server you would know that. This is really helpful in case we are using the webserver for commercial purposes and not for testing, thus prevents unnecessary downtime.

Type:

sudo nginx -t

If everything is working fine, you will get something like the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Graceful Reload

You don’t need to fully restart the Nginx server to reflect some changes you have made in the configuration file, the graceful reload will work for that.  The benefit of it is, the command will reload the configuration file of Nginx but also won’t disconnect the current established users’ connections to the webserver. Thus, the front-end users will not be affected.

sudo systemctl reload nginx

Fully Restart Nginx

In case you don’t want to reload just the configuration file instead of the full restart of all Nginx services along interrupting the concurrent connection to the webserver then use the below command:

sudo systemctl restat nginx

Check the status

Once you restarted the webserver and now want to check everything on it is working fine, use the below syntax:

sudo systemctl status nginx

 

Reload or restart Nginx on Ubuntu 20.04 LTS server

In this way, we can restart and reload the Nginx server on Ubuntu Linux using a single command or the other mentioned in the article. It’s all depending upon the situation in which you are.

Read More:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.