Published on

Top 10 NGINX Commands You Should Know

Published on

Top 10 NGINX Commands You Should Know

In this tutorial, we will demonstrate top 10 NGINX commands that every system admin must know with examples.

Nginx is a free, open-source and the most popular web server that routes network traffic. It often used as reverse proxy server and can also used to configure the regular web server.

Top 10 NGINX Commands

Install Nginx Server

To install Nginx, run the below default distribution package manager as shown,

$ sudo yum install epel-release && yum install nginx   [On CentOS/RHEL] 
$ sudo dnf install nginx                               [On Debian/Ubuntu] 
$ sudo apt install nginx                               [On Fedora]

Check Nginx Version

To verify the version of Nginx on your Linux system, run the below command,

nginx -v

nginx version: nginx/1.17.0

The above command simply displays the version of Nginx. If you want to know the version and configure options then use the -V flag as shown.

nginx -V

Check Nginx Configuration Syntax

Before you start the server, make sure to verify whether the configuration syntax is correct or not.

This is useful when you made changes or added new configuration to the existing configuration.

Run the below command to test the configuration.

$ sudo nginx -t

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

Start Nginx Service

Run the below command to start the Nginx service. If your configuration is not valid then the service won’t start.

$ sudo systemctl start nginx //systemd
OR 
$ sudo service nginx start   //sysvinit

Enable Nginx Service

The above command will only start the service but to enable at boot time, you will need to runt the below command,

$ sudo systemctl enable nginx //systemd
OR 
$ sudo service nginx enable   //sysvinit]

Restart Nginx Service

Run the below command to stop and restart the Nginx server.

$ sudo systemctl restart nginx //systemd 
OR 
$ sudo service nginx restart   //sysv init

View Nginx Service Status

This command shows the status of Nginx server.

$ sudo systemctl status nginx //systemd 
OR 
$ sudo service nginx status   //sysvinit

Example:

Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service. 
[[email protected] ~]# systemctl status nginx 
● nginx.service - The nginx HTTP and reverse proxy server    
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)    Active: active (running) since Tue 2019-03-05 05:27:15 EST; 2min 59s ago  
Main PID: 31515 (nginx)    
CGroup: /system.slice/nginx.service            
├─31515 nginx: master process /usr/sbin/nginx            
└─31516 nginx: worker process

Reload Nginx Service

Use the below command to reload the Nginx server configuration.

$ sudo systemctl reload nginx  //systemd 
OR 
$ sudo service nginx reload    //sysvinit

Stop Nginx Service

Run the below command to stop your Nginx server.

$ sudo systemctl stop nginx  //systemd 
OR 
$ sudo service stop reload    //sysvinit

Show Nginx Command Help

Use the help command, In case if you’re not sure about any Nginx server command.

$ sudo  systemctl -h nginx //systemd 
OR 
$ sudo service -h nginx   //sysvinit

Summary

We hope this tutorial helped you to learn the popular Nginx commands. There are few other commands do exit but those are not very much used.

If you have any suggestions or questions to ask, please do let us know in the comment section.

If you liked this tutorial, please do share with your friends and follow us on on FacebookTwitter and LinkedIn. Visit our Sysadmin Hub for more tutorials and updates

In this tutorial, we will demonstrate top 10 NGINX commands that every system admin must know with examples.

Nginx is a free, open-source and the most popular web server that routes network traffic. It often used as reverse proxy server and can also used to configure the regular web server.

Top 10 NGINX Commands

Install Nginx Server

To install Nginx, run the below default distribution package manager as shown,

$ sudo yum install epel-release && yum install nginx   [On CentOS/RHEL] 
$ sudo dnf install nginx                               [On Debian/Ubuntu] 
$ sudo apt install nginx                               [On Fedora]

Check Nginx Version

To verify the version of Nginx on your Linux system, run the below command,

nginx -v

nginx version: nginx/1.17.0

The above command simply displays the version of Nginx. If you want to know the version and configure options then use the -V flag as shown.

nginx -V

Check Nginx Configuration Syntax

Before you start the server, make sure to verify whether the configuration syntax is correct or not.

This is useful when you made changes or added new configuration to the existing configuration.

Run the below command to test the configuration.

$ sudo nginx -t

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

Start Nginx Service

Run the below command to start the Nginx service. If your configuration is not valid then the service won’t start.

$ sudo systemctl start nginx //systemd
OR 
$ sudo service nginx start   //sysvinit

Enable Nginx Service

The above command will only start the service but to enable at boot time, you will need to runt the below command,

$ sudo systemctl enable nginx //systemd
OR 
$ sudo service nginx enable   //sysvinit]

Restart Nginx Service

Run the below command to stop and restart the Nginx server.

$ sudo systemctl restart nginx //systemd 
OR 
$ sudo service nginx restart   //sysv init

View Nginx Service Status

This command shows the status of Nginx server.

$ sudo systemctl status nginx //systemd 
OR 
$ sudo service nginx status   //sysvinit

Example:

Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service. 
[[email protected] ~]# systemctl status nginx 
● nginx.service - The nginx HTTP and reverse proxy server    
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)    Active: active (running) since Tue 2019-03-05 05:27:15 EST; 2min 59s ago  
Main PID: 31515 (nginx)    
CGroup: /system.slice/nginx.service            
├─31515 nginx: master process /usr/sbin/nginx            
└─31516 nginx: worker process

Reload Nginx Service

Use the below command to reload the Nginx server configuration.

$ sudo systemctl reload nginx  //systemd 
OR 
$ sudo service nginx reload    //sysvinit

Stop Nginx Service

Run the below command to stop your Nginx server.

$ sudo systemctl stop nginx  //systemd 
OR 
$ sudo service stop reload    //sysvinit

Show Nginx Command Help

Use the help command, In case if you’re not sure about any Nginx server command.

$ sudo  systemctl -h nginx //systemd 
OR 
$ sudo service -h nginx   //sysvinit

Summary

We hope this tutorial helped you to learn the popular Nginx commands. There are few other commands do exit but those are not very much used.

If you have any suggestions or questions to ask, please do let us know in the comment section.

If you liked this tutorial, please do share with your friends and follow us on on FacebookTwitter and LinkedIn. Visit our Sysadmin Hub for more tutorials and updates

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Related Articles

How to Create Multiple Folders at Once in Windows 10

Creating folders and subfolders manually is time consuming tasks...

How to Integrate Solace with MuleSoft using JMS API

In this tutorial, we will demonstrate step by step...

How to Open Port on AWS EC2 Instance

In this tutorial, we will demonstrate step by step...

LEAVE A REPLY

Please enter your comment!
Please enter your name here