Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Configure Nginx Monitoring With Zabbix

This tutorial will show you how to configure your Zabbix to monitor Nginx on your Debian 12 / Ubuntu 22.04 server.

This tutorial assumes that you have already configured the Linux host in Zabbix using one of the related posts.


Create Nginx Site Configuration

First, we need to create a site configuration to tell Nginx to output the basic status metrics if a user connects from the local server on the /basic_status path. The server will not respond when requests to that path come in from the outside world/internet. This way only our Zabbix agent will be able to retrieve the metrics.

sudo editor /etc/nginx/sites-available/status

... and fill it with the following content:

server {
    listen [::1]:80;

    location = /basic_status {
        allow ::1;
        deny all;

Now create a symlink that points to it from the sites-enabled directory to "enable" the site.

cd /etc/nginx/sites-enabled/
sudo ln -s ../sites-available/status .

Reload Nginx

Reload nginx for it to take the configuration into account.

sudo nginx -s reload


Run the following command from the server in order to check that it is working:

wget -q --output-document - localhost/basic_status

You should see some output similar to below:

Active connections: 1 
server accepts handled requests
 5 5 8 
Reading: 0 Writing: 1 Waiting: 0

Configure Zabbix Server

Now that we have configured Nginx to output the metrics, we need to configure the Zabbix server to fetch them.

Right click on your host and click on Configuration.

Click Select (1) to select an additional template.

Scroll down and select Nginx by Zabbix agent.

Click Update

If you configured a different path than /basic_status, then you would need to go into Macros, click on the inherited toggle, and set the value of {$NGINX.STUB_STATUS.PATH} to the path you configured.


That's it! Zabbix should now retrieve metrics about your Nginx server. If you are using PHP, don't forget that you may also wish to configure the PHP-FPM by Zabbix agent template.


Last updated: 5th June 2024
First published: 17th July 2023