Ad Widget

Collapse

Zabbix Nginx 1.14 monitoring problems - I need help to solve this

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • guslinus
    Junior Member
    • Mar 2021
    • 11

    #1

    Zabbix Nginx 1.14 monitoring problems - I need help to solve this

    I'm having problems configuring the monitoring of some nginx items in Zabbix, I tried to do as in https://www.zabbix.com/integrations/nginx
    and it doesn't work the items are like "Not supported". In the images are the configuration of the file
    myhost.com.br.conf in /etc/nginx/sites-available
    I'm using the Nginx by Zabbix agent template for the host



    Click image for larger version

Name:	zabbix_nginx_agent1.png
Views:	1932
Size:	79.8 KB
ID:	434025​​

    configuration of myshost.com.br.conf file in /etc/nginx/sites-available

    Click image for larger version

Name:	zabbix_nginx_agent02.jpg
Views:	1912
Size:	132.4 KB
ID:	434028


    ngx_http_stub_status_module module is ok

    Click image for larger version

Name:	zabbix_nginx_agent03.png
Views:	1873
Size:	9.3 KB
ID:	434027






    Attached Files
  • tim.mooney
    Senior Member
    • Dec 2012
    • 1427

    #2
    The 404 error indicates pretty clearly that it's not a Zabbix issue: the URL that you're trying to query is not present.

    If you're using "Nginx by Zabbix Agent", then it would be the Zabbix agent running on the same system as Nginx that would be trying to connect, not the Zabbix server. The zabbix server talks to the zabbix agent running on the same system as nginx, and asks the agent to connect to the URL and return the results.

    Does it work if you add an "allow 127.0.0.1;" and then restart nginx?

    Comment


    • guslinus
      guslinus commented
      Editing a comment
      Hi, thanks for the help, I talked to some people and was told that I wasn't doing good practices, I was using Zabbix 5.4 with zabbix Agent 2, so I decided to redo my containers
  • guslinus
    Junior Member
    • Mar 2021
    • 11

    #3


    I reinstalled the containers all with the same version, my new container structure looks like this:
    I still have problems with Nginx monitoring

    Click image for larger version

Name:	zabbix_docker_infra.png
Views:	1855
Size:	41.2 KB
ID:	434082


    I removed zabbix-agent2 from the target host I left only zabbix-agent

    For the target host in the Zabbix settings I'm using the Template App Nginx by HTTP: Nginx: Get stub status page and it's returning the error in the image below I tried some searches to solve but without success

    Click image for larger version

Name:	zabbix_nginx3.png
Views:	1915
Size:	38.8 KB
ID:	434080


    mysite.com.br.conf file It has https configured :


    server {
    server_name mysite.com.br www.mysite.com.br;

    root /var/www/html/mysite.com.br/placas-front/dist;
    location / {
    try_files $uri $uri/ /index.html index.nginx-debian.html ;
    }



    location = /basic_status {
    stub_status;
    allow 127.0.0.1;
    allow 167.99.114.151; # Zabbix Server
    deny all;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.mysite.com.br/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.mysite.com.br/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


    # add_header Access-Control-Allow-Origin *;
    }
    server {


    add_header Access-Control-Allow-Origin *;
    if ($host = www.mysite.com.br) {
    return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = mysite.com.br) {
    return 301 https://$host$request_uri;
    } # managed by Certbot


    server_name mysite.com.br www.mysite.com.br;
    listen 80;
    return 404; # managed by Certbot

    }

    Attached Files

    Comment

    • tim.mooney
      Senior Member
      • Dec 2012
      • 1427

      #4
      Ok, now that you've switched to using the "Template App Nginx by HTTP", the http request is going to come from your Zabbix server (or proxy, if you're using a proxy to monitor this system, but you didn't mention one so I assume not).

      If you look at the macros that you can use to configure that template, you can see:

      Macros used
      {$NGINX.DROP_RATE.MAX.WARN} The critical rate of the dropped connections for trigger expression. 1
      {$NGINX.RESPONSE_TIME.MAX.WARN} The Nginx maximum response time in seconds for trigger expression. 10
      {$NGINX.STUB_STATUS.PATH} The path of Nginx stub_status page. basic_status
      {$NGINX.STUB_STATUS.PORT} The port of Nginx stub_status host or container. 80
      {$NGINX.STUB_STATUS.SCHEME} The protocol http or https of Nginx stub_status host or container. http
      That means that by default, your Zabbix server is going to connect via http. So the URL would be http://www.mysite.com.br/basic_status

      If you log in to a shell on your Zabbix server and use either "wget" or "curl" to connect to that exact URL, does it work, or does it return a 404 status?

      If it returns a 404 status, does it work if you change the URL to use "https" instead of "http"?

      Based on how I read your Nginx config, it seems like the "location = /basic_status" is only defined for the https vhost, not the http vhost. If that's the case, you could either move that "location" stanza into the http vhost or you could override the default value of the macro {$NGINX.STUB_STATUS.SCHEME} in the settings for this host in Zabbix, so that the template uses https to connect, instead of the default of http.

      Comment

      • guslinus
        Junior Member
        • Mar 2021
        • 11

        #5
        Hi, first I would like to thank you for the help but it's been quite difficult to set up these items, what I tried to do now is setup a /etc/nginx/sites-available/nginx_status.conf

        is it better to do it in a separate .conf or configure it in the of mysite.com.br.conf ?


        server {
        listen 127.0.0.1:443;
        listen [::1]:443;
        location /basic_status {
        stub_status;
        #access_log off;
        allow 127.0.0.1;
        allow 167.99.114.151;
        deny all;
        }
        }

        After configuring this way, it was like this in zabbix

        Click image for larger version

Name:	Captura de tela 2021-11-04 095054.png
Views:	1914
Size:	132.3 KB
ID:	434198


        I changed the Macro setting to https and port 443, I really believe I'm doing it incorrectly

        Click image for larger version

Name:	Captura de tela 2021-11-04 095325.png
Views:	1870
Size:	45.4 KB
ID:	434199

        Thanks for your help
        Attached Files

        Comment


        • um3n
          um3n commented
          Editing a comment
          I think you cannot access the site from another location then 127.0.0.1 because you bound it to loopback.
          If you check via Zabbix Agent it should be able to access 127.0.0.1 but you have to curl for localhost... i think

        • guslinus
          guslinus commented
          Editing a comment
          I have been trying some settings and nothing is working to monitor nginx.
      • guslinus
        Junior Member
        • Mar 2021
        • 11

        #6
        My curl response see

        root@srv2zbx:/home/gus# curl http://mysite.com.br/basic_status
        <html>
        <head><title>301 Moved Permanently</title></head>
        <body bgcolor="white">
        <center><h1>301 Moved Permanently</h1></center>
        <hr><center>nginx/1.14.0 (Ubuntu)</center>
        </body>
        </html>

        Comment

        • um3n
          Member
          • Aug 2021
          • 47

          #7
          Could you please use -L option in curl? To follow redirects and so on...
          Could you also check for http://localhost/basic_status

          Comment

          Working...