# Author: Martin Ptacek

# nginx configuration for pushprox, grafana and prometheus UI
http{

    # Needed for grafana websockets
    map $http_upgrade $connection_upgrade {
        default upgrade;
        '' close;
    }

    # Upstream server definitions
    upstream prometheus{
        server prometheus:9090;
    }

    upstream pushprox{
        server pushprox:8080;
    }

    upstream grafana{
        server grafana:3000;
    }

    # Grafana server configuration
    server {
        listen 3000;

        root /usr/share/nginx/html;
        index index.html index.htm;

        location / {
            proxy_set_header Host $http_host;
            proxy_pass http://grafana;
        }

        # Proxy Grafana Live WebSocket connections
        location /api/live/ {
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
            proxy_set_header Host $http_host;
            proxy_pass http://grafana;
        }
    }

    # PushProx server configuration
    server {
        listen 8080;

        proxy_read_timeout 3600;
        proxy_connect_timeout 3600;
        proxy_send_timeout 3600; 

        location / {
            proxy_pass http://pushprox;
        }

    }

    # Prometheus UI server configuration
    server {
        listen 9090;

        location / {
            proxy_pass http://prometheus;
        }
    }
}

events {
  worker_connections  1024;
}
