gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript
           application/xml+rss application/atom+xml image/svg+xml;

server {
    listen 80;
    listen [::]:80;
    server_name biztaghavi.com www.biztaghavi.com;

    # Certbot will insert HTTPS redirect and SSL block here automatically.
    # After first HTTP deploy, run:
    #   certbot --nginx -d biztaghavi.com -d www.biztaghavi.com

    client_max_body_size 50M;

    # Next.js static assets — long-lived cache
    location /_next/static/ {
        proxy_pass http://127.0.0.1:3009;
        proxy_set_header Host $host;
        add_header Cache-Control "public, max-age=31536000, immutable";
        access_log off;
    }

    # Uploaded media
    location /uploads/ {
        proxy_pass http://127.0.0.1:3009;
        proxy_set_header Host $host;
        add_header Cache-Control "public, max-age=86400";
        access_log off;
    }

    # Next.js HMR / WebSocket (needed for dev; harmless in prod)
    location /_next/webpack-hmr {
        proxy_pass http://127.0.0.1:3009;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
    }

    location / {
        proxy_pass http://127.0.0.1:3009;
        proxy_http_version 1.1;

        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;

        # WebSocket support
        proxy_set_header Upgrade    $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_read_timeout  60s;
        proxy_send_timeout  60s;
        proxy_connect_timeout 10s;

        proxy_buffering    off;
        proxy_cache_bypass $http_upgrade;
    }
}
