Websocket with Cloudflare Tunnel Reversed Proxy to Self-hosted Ubuntu Server

Image by James M Snell. Edited to Illustrate Architecture in This Post

Cloudflare Tunnel (aka Argo Tunnel)is tunneling software that lets you quickly secure and encrypt application traffic to any type of infrastructure.

#Although ws/wss is not listed as one of the supported protocols, it will still work.ingress:
- hostname: mydomain
service: ws://localhost:port
- service: http_status:404
# Websocket is on top of TCP, which is different from the HTTP protocol. Fortunately, its handshake is compatible with the HTTP after upgrading the connection to Websocket.location /ws/ {
proxy_pass http://127.0.0.1:port;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header Host $host;
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store