Both Nginx and Prometheus are deployed on Docker, with below nginx config file, the prometheus location is not accessible with error “404 page not found”
The Prometheus container is acesible from nginx container with curl and ping
server {
# https://ypereirareis.github.io/blog/2020/02/18/how-to-reduce-nginx-502-bad-gateway-errors-risks-with-dynamic-domain-name-resolution/
resolver 127.0.0.11 valid=30s;
set $upstream_endpoint django:8066;
set $prometheus_endpoint prometheus:9090;
error_page 502 /static/502.html;
listen 80;
listen 443 ssl;
ssl_certificate ******;
ssl_certificate_key ******;
charset utf-8;
client_max_body_size 0;
client_body_buffer_size 128k;
server_tokens off;
sendfile off;
gzip on;
gzip_disable "msie6";
gzip_types application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font application/x-font-opentype application/x-font-otf application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xm>
location /static {
alias /static;
autoindex off;
expires 30d;
}
location / {
proxy_pass http://$upstream_endpoint;
client_max_body_size 0;
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 1200;
proxy_send_timeout 1200;
proxy_read_timeout 1200;
send_timeout 1200;
aio threads;
}
location /prometheus {
proxy_pass http://$prometheus_endpoint;
client_max_body_size 0;
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 1200;
proxy_send_timeout 1200;
proxy_read_timeout 1200;
send_timeout 1200;
aio threads;
}
# HTTP to HTTPS redirect
if ($scheme = http) {
return 301 https://$host$request_uri;
}
}
The compose file:
services:
prometheus:
build: docker/prometheus
command:
- "--log.format=json"
- "--config.file=/etc/prometheus/prometheus.yml"
- "--storage.tsdb.path=/prometheus"
- "--web.console.libraries=/usr/share/prometheus/console_libraries"
- "--web.console.templates=/usr/share/prometheus/consoles"
restart: "always"
volumes:
- prometheus_data:/prometheus
networks:
- proxy-tier
nginx:
build:
context: docker/nginx
restart: "always"
depends_on:
- django
volumes:
- cache_media:/var/media:ro
- static_files:/static:ro
- "./docker/nginx/certs:/etc/nginx/ssl:ro"
ports:
- "80:80"
- "443:443"
- "9090:9090" # Prometheus dashboard
- "3000:3000" # Grafana interface
networks:
- proxy-tier
environment:
- DOMAINNAME_CLOUD_SERVER
volumes:
cache_media:
static_files:
prometheus_data:
networks:
proxy-tier:
driver: bridge
secrets:
The similar location ( the location above prometheus in nginx config file / ) is working, the application on the django is deployed on docker as well