# ── HTTP → HTTPS Redirect ───────────────────────────────────────────────────
server {
    listen 80;
    server_name _;
    return 301 https://$host$request_uri;
}

# ── Landing Page (Next.js) ──────────────────────────────────────────────────
server {
    listen 443 ssl;
    server_name greenlns.ai;

    ssl_certificate     /etc/nginx/certs/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/privkey.pem;

    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;

    location / {
        proxy_pass         http://app:3000;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection 'upgrade';
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

# ── MinIO API (public image URLs) ──────────────────────────────────────────
server {
    listen 9000 ssl;
    server_name greenlns.ai;

    ssl_certificate     /etc/nginx/certs/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/privkey.pem;

    # Allow large image uploads
    client_max_body_size 20m;

    location / {
        proxy_pass         http://minio:9000;
        proxy_set_header   Host $host;
        proxy_set_header   X-Real-IP $remote_addr;
    }
}

# ── MinIO Console (Admin UI) ────────────────────────────────────────────────
server {
    listen 9001 ssl;
    server_name greenlns.ai;

    ssl_certificate     /etc/nginx/certs/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/privkey.pem;

    location / {
        proxy_pass         http://minio:9001;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection 'upgrade';
        proxy_set_header   Host $host;
    }
}
