14.06.2023

Monitoring Nginx with Zabbix

Nginx is a widely presented web server that is often employed to serve static content, reverse proxy, or load balance web traffic. It is well-known for its reliability, flexibility, and high performance. As with any server, it is important to monitor Nginx to ensure it is functioning appropriately and to address any issues that may arise. In this article, we will explore how to monitor Nginx with Zabbix, to proactively detect and resolve any problems with your Nginx server.

Preparations

Before we start exploring the process of monitoring Nginx with Zabbix, we need to ensure that we meet the prerequisites. These include:

Configuring Nginx

Open the /etc/nginx/conf.d/stub_status.conf file with the editor of your choice and paste the following text block:

server {
listen 127.0.0.1:80;
server_name 127.0.0.1;
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
location = /basic_status {
stub_status;
allow 127.0.0.1;
allow ::1;
deny all;
}
}


It makes the server generate basic status information on /basic_status page available only from this same server, so our agent can get it to the server.

Now lets check if Nginx procces is fine with new settings by running:

nginx -t

systemctl restart nginx

systemctl status nginx

Next lets's see if the new status page works with curl:

curl http://127.0.0.1/basic_status

Configuring logs

You should check if Nginx generates the logs needed by Zabbix by checking logging settings in /etc/nginx/nginx.conf

Now for Zabbix to work with logs let's comment the original access_log line and paste this fragment:

It should be looking like this:

Check and restart Nginx another time, and let’s get to configuring our Zabbix.

Configuring Zabbix

Assuming that all previous instructions have been completed, you now only need to create a host for this server and add Nginx by Zabbix agent template to it, or add it to an already existing one.

Assign the template to the host running Nginx by going to Configuration → Hosts → Select the host → Templates → Add.


If everything is right you must be able to work with the data which is provided by the template:

The Zabbix template also includes a number of triggers alerting you when there is a problem with your Nginx server. These triggers notify you of problems such as high CPU usage, high memory usage, high error rate, and downtime.

For example:

And some items if you want to check something not covered in default graphs or triggers.

Conclusion

You have explored how to get Nginx ready for monitoring with Zabbix and add a suitable template to Zabbix which allows you to proactively monitor your server and quickly resolve any issues that may arise.