I’m trying to restrict specific paths to only accept WebSocket connections in my Caddy 2 server. I have a working configuration for regular HTTP traffic, but I want to modify it to only allow WebSocket connections for certain endpoints.
Current working config:
handle /path* {
uri strip_prefix /path
reverse_proxy localhost:3000
}
I want to:
- Only allow WebSocket connections to /path
- Return 404 for any non-WebSocket requests to these paths
- Maintain the WebSocket connection (currently getting Connection: keep-alive instead of upgrade)
I’ve tried various approaches with @websocket matchers and header checks but can’t get it to work. What’s the correct way to restrict paths to WebSocket-only connections in Caddy 2?