I try to connect follow the request from nginx to port 9100 (Node exporter) on linux host.
this is my docker-compose.yml version: '3.3'
services:
nginx:
image: nginx:1.21.4-perl
ports:
- 80:80
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
extra_hosts:
- 'host.docker.internal:10.187.1.52'
This is my nginx.conf
worker_processes auto;
http {
listen 80;
server_name localhost;
resolver 127.0.0.11 ipv6=off;
location ~ ^/node(/?.*) {
proxy_pass http://host.docker.internal:9100$1;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_read_timeout 300s;
}
}
This is my docker version
docker version
Client: Docker Engine - Community
Version: 20.10.10
API version: 1.41
Go version: go1.16.9
Git commit: b485636
Built: Mon Oct 25 07:44:50 2021
OS/Arch: linux/amd64
Context: default
Experimental: true
I do reverse proxy for Node Exporter on port 9100. It's run on linux host machine. It works well when I put ip-address ("10.187.1.52") in nginx.cnf directly. However, It will failed when I try to use hostname as "host.docker.internal". I also try to define it on "extra_hosts" section in docker-compose.yml but the result still be failed. I got the same error '[error] 24#24: *1 no resolver defined to resolve host.docker.internal, client: 10.186.110.106, server: localhost, request: "GET /node/metrics HTTP/1.1"'
Could you please give me any suggestions to fix this?
Note!! I'm creating an example for monitoring with load testing on GitHub. This is the snap code from my project so you could see the full source code on this link.
http://appcadvisor:8080
instead?docker-compose up --force-recreate
to apply the changes.