# Nginx config for DevEx FM Platform
# Install: sudo cp nginx.conf /etc/nginx/sites-available/devex-fm
#          sudo ln -s /etc/nginx/sites-available/devex-fm /etc/nginx/sites-enabled/
#          sudo nginx -t && sudo systemctl reload nginx

server {
    listen 80;
    server_name your-domain.com;

    # Redirect HTTP → HTTPS
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name your-domain.com;

    # SSL — replace with your certificate paths (e.g. from Let's Encrypt)
    ssl_certificate     /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;

    # Serve static files directly (much faster than going through Gunicorn)
    location /static/ {
        alias /var/www/devex-fm/static/;
        expires 7d;
        add_header Cache-Control "public, immutable";
    }

    # Serve uploaded photos directly
    location /photos/ {
        alias /var/www/devex-fm/photos/;
        expires 1d;
    }

    # Everything else → Gunicorn
    location / {
        proxy_pass         http://127.0.0.1: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;

        # Twilio webhooks and Gemini calls can be slow — match gunicorn timeout
        proxy_read_timeout 65;
        proxy_connect_timeout 10;

        # Max upload size for photo evidence
        client_max_body_size 20M;
    }
}
