9 Popular Nginx Commands You Should Know
Last updated
Last updated
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.
Starting Nginx is very simple. Just use the following command:
If you’re using a systemd based version such as Ubuntu Linux 16.04LTS and above, use systemctl
within the command, like so:
Example response:
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:
Example response:
This command can still, however, take some time on busy servers. Therefore, if you want Nginx to stop even faster, you can also use:
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:
Restarting Nginx basically performs a stop then a start. Use one of the following commands to run a Nginx restart:
Example response:
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:
Example response:
Check what the current status of your Nginx web server is with one of the following commands:
Example response:
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:
Or use one of the following:
Example response:
There are also two different ways to check your Nginx version. Both are fairly similar but one shows a little more information than the other. Use one of the following Nginx commands to print the Nginx version:
Use the following command to print the Nginx version, compiler version and configure parameters.
If you’d like a quick reference guide of the commands available directly from within the terminal, use one of the following help commands:
Or:
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.