# Config HTTPS définitive avec SSL Let's Encrypt
# Copiée vers nginx.conf par setup-vps.sh après obtention du certificat.

server {
    listen 80;
    server_name openfin.open-squared.tech;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        return 301 https://$host$request_uri;
    }
}

server {
    listen 443 ssl;
    http2 on;
    server_name openfin.open-squared.tech;

    ssl_certificate     /etc/letsencrypt/live/openfin.open-squared.tech/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/openfin.open-squared.tech/privkey.pem;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;

    # Sécurité headers
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
    add_header X-Frame-Options SAMEORIGIN always;
    add_header X-Content-Type-Options nosniff always;

    # API FastAPI
    location /api/ {
        proxy_pass http://backend:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_read_timeout 120s;
        proxy_buffering off;
    }

    # Swagger docs FastAPI
    location /docs {
        proxy_pass http://backend:8000;
        proxy_set_header Host $host;
    }
    location /openapi.json {
        proxy_pass http://backend:8000;
        proxy_set_header Host $host;
    }

    # Frontend React SPA
    location / {
        proxy_pass http://frontend:80;
        proxy_set_header Host $host;
        proxy_read_timeout 30s;
    }
}
