# nginx site config for bigscreen10.maxbrandenbarg.nl
# Drop into /etc/nginx/sites-available/bigscreen10 and symlink into sites-enabled.
# certbot --nginx will rewrite this with the SSL certificate paths automatically.

server {
    listen 80;
    listen [::]:80;
    server_name bigscreen10.maxbrandenbarg.nl;

    # certbot uses this to verify the domain; serve plain http
    location /.well-known/acme-challenge/ {
        root /var/www/bigscreen10;
    }

    # Everything else: redirect to https (certbot adds this once SSL is in)
    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name bigscreen10.maxbrandenbarg.nl;

    # ssl_certificate / ssl_certificate_key — written by certbot

    root /var/www/bigscreen10;
    index index.html;

    # Basic auth gate while in preview
    auth_basic            "Bigscreen 10 Years (preview)";
    auth_basic_user_file  /etc/nginx/.htpasswd-bigscreen10;

    # Long cache on heavy assets (images / video / fonts)
    location ~* \.(jpg|jpeg|png|gif|webp|svg|mp4|webm|woff2?|ttf|otf|ico)$ {
        expires 30d;
        access_log off;
        add_header Cache-Control "public, immutable";
    }

    # HTML / CSS / JS — short cache so updates land fast
    location ~* \.(html|css|js|json)$ {
        expires 5m;
        add_header Cache-Control "public, must-revalidate";
    }

    location / {
        try_files $uri $uri/ =404;
    }

    # Compression
    gzip on;
    gzip_vary on;
    gzip_min_length 1024;
    gzip_types text/plain text/css text/xml application/javascript application/json image/svg+xml;

    # Hide nginx version
    server_tokens off;
}
