server {
    listen 443 ssl;
    http2 on;
    server_name max.aegisone.ru;

    ssl_certificate /etc/nginx/certs/live/max.aegisone.ru/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/live/max.aegisone.ru/privkey.pem;

    client_max_body_size 50M;

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

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

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

    location /health {
        proxy_pass http://127.0.0.1:8002/health;
        proxy_set_header Host $host;
    }

    location / {
        return 404;
    }
}

server {
    listen 80;
    server_name max.aegisone.ru;

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

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