Skip to content

Instantly share code, notes, and snippets.

@sagacity
Created November 9, 2022 15:54
Show Gist options
  • Save sagacity/f6ce77679fecf90bef56b2cc47082367 to your computer and use it in GitHub Desktop.
Save sagacity/f6ce77679fecf90bef56b2cc47082367 to your computer and use it in GitHub Desktop.
Prometheus behind Nginx with CORS enabled
version: '2'
services:
prometheus:
container_name: prometheus
image: bitnami/prometheus:latest
volumes:
- ./prometheus.yml:/opt/bitnami/prometheus/conf/prometheus.yml
ports:
- "9090:9090"
environment:
FOO: 'bar'
nginx:
image: nginx:latest
container_name: nginx
volumes:
- ./reverse_proxy.conf:/etc/nginx/conf.d/default.conf
ports:
- "9091:9091"
links:
- prometheus
# Just the demo prometheus config file that scrapes itself
global:
scrape_interval: 15s # By default, scrape targets every 15 seconds.
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'codelab-monitor'
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# Override the global default and scrape targets from this job every 5 seconds.
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
server {
listen 9091;
server_name nginx;
add_header 'Access-Control-Allow-Origin' 'http://localhost:1234';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Headers' 'Authorization,Accept,Origin,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Range,Range';
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS,PUT,DELETE,PATCH';
location / {
proxy_hide_header 'Access-Control-Allow-Origin';
proxy_pass http://prometheus:9090/;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment