Skip to content

Self-hosted homelab infrastructure visualizer — interactive network diagram with live status monitoring

2.0 KB
Raw Blame
# Full-mode nginx config, served at the root. Installed as an nginx template:
# the image renders ${BACKEND_UPSTREAM} at container start (default backend:8000,
# see Dockerfile.frontend), so the API can live somewhere other than the compose
# `backend` service — e.g. host.docker.internal:8000 when the backend runs with
# network_mode: host.

server {
    listen 80;
    server_name _;
    root /usr/share/nginx/html;
    index index.html;

    # Proxy WebSocket (must be before /api/ to take priority)
    location /api/v1/status/ws/ {
        proxy_pass http://${BACKEND_UPSTREAM};
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    # Proxy API to backend
    location /api/ {
        proxy_pass http://${BACKEND_UPSTREAM};
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    # Interactive API docs — Swagger UI, ReDoc and the OpenAPI schema FastAPI
    # generates. Outside /api/, so they need their own blocks or the SPA
    # fallback below swallows them. See docs/api.md.
    location /docs {
        proxy_pass http://${BACKEND_UPSTREAM};
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location /redoc {
        proxy_pass http://${BACKEND_UPSTREAM};
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    location = /openapi.json {
        proxy_pass http://${BACKEND_UPSTREAM};
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }

    # Proxy legacy /ws/ path
    location /ws/ {
        proxy_pass http://${BACKEND_UPSTREAM};
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
    }

    # SPA fallback
    location / {
        try_files $uri $uri/ /index.html;
    }
}