Skip to content

Self-hosted monitoring for homelabs: host and container metrics and uptime checks from all your machines in one dashboard, with an optional AI agent that diagnoses incidents and suggests fixes.

2.7 KB
Raw Blame
# Public listener for installs that expose the dashboard through a reverse proxy (e.g. Traefik)
# while collectors report over a VPN. Mount over /etc/nginx/conf.d/default.conf in the frontend
# container (docker-compose.server.yml does this) and set COLLECTOR_ACCESS=strict on the backend.
#
# Every collector endpoint is refused here. Collectors use the separate collector-gate container
# (docker/nginx.collector.conf), which is not attached to the reverse proxy's network.

server {
    # 8080, not 80: nginx runs as an unprivileged user, which can't open ports below 1024 without a capability.
    listen 8080;
    server_name _;

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

    # Security headers. The CSP matches what the built app loads: its own scripts and styles, no
    # external resources; style attributes (React inline styles) need 'unsafe-inline' for styles only.
    server_tokens off;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-Frame-Options "DENY" always;
    add_header Referrer-Policy "no-referrer" always;
    add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=(), usb=()" always;
    add_header Cross-Origin-Opener-Policy "same-origin" always;
    add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self' data:; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;
    # Served over HTTPS by the reverse proxy; browsers ignore this on plain HTTP. No includeSubDomains,
    # since other apps on your domain may not be HTTPS-only.
    add_header Strict-Transport-Security "max-age=15552000" always;

    # Whose X-Forwarded-For is believed comes from TRUSTED_PROXIES, the address or network of your reverse
    # proxy (docker/trusted-proxies.sh writes the file included here at start). By default nobody's:
    # $remote_addr is the address that connected.
    include /etc/nginx/trusted-proxies/*.conf;

    location ~ ^/api/(collector\.py$|monitoring/(collectors|metrics/)) {
        return 404;
    }

    location /api/ {
        proxy_pass http://backend:8000/;
        proxy_http_version 1.1;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header X-Forwarded-Host $host;
        # The backend answers collector endpoints only when this says vpn or internal, so a client
        # must never be able to set it on the public listener.
        proxy_set_header X-Collector-Via "";
        proxy_read_timeout 120s;
        client_max_body_size 5m;
    }

    location / {
        try_files $uri $uri/ /index.html;
    }
}