Nginx Commands You Should Know
In this guide, we will go over the most important and frequently used Nginx commands, including starting, stopping, and restarting Nginx.
Nginx pronounced “engine x” is a free, open-source, high-performance HTTP and reverse proxy server responsible for handling the load of some of the largest sites on the Internet. It can be used as a standalone web server, and as a reverse proxy for Apache and other web servers.
If you are a developer or system administrator, chances are that you’re dealing with Nginx on a regular basis.
Before You Begin
We’re assuming that you are logged in as root or user with sudo privileges. The commands in uide this gshould work on any modern Linux distribution like Ubuntu 18.04 and CentOS 8 and Debian 10 .
Starting Nginx is pretty simple. Just run the following command:
On success, the command doesn’t produce any output.
If you are running a Linux distribution without systemd to start Nginx type:
Instead of manually starting the Nginx service, it is recommended to set it to start on system boot:
Stopping Nginx quickly shuts down all Nginx worker processes even if there are open connections.
To stop Nginx, run one of the following commands:
The restart option is a quick way of stopping and then starting the Nginx server.
Use one of the following commands to perform an Nginx restart :
This is the command that you will probably use the most frequently.
You need to reload or restart Nginx whenever you make changes to its configuration.
The reload command loads the new configuration, starts new worker processes with the new configuration, and gracefully shuts down old worker processes.
To reload Nginx, use one of the following commands:
Testing Nginx Configuration
Whenever you make changes to the Nginx server’s configuration file, it is a good idea to test the configuration before restarting or reloading the service.
Use the following command to test the Nginx configuration for any syntax or system errors:
The output will look like below:
If there are any errors, the command prints a detailed message.
Viewing Nginx Status
To check the status of the Nginx service, use the following command:
The output will look something like this:
Checking Nginx Version
Sometimes you may need to know the version of your Nginx so you can debug an issue or determine whether a certain feature is available.
You can check your Nginx version by running:
The -V option displays the Nginx version along with the configure option.
In this guide, we have shown you some of the most essential Nginx commands. If you want to learn more about the Nginx command line options, visit the Nginx documentation .