【问题标题】:nginx-prometheus-exporter container cannot connect to nginxnginx-prometheus-exporter 容器无法连接到 nginx
【发布时间】:2020-11-22 09:22:44
【问题描述】:

我有一个 docker-compose,nginx 和 nginx-prometheus-exporter 都是容器。我把相关部分放在这里:

  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

我试过http://nginx:8080/stub_statusnginx:8080/stub_status127.0.0.1:8080/stub_status for -nginx.scrape-uri 但它们都不起作用,我得到了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

localhost:8080/stub_status 也可以在我的 VM 中使用 curl。

【问题讨论】:

    标签: nginx docker-compose docker-networking


    【解决方案1】:

    问题是缺少-

     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
    

    【讨论】:

      【解决方案2】:

      就我而言,我在 docker 中运行 nginx-prometheus-exporter。不要使用http://127.0.0.1:8080/stub_status,而是通过运行以下命令来查找主机的IP(运行docker的地方):

      ip addr show docker0
      

      并在 docker run 命令中传递 URL,如下所示:

      -nginx.scrape-uri=http://<host_machine_IP>:8080/stub_status
      

      注意:将上述命令中的portserver url“/stub_status”更改为您在nginx中配置的那样

      【讨论】:

        猜你喜欢
        • 2019-10-01
        • 1970-01-01
        • 2021-08-26
        • 1970-01-01
        • 1970-01-01
        • 2022-01-25
        • 1970-01-01
        • 2021-12-16
        • 2018-02-25
        相关资源
        最近更新 更多