server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;

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

    # Gzip
    gzip on;
    gzip_types text/plain text/css application/javascript application/json image/svg+xml;
    gzip_min_length 256;

    # Long cache for static assets
    location ~* \.(?:png|jpg|jpeg|gif|ico|webp|svg|woff2?|ttf|eot|otf)$ {
        expires 30d;
        add_header Cache-Control "public, immutable";
        try_files $uri =404;
    }

    location ~* \.(?:js|css)$ {
        expires 7d;
        add_header Cache-Control "public";
        try_files $uri =404;
    }

    # Don't cache HTML / app shell
    location = / {
        add_header Cache-Control "no-store" always;
        try_files /index.html =404;
    }
    location = /index.html {
        add_header Cache-Control "no-store" always;
    }

    # SPA fallback: any unknown path -> index.html
    location / {
        try_files $uri $uri/ /index.html;
    }

    # Security headers
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "strict-origin-when-cross-origin" always;

    # Healthcheck
    location = /health {
        access_log off;
        return 200 "ok\n";
        add_header Content-Type text/plain;
    }
}
