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.

1.8 KB
Raw Blame
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;

    # Whose X-Forwarded-For is believed comes from TRUSTED_PROXIES (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;

    # Dashboard and API share one origin: no CORS, and collectors and browsers
    # use the same address (http(s)://<host>/api).
    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-Collector-Via "";
        proxy_set_header X-Forwarded-Host $host;
        proxy_read_timeout 120s;
        client_max_body_size 5m;
    }

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