Reverse_proxy using unix socket websocket does not work

1. Output of caddy version:

2.6.2

2. How I run Caddy:

screen.fos.gg {
     reverse_proxy unix/run/screego/screego.sock
      encode gzip
}

a. System environment:

Normal systemd

3. The problem I’m having:

I am moving from listing on ports to sockets. With normal ip/port the websocket is accessible, but with unix sockets its not accessible.

4. Error messages and/or full log output:

Is empty

5. What I already tried:

(The server now uses again ports, thats why it works now)

curl against Caddy

            curl --include \
                      --no-buffer \
                      --header "Connection: Upgrade" \
                      --header "Upgrade: websocket" \
                      --header "Origin: http://example.com:80" \
                      --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
                      --header "Sec-WebSocket-Version: 13" \
                 https://screen.fos.gg/stream
HTTP/2 200 
alt-svc: h3=":443"; ma=2592000
server: Caddy
content-length: 0
date: Tue, 13 Dec 2022 22:43:30 GMT

Curl against the used socket it works

curl --include \
                          --no-buffer \
                          --header "Connection: Upgrade" \
                          --header "Upgrade: websocket" \
                          --header "Host: example.com:80" \
                          --header "Origin: http://example.com:80" \
                          --header "Sec-WebSocket-Key: SGVsbG8sIHdvcmxkIQ==" \
                          --header "Sec-WebSocket-Version: 13" \
                     --unix-socket /var/run/screego/screego.sock http://localhost/stream
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: qGEgH3En71di5rrssAZTmtRTyFk=

The syntax should be unix//run/screego/screego.sock, i.e. two //. That’s because unix/ is the network part, and the rest is the path. So you need a leading / to make it an absolute path, otherwise it’s a relative path from Caddy’s working directory.

1 Like

Hey @francislavoie ,

The website itself is working, only the Websockets are not connecting. I changed the line to double slash :slight_smile:

This topic was automatically closed after 30 days. New replies are no longer allowed.