nginx-prometheus-exporter 容器无法连接到 nginx

nginx-prometheus-exporter container cannot connect to nginx

我有一个 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_status, nginx:8080/stub_status127.0.0.1:8080/stub_status 用于 -nginx.scrape-uri,但其中 none 有效,我得到了 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:
    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

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

ip addr show docker0

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

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

注意:更改端口服务器url"/stub_status" 在上面的命令中,你已经在 nginx

中配置了