caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
57.51k stars 4.01k forks source link

Websocket not support yet? #6587

Closed ssrlive closed 1 week ago

ssrlive commented 1 week ago

I try to reverse proxy my special URI /mypathbWrYWiWL/ as Websocket, but it always failed, it do not send package to target server http://127.0.0.1:12948 at all.

Here's my Caddyfile. What's wrong with it?

mysite.com:443 {
    tls s@gmail.com
    encode gzip

    route /mypathbWrYWiWL/ {
        @websockets {
            header Connection *Upgrade*
            header Upgrade websocket
        }
        reverse_proxy @websockets http://127.0.0.1:12948
    }
    handle {
        reverse_proxy https://www.gov.cn {
            trusted_proxies 0.0.0.0/0
            header_up Host {upstream_hostport}
        }
    }
}

The similar settings for nginx will work fine:

        location /mypathbWrYWiWL/ {
            proxy_redirect off;
            proxy_pass http://127.0.0.1:12948;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $http_host;
        }
francislavoie commented 1 week ago

Websockets are supported. You don't need that @websockets matcher at all if you're matching by path.

Are you sure your URL is exactly /mypathbWrYWiWL/ or is there sometimes something past that like /mypathbWrYWiWL/foo or without the trailing slash /mypathbWrYWiWL? If so then that matcher is incorrect, it might need to be /mypathbWrYWiWL* or /mypathbWrYWiWL/*.

All you really need is this (don't need the route, don't need the @websockets matcher):

reverse_proxy /mypathbWrYWiWL/* 127.0.0.1:12948

I'll close this because it's a usage question and there's nothing actionable for us here. For next time, please ask your usage questions on the Caddy community forums. We prefer to keep the GitHub issue board for bugs and feature requests. Don't forget to fill out the thread template so we can help you!