upstream django {
    server web:8000;
}

# ── HTTP → HTTPS redirect ──────────────────────────────────
server {
    listen 80;
    server_name dev.jool-international.com;

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

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

# ── HTTPS ──────────────────────────────────────────────────
server {
    listen 443 ssl;
    http2  on;
    server_name dev.jool-international.com;

    ssl_certificate     /etc/letsencrypt/live/dev.jool-international.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/dev.jool-international.com/privkey.pem;
    include             /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam         /etc/letsencrypt/ssl-dhparams.pem;

    server_tokens off;
    client_max_body_size 10M;

    add_header X-Robots-Tag "noindex, nofollow" always;

    location /static/ {
        alias /app/staticfiles/;
        expires 1d;
        add_header Cache-Control "public";
        access_log off;
    }

    location /media/careers/cvs/ {
        deny all;
        return 404;
    }

    location /media/ {
        alias /app/media/;
        expires 1d;
        add_header Cache-Control "public";
        access_log off;
    }

    location / {
        proxy_pass         http://django;
        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_redirect     off;
        proxy_read_timeout 60s;
    }
}
