0% found this document useful (0 votes)
20 views6 pages

9 Popular Nginx Commands You Should Know - KeyCDN Support

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views6 pages

9 Popular Nginx Commands You Should Know - KeyCDN Support

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

9 Popular Nginx Commands You Should Know - KeyCDN Support 7/12/19, 12(38

9 Popular Nginx Commands You


Should Know
Updated on October 4, 2018

Nginx is one of the most popular web servers in the world. So whether
youʼre currently using it or not, chances are, if youʼre a web developer
chances are youʼll likely come in contact with it at some point. Therefore
there are a few important Nginx commands you should be aware of in order
to get familiar with the basics of this web server.

I this guide weʼre going to go over what these popular Nginx commands are,
how to use them, and what each one does.

Reference the following list of popular commands if you ever need a quick
reminder on how to use a certain command or what it does. Remember, if
you arenʼt a root user, youʼll need to sudo each command in order for them
to properly work.

https://www.keycdn.com/support/nginx-commands Page 1 of 6
9 Popular Nginx Commands You Should Know - KeyCDN Support 7/12/19, 12(38

Starting Nginx is very simple. Just use the following command:

service nginx start

If youʼre using a systemd based version such as Ubuntu Linux 16.04LTS and
above, use systemctl within the command, like so:

systemctl start nginx

Example response:

Starting nginx server...

Stopping Nginx will kill all system processes quickly. This will terminate
Nginx even if there are open connections. In order to do so, run one of the
following commands:

service nginx stop


systemctl stop nginx

Example response:

Stopping nginx Server...

This command can still, however, take some time on busy servers.
Therefore, if you want Nginx to stop even faster, you can also use:

killall -9 nginx

https://www.keycdn.com/support/nginx-commands Page 2 of 6
9 Popular Nginx Commands You Should Know - KeyCDN Support 7/12/19, 12(38

Quitting Nginx is very similar to stopping it however it does so gracefully


which means it will finish serving open connections before shutting down.
To quit Nginx, use one of the following commands:

service nginx quit


systemctl quit nginx

Restarting Nginx basically performs a stop then a start. Use one of the
following commands to run a Nginx restart:

service nginx restart


systemctl restart nginx

Example response:

Stopping nginx Server... [ OK ]


Starting nginx Server... [ OK ]

Reload is a bit different from restart in that, again, it is more gracefully.


According to Nginx, reload is defined as “start the new worker process with
a new configuration, gracefully shut down old worker processes.”. You can
reload Nginx by using one of the following commands:

service nginx reload


systemctl reload nginx

Example response:

Reloading nginx Server... [ OK ]

https://www.keycdn.com/support/nginx-commands Page 3 of 6
9 Popular Nginx Commands You Should Know - KeyCDN Support 7/12/19, 12(38

Check what the current status of your Nginx web server is with one of the
following commands:

service nginx status


systemctl status nginx

Example response:

nginx is running

Test Nginx Configuration#

You can test your Nginx serverʼs configuration file before restarting or
reloading it completely. This helps prevent any unforeseen errors which can
cause your website to gown down. To do this there are two separate
commands you can use, both return the same information:

nginx -t

Or use one of the following:

service nginx configtest


systemctl config nginx

Example response:

nginx: the configuration file /etc/nginx-sp/nginx.conf syntax is ok


nginx: configuration file /etc/nginx-sp/nginx.conf test is successful

There are also two different ways to check your Nginx version. Both are

https://www.keycdn.com/support/nginx-commands Page 4 of 6
9 Popular Nginx Commands You Should Know - KeyCDN Support 7/12/19, 12(38

fairly similar but one shows a little more information than the other. Use one
of the following Nginx commands to print the Nginx version:

service nginx -v
systemctl -v nginx

Use the following command to print the Nginx version, compiler version and
configure parameters.

service nginx -V
systemctl -V nginx

If youʼd like a quick reference guide of the commands available directly from
within the terminal, use one of the following help commands:

service nginx -h
systemctl -h nginx

Or:

service nginx -?
systemctl -? nginx

This Nginx commands shown in this article are a few of the most popular
ones. There do exist a few other parameters however these arenʼt used
nearly as much. Reference this guide whenever youʼre stuck for a Nginx
command and hopefully, youʼll find the one you need.

What Is a Virtual Host? A virtual host is an Apache term, however, is


commonly used by Nginx users as well. The proper term for Nginx is “server
block”. Both of these words have the same meaning which is basically the

https://www.keycdn.com/support/nginx-commands Page 5 of 6
9 Popular Nginx Commands You Should Know - KeyCDN Support 7/12/19, 12(38

feature of being…

https://www.keycdn.com/support/nginx-commands Page 6 of 6

You might also like