Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit c499f5d

Browse files
Update Caddy example for Caddy v2
Caddy v2 greatly simplifies things for proxying websockets. The dumb rewrite hack is no longer necessary because request matchers handle it perfectly. Caddy is _by far_ the simplest and easiest solution for proxying websockets like this.
1 parent e9b85bb commit c499f5d

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

docs/basic-usage/ssl.md

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -270,28 +270,20 @@ You know you've reached this limit of your Nginx error logs contain similar mess
270270

271271
Remember to restart your Nginx after you've modified the `worker_connections`.
272272

273-
### Example using Caddy
273+
### Example using Caddy v2
274274

275-
[Caddy](https://caddyserver.com) can also be used to automatically obtain a TLS certificate from Let's Encrypt and terminate TLS before proxying to your echo server.
275+
[Caddy](https://caddyserver.com) can also be used to automatically obtain a TLS certificate from Let's Encrypt and terminate TLS before proxying to your websocket server.
276276

277277
An example configuration would look like this:
278278

279279
```
280280
socket.yourapp.tld {
281-
rewrite / {
282-
if {>Connection} has Upgrade
283-
if {>Upgrade} is websocket
284-
to /websocket-proxy/{path}?{query}
281+
@ws {
282+
header Connection *Upgrade*
283+
header Upgrade websocket
285284
}
286-
287-
proxy /websocket-proxy 127.0.0.1:6001 {
288-
without /special-websocket-url
289-
transparent
290-
websocket
291-
}
292-
293-
tls youremail.com
285+
reverse_proxy @ws 127.0.0.1:6001
294286
}
295287
```
296288

297-
Note the `to /websocket-proxy`, this is a dummy path to allow the `proxy` directive to only proxy on websocket connections. This should be a path that will never be used by your application's routing. Also, note that you should change `127.0.0.1` to the hostname of your websocket server. For example, if you're running in a Docker environment, this might be the container name of your websocket server.
289+
Note that you should change `127.0.0.1` to the hostname of your websocket server. For example, if you're running in a Docker environment, this might be the container name of your websocket server.

0 commit comments

Comments
 (0)