If We Do Not Create Ngnix Status Graph in PHP5-FPM Setup After Enabling Nginx Status Page, The Fun Remains Incomplete. Easiest Way is Described Here. One of the most search topic around Nginx is how to create Ngnix status graph, it is quite odd – most writes the on how to enable /ping status page or enable /status page; but they do not extend the guides to the next step.
Ngnix Status Graph in PHP5-FPM Setup : Work With Easy Setup
So, in our guide to enable /status page for Nginx PHP5-FPM setup, we did some works needed for this guide. There are hundreds of monitoring tools including paid stuffs to create Nginx status graph but none of them neither are easy to setup nor light for the server. There is actually very easy way to create graph.
Ngnix Status Graph in PHP5-FPM Setup : With Modified PHP Script
From the previous guide, this was our vhost file’s main content related to /status
:
---
1 2 3 4 5 6 7 8 9 10 11 | location /status { access_log off; allow 127.0.0.1; # allow sub.net.ip; deny all; fastcgi_split_path_info ^(.+.php)(.*)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; i nclude fastcgi_params; } |
What we have not added was – stub_status on;
. Here is what it does :
1 | http://nginx.org/en/docs/http/ngx_http_stub_status_module.html |
Instead of writing so much, we can create alternative / additional location in this way :
1 2 3 4 | location /nginx_status { stub_status on; access_log off; } |
For apt version of Nginx (if you have installed Ninx with apt-get install nginx
command), that required stuff is actually present :
1 2 3 4 5 6 | nginx -V # output nginx version: nginx/1.4.6 (Ubuntu) built by gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1) TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module |
If that --with-http_stub_status_module
was not present, the thing would not work. So a bit modification :
1 2 3 4 5 6 7 8 9 10 11 12 | location /status { access_log off; stub_status on; #allow 127.0.0.1; #allow sub.net.ip; #deny all; fastcgi_split_path_info ^(.+.php)(.*)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } |
We have commented out :
1 2 3 | #allow 127.0.0.1; #allow sub.net.ip; #deny all; |
and added :
1 | stub_status on; |
Saving it, running nginx -t
will tell that everything is fine and we can actually do restart :
1 2 | service php5-fpm restart service nginx restart |
If we point our browser towards https://thecustomizewindows.com/status
, we will get a basic informative webpage :
But, this way if the page is kept open, people will hack us! You can read the nginx documentation about restricting access with username and password :
1 | http://nginx.com/resources/admin-guide/restricting-access/ |
We saw that, this person :
1 | http://baris.shadowytree.com/?node=blog/nginx%20status |
did lot of work but we needed to modify it as our location
is different. We can use a better way to password protect the PHP files :
1 | http://php.net/manual/en/features.http-auth.php |
So, first I modified that main file uptime.php
[you must change the domain name at line 72], you can grab the file here on Github Gist.
1 2 3 4 5 | cd /usr/share/nginx/html nano uptime.php ## copy pasted the material and saved it ## permission sudo chown root:www-data /usr/share/nginx/html/uptime.php |
Now, when we pointed towards this url :
1 | https://thecustomizewindows.com/uptime.php |
we received a webpage with stuffs in JSON format. This followed by uploading the files from that blog URL. It did the work we needed.
Nginx community version does not have the ngx_http_status_module
. Definitely there are many standalone tools, but this is the easiest way of getting a graph from status.