upstream remnawave_backend_webhooks {
    server backend:8080;
    keepalive 16;
}

upstream remnawave_frontend {
    server frontend:80;
    keepalive 16;
}

server {
    listen 80;
    server_name ${WEBHOOK_HOST} ${MINIAPP_HOST};

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

# WEBHOOK_BASE_URL: Telegram, payment providers and Remnawave webhooks.
server {
    listen 443 ssl;
    http2 on;
    server_name ${WEBHOOK_HOST};

    ssl_certificate /etc/nginx/ssl/${WEBHOOK_HOST}/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/${WEBHOOK_HOST}/privkey.pem;

    client_max_body_size 20m;

    location / {
        proxy_pass http://remnawave_backend_webhooks;
        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-Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

# SUBSCRIPTION_MINI_APP_URL: static Mini App frontend.
# The frontend container proxies /api, /auth and theme/logo assets to backend:8081.
server {
    listen 443 ssl;
    http2 on;
    server_name ${MINIAPP_HOST};

    ssl_certificate /etc/nginx/ssl/${MINIAPP_HOST}/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/${MINIAPP_HOST}/privkey.pem;

    client_max_body_size 20m;

    location / {
        proxy_pass http://remnawave_frontend;
        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-Host $host;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

