Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse Proxy for Web Sockets (WSS) using Caddy

Project GitHub URL

I have just started using caddy. I have made a simple chat application which I am serving using caddy.
The WebSockets are served on ws instead of wss by the application, similar to how the application is served on HTTP and not https, by the application. I am trying to secure the protocols using caddy and have successfully done that for https. Since I wouldn't be able to use ws when I am using https, I would need to serve the WebSockets on wss as well. I couldn't find a way in the docs where I can find how to reverse proxy wss to ws as I did with https to http.

What I tried

your.tld.com {
    proxy / 0.0.0.0:8266 {
        transparent
        websocket
    }
}

2)

your.tld.com {
    proxy / 0.0.0.0:8266 {
        transparent
    }
   proxy /ws 0.0.0.0:8266 {
        transparent
    }
}

3)

your.tld.com {
    proxy / 0.0.0.0:8266 {
        transparent
    }
   proxy /ws 0.0.0.0:8266/ws {
        transparent
   }
}

The above attemots did not work. Hopefully will get a solution here.

like image 671
Shaurya Chaudhuri Avatar asked Jul 24 '17 05:07

Shaurya Chaudhuri


1 Answers

I have something like this is my config files :

proxy /api/v1/streaming http://localhost:4000 {
    websocket
} 

So for you it will be something like :

your.tld.com {
   proxy / 0.0.0.0:8266 {
        transparent
   }
   proxy /ws http://0.0.0.0:8266 {
        websocket
   }
}
like image 161
papey Avatar answered Sep 27 '22 20:09

papey