project-pegaprox icon indicating copy to clipboard operation
project-pegaprox copied to clipboard

[Bug] Proxmox VM VNC console fails due to duplicate Host header

Open ralphys opened this issue 3 weeks ago • 6 comments

Hey there! 👋 Thanks for taking the time to report this bug — we appreciate it!

Please keep in mind: PegaProx is developed and maintained entirely by volunteers in our free time. We do our best, but we can't work magic 🪄 — please be patient, we'll get to your issue as soon as we can.

Want to help keep PegaProx alive?

  • ⭐ [Star the project](https://github.com/PegaProx/project-pegaprox) — it's free and helps a lot!
  • 💖 [Become a Sponsor](https://pegaprox.com/#sponsor) — helps us dedicate more time to development
  • 🤝 Contributing code or docs is always welcome too!

PegaProx Version:1.4.1

Docker image: ghcr.io/pegaprox/pegaprox:1.4.1

Steps to Reproduce

  1. Deploy PegaProx using the official Docker image.
  2. Configure a Proxmox VE 9.x cluster.
  3. Log in to the PegaProx web interface.
  4. Navigate to a VM hosted on the Proxmox cluster.
  5. Open the VM's VNC console.
  6. Observe that the console fails to connect and closes immediately.

Expected behavior:

The VM's VNC console should open normally and display the VM screen.

Actual behavior:

The console fails to connect. The browser console displays:

Failed when connecting: Connection closed (code: 1000)

Describe the bug

I was having trouble opening the VNC console for Proxmox VMs through PegaProx 1.4.1.

The PegaProx web interface worked normally, and I could access the VM details, but opening a VM's console would fail.

The Nginx reverse proxy was successfully establishing the WebSocket connection with PegaProx (HTTP 101), so the problem wasn't with Nginx or the browser-to-PegaProx connection.

Root cause

After checking the PegaProx logs and source code, I found the following error:

WebSocketBadStatusException:
Handshake status 400 invalid duplicate header

The issue appears to be in:

/app/pegaprox/api/vms.py

Inside the _pve_console_ws_auth() function, the code initializes the headers with:

headers = {"Host": netloc}

However, the websocket-client library automatically generates the Host header from the WebSocket URL. Supplying it manually results in a duplicate Host header.

Proxmox rejects the WebSocket handshake with HTTP 400 because of this duplicate header.

Proposed fix

Replace:

headers = {"Host": netloc}

with:

headers = {}

The rest of the function can remain unchanged. The Cookie and Authorization headers are still added as needed.

Result

I built a custom Docker image with this one-line change and deployed it in place of the original PegaProx 1.4.1 image.

After restarting the container, the Proxmox VNC console connected successfully.

This confirms that removing the manually supplied Host header resolves the issue in my environment.

Environment

  • PegaProx: 1.4.1
  • Proxmox VE: 9.x
  • Deployment: Docker
  • Reverse proxy: Nginx
  • Browsers tested: Firefox and Brave

Hopefully this helps identify and fix the issue in an upcoming release so other users don't run into the same problem.

Thanks for the work on PegaProx!

ralphys avatar Nov 09 '26 07:11 ralphys

Thanks for digging into this and for the clear write-up. You were right: websocket-client writes its own Host line and we added a second one. Proxmox started refusing repeated Host, Cookie and Content-Length headers in libpve-http-server-perl 6.0.6 (released at the end of October), which is why it showed up now on updated PVE 9 nodes and not before.

The fix from #1330 is on the Testing branch now. If you want to try it before a release, ghcr.io/pegaprox/pegaprox-testing:latest has it once the current image build is through. We checked it against a node with the new pveproxy (console failed before, connects now) and one still on 6.0.5 (keeps working).

PegaProx is funded by its sponsors at https://opencollective.com/pegaprox, if this saved you some time.

MrMasterbay avatar Nov 09 '26 10:11 MrMasterbay

The fix from #1330 is on the Testing branch now. If you want to try it before a release, ghcr.io/pegaprox/pegaprox-testing:latest has it once the current image build is through. We checked it against a node with the new pveproxy (console failed before, connects now) and one still on 6.0.5 (keeps working).

Pulled the Testing image (ghcr.io/pegaprox/pegaprox-testing:latest), and I can confirm the fix works! The console is connecting successfully now.

  • Proxmox VE: 9.2.26
  • Reverse proxy: Nginx

Thanks for all the great work!

ralphys avatar Nov 09 '26 22:11 ralphys

Nice, thanks for checking it on the Testing image, and for the version info. Good to know it holds up behind nginx too. I'll leave the issue open until the fix is in a regular release.

Marcus

mkellermann97 avatar Nov 10 '26 08:11 mkellermann97

One additional note: although this is not directly related to the reported bug, I wanted to share an example of my Nginx reverse-proxy configuration for PegaProx in case it is useful to other users.

This setup includes:

  • HTTP-to-HTTPS redirection.
  • WebSocket support for the VNC console and SSH terminal.
  • Server-Sent Events (SSE) support for live updates.
  • A separate HTTPS listener for direct VNC and SSH console access.
  • Support for large ISO uploads (up to 100 GB).

Nginx configuration

# WebSocket connection handling
map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

# PegaProx application
upstream pegaprox_app {
    server 192.0.2.20:5000;
}

# VNC console
upstream pegaprox_vnc {
    server 192.0.2.20:5001;
}

# SSH terminal
upstream pegaprox_ssh {
    server 192.0.2.20:5002;
}

# Redirect HTTP to HTTPS
server {
    listen 192.0.2.10:80;
    server_name pegaprox.example.com;

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

# HTTPS reverse proxy
server {
    listen 192.0.2.10:443 ssl http2;
    server_name pegaprox.example.com;

    # SSL certificates
    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    ssl_protocols TLSv1.2 TLSv1.3;

    # ISO uploads
    client_max_body_size 100g;

    proxy_connect_timeout 10;
    proxy_read_timeout 3600;
    proxy_send_timeout 3600;

    # VNC console WebSocket
    location ~ ^/api/clusters/.*/vncwebsocket {
        proxy_pass https://pegaprox_vnc;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        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;

        proxy_read_timeout 3600;
    }

    # SSH terminal WebSocket
    location ~ ^/api/clusters/.*/shellws {
        proxy_pass https://pegaprox_ssh;

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        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;

        proxy_read_timeout 3600;
    }

    # Server-Sent Events (live updates)
    location /api/sse/ {
        proxy_pass https://pegaprox_app;

        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;

        proxy_buffering off;
        proxy_cache off;
        proxy_read_timeout 86400;
    }

    # Main application and API
    location / {
        proxy_pass https://pegaprox_app;

        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        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;
    }
}

# Dedicated VNC console access
server {
    listen 192.0.2.10:444 ssl;
    server_name pegaprox.example.com;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
        proxy_pass https://192.0.2.20:5001;

        proxy_ssl_verify off;
        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        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;

        proxy_read_timeout 3600;
    }
}

# Dedicated SSH terminal access
server {
    listen 192.0.2.10:445 ssl;
    server_name pegaprox.example.com;

    ssl_certificate     /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

    location / {
        proxy_pass https://192.0.2.20:5002;

        proxy_ssl_verify off;
        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;

        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;

        proxy_read_timeout 3600;
    }
}

A few notes:

  • The IP addresses and domain names above are placeholders and should be replaced with your actual values.
  • The map directive belongs in the Nginx http context, not inside a server block.
  • The dedicated VNC and SSH listeners use proxy_ssl_verify off because the upstream services may use self-signed certificates. Adjust this if your upstream certificates are trusted.

Hopefully this helps anyone looking to run PegaProx behind an Nginx reverse proxy.

ralphys avatar Nov 10 '26 15:11 ralphys

Thanks for sharing that. A working nginx example with the two console listeners and SSE is handy for anyone else behind a proxy, so it's good to have it here where people searching for it will find it.

Marcus

mkellermann97 avatar Nov 11 '26 08:11 mkellermann97

1.5.0 is out with the console fix, so no more need for the testing image here. Thanks for confirming it worked for you. Closing.

Nico

MrMasterbay avatar Nov 15 '26 01:11 MrMasterbay