server {
    listen 443 ssl ipv6only=on;

    server_name api.quan-ng.uk api.techgel.vn;
    ssl_certificate /etc/letsencrypt/live/techgel-erp/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/techgel-erp/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

    client_max_body_size 50m;

    # Proxy API requests
    location /api/ {
        proxy_pass http://localhost:5000;
        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;
    }

    location /hubs/ {
       proxy_http_version 1.1;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "Upgrade";
       proxy_set_header Host $host;
       proxy_set_header Origin $http_origin;  # 🔥 CORS
       proxy_pass http://localhost:5000;
    }

}

server {
    if ($host = api.techgel.vn) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host ~* ^(api\.quan-ng\.uk|api\.techgel\.vn)$) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    listen [::]:80;

    server_name 127.0.0.1 localhost api.quan-ng.uk api.techgel.vn;
    return 404; # managed by Certbot


}
