loading...

Checking status for Nginx

anselmopfeifer profile image Anselmo Pfeifer ・1 min read

In this post, I will explain how we can get status for Nginx configuration, sometimes is not easy to filter the HTTP code by curl command when the backend is not working, besides that intention here is get the status of the proxy configuration.

  • First of all, check if the status module is already enabled the command for it is:
    nginx -V 2>&1 | grep -o with-http_stub_status_module, most Linux distributions comes with the ngx_http_stub_status_module enabled.

  • After that, we need to enable stub_status module in the Nginx configuration file, we can create a new file named nginx-status.conf or add the content below in an existing proxy configuration file.

location /nginx-status {
    stub_status;
    allow 127.0.0.1;    #only allow requests from localhost
    deny all;       #deny all other hosts   
 }
  • Before restart Nginx, we can test if the configuration above didn't break something, to test it, run the command nginx -t, if the result is great, let's go to reload the service to apply the configuration nginx -s reload.

  • To test the status result go to the http://127.0.0.1/nginx-status, the result must be like this example:

Active connections: 1 
server accepts handled requests
 15 15 27 
Reading: 0 Writing: 1 Waiting: 0 

PS: Did something not work? don't put blame on me, and take a look this link: More information about Nginx here :)

Discussion

pic
Editor guide