Getting a '502 - Bad gateway' when proxying the vncwebsocket.

michael-h

New Member
Apr 18, 2023
1
1
1
Hello,

I am currently using Nginx to embed a console onto an external webpage. To accomplish this, I am proxying the content to the Proxmox host. Please refer to the Nginx configuration below:

Nginx configuration:
Code:
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    return 301 https://example.com$request_uri;
}
server {
    listen 443 ssl;
    listen [::]:443 ssl;
    ssl_certificate /etc/ssl/certs/example.com.pem;
    ssl_certificate_key /etc/ssl/private/example.com.key;
    ssl_session_timeout 1d;
    root /var/www/example.com;
    index index.html;
     location /console/ {
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Host proxmox-host.com;
        proxy_pass https://proxmox-host.com/;
    }

    location /api2/json {
        proxy_pass https://proxmox-host.com/api2/json;
        proxy_http_version 1.1;
        proxy_set_header Host proxmox-host.com;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_set_header Authorization  "PVEAPIToken=TOKEN";    
    }
    location /novnc/ {
        proxy_pass https://proxmox-host.com/novnc/;
    }
}


The problem I am experiencing:
With the above Nginx configuration, I can now access the console via an external web page. All calls made by the novnc client work. However, as soon as I make the call to establish the websocket connection, I usually get a 502 bad gateway error after 6 seconds. Occasionally, it is possible to connect to the console, and then the connection is established after 2 seconds. But this occurs at most 2 times out of 10 attempts. Most of the time, the websocket connection is simply not established.

Scherm­afbeelding 2023-04-28 om 11.03.00.png


What I have already tried:
  • Tried setting different headers, such as keep-alive, in the proxy_set_header.
  • Checked if Nginx sets a timeout after 6 seconds, but this doesn't seem to be the case.
  • Checked the Nginx logs, which indicate that the handshake has failed.


My specific question:
Does anyone know why the websocket connection is sometimes established but mostly not? And why it times out after 6 seconds when it fails?
 
  • Like
Reactions: Kolovatoff1
@yswery, personally I didn't figure this out myself, but if I remember correctly, it had something to do with routing within Proxmox. The issue was related to IPv4 and IPv6, but I'm not exactly sure. It was a problem with correctly resolving the address or something similar. Hopefully, this information can help you make some progress.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!