# nginx Reverse-Proxy für pir.staging.rebreak.org → 127.0.0.1:8090 (PIR-Service)
#
# Referenz-Config. Auf dem Server liegt sie unter
#   /etc/nginx/sites-available/pir-staging.rebreak.org
# verlinkt nach sites-enabled/. Die `listen 443 ssl` + ssl_certificate-Zeilen
# werden von certbot automatisch eingefügt (`certbot --nginx -d pir.staging.rebreak.org`).
#
# PIR-Requests können groß sein (EvaluationKey bis ~10 MiB) → client_max_body_size 12m.

server {
    server_name pir.staging.rebreak.org;

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

    location / {
        proxy_pass http://127.0.0.1:8090;
        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;

        client_max_body_size 12m;
        proxy_read_timeout 60s;
        proxy_send_timeout 60s;
    }

    # ── von certbot verwaltet ──
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl_certificate /etc/letsencrypt/live/pir.staging.rebreak.org/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/pir.staging.rebreak.org/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}

# HTTP → HTTPS Redirect (von certbot verwaltet)
server {
    listen 80;
    listen [::]:80;
    server_name pir.staging.rebreak.org;

    if ($host = pir.staging.rebreak.org) {
        return 301 https://$host$request_uri;
    }

    return 404;
}
