Original issue was closed but I think it was never fixed (reverted in a pull request)?
See: https://github.com/google/cadvisor/issues/667
See: https://github.com/google/cadvisor/pull/680
Original post:
Hello,
I'm trying to run cAdvisor docker image with nginx proxy. The problem is that I need to set up a proxy from different then root context - my goal is to have cAdvisor running behind e.g. http://localhost/cadvisor/ Here is my exemplary nginx config:
server {
listen 82;
server_name ${HOSTNAME};set $cadvisor cadvisor.docker;
location ~ ^/cadvisor/(.)$ {
rewrite ^/cadvisor/(.) /$1 break;
proxy_pass http://$cadvisor:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 150;
proxy_send_timeout 100;
proxy_read_timeout 100;
proxy_buffers 16 64k;
proxy_busy_buffers_size 64k;
client_max_body_size 256k;
client_body_buffer_size 128k;
}
}
The problem is that application assumes that the web context is set to "/", that's why I get redirected to http://localhost:82/containers/ after accessing http://localhost:82/cadvisor/Is it possible to define application base context path to make cadvisor running behind custom nginx location? Any help will be appreciate
I came up with the following config which seems to work ok for now:
server {
listen 443 ssl;
server_name dashboards.domain.tld;
location /cadvisor/ {
proxy_pass http://cadvisor-host:12345/;
proxy_redirect ~^/containers/ /cadvisor/containers/;
proxy_redirect ~^/docker/ /cadvisor/docker/;
}
}
cAdvisor is available at https://dashboards.domain.tld/cadvisor once the config is loaded
I tried to route cadvisor ui to /cadvisor with traefik and couldn't make it work.
@sebhoss add 1 more redirect
proxy_redirect ~^/metrics/ /cadvisor/metrics/;
What I did.
set $cadvisor http://cadvisor:8080;
location ~ ^/cadvisor(?<requesturi>.*) {
proxy_pass $cadvisor$requesturi;
proxy_redirect ~^(/.*) /cadvisor$1;
}
If anyone else is trying to get this to work through docker-compose, where nginx serves as a reverse proxy to cadvisor on the /admin/cadvisor/ path, this is the configuration that worked for me:
docker-compose entry:
cadvisor:
container_name: cadvisor
build:
context: .
dockerfile: projects/cadvisor/Dockerfile
command:
- '-port=80'
- '-url_base_prefix=/admin/cadvisor'
volumes:
- "/:/rootfs:ro"
- "/var/run:/var/run:ro"
- "/sys:/sys:ro"
- "/var/lib/docker:/var/lib/docker:ro"
- "/dev/disk:/dev/disk:ro"
expose:
- 80
The relevant: nginx configuration
location ~* /admin/cadvisor/.*$ {
proxy_pass http://cadvisor;
}
My docker-compose configuration is a bit atypical, so don't copy/paste that expecting it to work with your project as-is.
Hello,
Someone have success with traefik reverse proxy ?
The following does not work :
cadvisor:
container_name:cadvisor
image: gcr.io/google-containers/cadvisor:latest
restart: always
privileged: true
networks:
- back-network
ports:
- "8080:8080"
command:
- '-url_base_prefix=/cadvisor'
volumes:
- /:/rootfs:ro
- /var/run:/var/run:rw
- /sys:/sys:ro
- /var/lib/docker/:/var/lib/docker:ro
labels:
- "traefik.http.routers.cadvisor.rule=Host(`localhost`) && PathPrefix(`/cadvisor`)"
- "traefik.http.services.cadvisor.loadbalancer.server.port=8080"
Most helpful comment
I came up with the following config which seems to work ok for now:
cAdvisor is available at https://dashboards.domain.tld/cadvisor once the config is loaded