Reverse Proxy Websocket

1. Caddy version (caddy version):


2. How I run Caddy:

caddy run

a. System environment:

Ubuntu 20.04 systemd

b. Command:

caddy run

c. Service/unit/compose file:

paste full file contents here

d. My complete Caddyfile or JSON config:

    auto_https disable_redirects
    auto_https off
    http_port 8999

:2016 {

    reverse_proxy * localhost:1337 {


    reverse_proxy /ws ws://localhost:8443 {
        header_up Host {}
        header_up X-Real-IP {http.request.remote}
        header_up X-Forwarded-For {http.request.remote}
        header_up X-Forwarded-Port {http.request.port}
        header_up X-Forwarded-Proto {http.request.scheme}

3. The problem I’m having:

giving WebSocket connection to ‘ws://localhost:2016/ws?peer=996a8fab-bbc2-48f5-b003-b72eebf45cf1’ failed: Error during WebSocket handshake: Unexpected response code: 502

4. Error messages and/or full log output:

2020/09/04 17:13:06.600 ERROR http.log.error EOF {“request”: {“method”: “GET”, “uri”: “/ws?peer=996a8fab-bbc2-48f5-b003-b72eebf45cf1”, “proto”: “HTTP/1.1”, “remote_addr”: “[::1]:50190”, “host”: “localhost:2016”, “headers”: {“Sec-Websocket-Protocol”: [“protoo”], “Pragma”: [“no-cache”], “Cache-Control”: [“no-cache”], “Upgrade”: [“websocket”], “Sec-Websocket-Version”: [“13”], “Accept-Language”: [“en-GB,en-US;q=0.9,en;q=0.8”], “Sec-Websocket-Extensions”: [“permessage-deflate; client_max_window_bits”], “Connection”: [“Upgrade”], “User-Agent”: [“Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36”], “Origin”: [“http://localhost:3000”], “Accept-Encoding”: [“gzip, deflate, br”], “Sec-Websocket-Key”: [“lowyVnepSNJHotu8BRvZYg==”]}}, “duration”: 1.002702855, “status”: 502, “err_id”: “qirrmep88”, “err_trace”: “reverseproxy.(*Handler).ServeHTTP (reverseproxy.go:411)”}

5. What I already tried:

6. Links to relevant resources:

i am running GitHub - pion/ion: Real-Distributed RTC System by pure Go and Flutter biz in 8443 port

ws:// is not a valid scheme in Caddy for reverse_proxy. Instead, just use localhost:8443.

Also, those header_up lines are unnecessary, Caddy already sets X-Forwarded-For and X-Forwarded-Proto on its own, and the others are likely not needed or ineffectual.

This topic was automatically closed after 30 days. New replies are no longer allowed.