Warm tip: This article is reproduced from serverfault.com, please click

nginx-prometheus-exporter container cannot connect to nginx

发布于 2020-11-22 09:22:44

I have a docker-compose and both nginx and nginx-prometheus-exporter are containers. I put the relevant parts here:

  nginx:
    container_name: nginx
    image: nginx:1.19.3
    restart: always
    ports:
      - 80:80
      - 443:443
      - "127.0.0.1:8080:8080"

  nginx-exporter:
    image: nginx/nginx-prometheus-exporter:0.8.0
    command:
      -nginx.scrape-uri
      -http://127.0.0.1:8080/stub_status

I tried http://nginx:8080/stub_status, nginx:8080/stub_status and 127.0.0.1:8080/stub_status for -nginx.scrape-uri but none of them worked and I got Could not create Nginx Client: failed to get http://127.0.0.1:8080/stub_status: Get "http://127.0.0.1:8080/stub_status": dial tcp 127.0.0.1:8080: connect: connection refused.

Also the localhost:8080/stub_status is available in my VM using curl.

Questioner
no746
Viewed
0
no746 2020-11-30 16:15:30

the problem was the missing -.

 nginx:
    container_name: nginx
    image: nginx:1.19.3
    restart: always
    ports:
      - 80:80
      - 443:443
      - "127.0.0.1:8080:8080"

  nginx-exporter:
    image: nginx/nginx-prometheus-exporter:0.8.0
    command:
      - -nginx.scrape-uri
      - http://127.0.0.1:8080/stub_status