How to restart NGINX on Linux

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

In this article, we’ll go over a couple different command line options for restarting and reloading an NGINX server. In addition, you’ll learn how to check the NGINX configuration file for mistakes before restarting NGINX. After all, you wouldn’t want to load up a configuration that contains errors.

In this tutorial you will learn:

  • How to reload NGINX (no effect on client connections)
  • How to completely restart NGINX

Restarting NGINX web server on Linux

Restarting NGINX web server on Linux

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any Linux distro
Software NGINX
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

How to restart NGINX

Using systemctl, there are two different options for restarting NGINX:

  • reload – reloads the configuration file but doesn’t fully exit NGINX or close current connections
  • restart – completely restart NGINX, which also closes connections and reloads the configuration file

Those commands will also check the configuration file for errors and alert you if any are found, but in a production environment it’s always a good idea to check the configuration file for potential syntax errors before reloading or restarting NGINX. Use the following command in 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 the configuration file is okay, use one of the following commands for the configuration changes to take effect.

  1. Gracefully reload NGINX web server:
    $ sudo systemctl reload nginx
  2. Fully restart 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’s 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 pick whichever command is most appropriate for your situation and be sure to check your configuration file for syntax errors before doing so.

Comments and Discussions
Linux Forum