After installing NGINX on Ubuntu Linux, either as a web server or reverse proxy server, you’ll need to learn the basics of administrating the service. In this tutorial, we’ll show how to check the status of NGINX on Ubuntu. This will give you information about the state of the NGINX service, to help you determine if it’s running, accepting connections successfully, etc. We’ll also explain the various states of NGINX, so you know what to do with the information that’s presented.
In this tutorial you will learn:
- How to check the status of NGINX with systemd
- How to configure and access the NGINX status page
- How to check NGINX configuration, restart, and reload the service
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Ubuntu Linux |
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 |
Checking NGINX status with systemd
We can see whether or not NGINX is currently running by using the following systemctl
command.
$ systemctl status nginx
There are a few possible results you might see when running this command. If the service is running without problems, it will say “active (running)”, as seen in the screenshot below.
NGINX is active and running
If NGINX is not running, and was last shut down gracefully, you’ll see the status as “inactive (dead)”.
NGINX is currently inactive
If NGINX crashed, or didn’t shut down gracefully, the status may say “failed” along with the reason it failed. In the screenshot below, the service crashed as a result of running the kill command, which systemd indicates to us.
NGINX status is failed, due to a received signal
In the case of a misconfigured NGINX file, the status of NGINX may indicate that it was never able to start in the first place.
NGINX indicates that it was not able to start due to a misconfigured config file
Checking NGINX status with status page
Setting up the NGINX status page can give you bunch of information about active connections and other server statistics.
Edit your NGINX site configuration file and add the following block of code within the server
directive.
location /nginx_status { stub_status on; allow 127.0.0.1; deny all; }
Setting up the NGINX status page
This will allow localhost (127.0.0.1) to access the page example.com/nginx_status
to see the NGINX status page.
The output looks like this, but will have different numbers depending on the number of connections your server has.
Active connections: 16 server accepts handled requests 417 417 610 Reading: 0 Writing: 3 Waiting: 5
Here’s a breakdown of how to interpret the data:
- Active connections: Total number of open and active connections to NGINX
- The three numbers on line three:
- Number of accepted connections
- Number of handled connections (usually the same as accepted connections)
- Total number of client requests
- Reading: Number of current connections in which NGINX is reading the request header
- Writing: Number of current connections in which NGINX is writing a response to the client
- Waiting:: Number of open connections that are idle and waiting for a requests
Accessing the NGINX status pageWARNING
It is generally not a good idea to let your NGINX status page be publicly accessible. Either get rid of the page after you are done using it, or put it behind password protection so everyone on the internet can’t see the current status of your web server.
Check NGINX configuration, restart and reload NGINX
Now that you know how to check the status of NGINX, knowing how to check your configuration for errors also goes hand in hand, along with restarting and reloading NGINX.
Use the following command to check your NGINX configuration files.
$ sudo nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
And check out our guide on how to restart or reload NGINX for further explanation about the differences between the commands. The summary is that “reload” will just refresh the configuration files, whereas “restart” will completely close Nginx and start it again.
$ sudo systemctl restart nginx AND $ sudo systemctl reload nginx
Closing Thoughts
In this guide, we saw how to check the status of NGINX on Ubuntu Linux. This included checking the service using systemctl
, as well as setting up and checking the NGINX status page. We also learned how to check our NGINX configuration for errors, and restart or reload the service. All of this information is essential for web admins, and should help you to keep tabs on the state of your website or reverse proxy server.