Skip to content

Reverse proxy

David Reed edited this page Nov 20, 2026 · 2 revisions

holyWisp has no TLS on its TCP port. A public wss:// relay puts nginx, Caddy or a CDN in front of it to terminate TLS and pass the WebSocket upgrade through. This page covers what the proxy has to forward, how holyWisp learns the real client address from it, the built-in web client behind a proxy, and why WebTransport never goes through the proxy.

The examples use wisp.example.org as an example host name and assume holyWisp listens on 127.0.0.1:6001, which is what the packaged config (deploy/holywisp.conf) does.

What the server expects from a proxy

Everything on the TCP port is HTTP/1.1, and one port carries all of it:

Request What holyWisp does
A WebSocket upgrade on any path Relays Wisp. The path is not checked, so /, /wisp/ or a long keyed path all work.
GET /health {"status":"ok"}
GET /stats The counters as JSON (see Stats and monitoring).
GET /webtransport.json The WebTransport description, only when webtransport is on.
GET / The built-in web client, while serve-webclient is on (the default).
Anything else non-ws-response as 200 text/plain, or 426 when that key is empty.

The plain paths match with or without a query string: GET /health?probe=1 gets the health answer and GET /?utm=x the page. Another path does not: /healthz and /health/ get the banner.

A request counts as a WebSocket upgrade only with GET, Upgrade: websocket, Connection: upgrade, Sec-WebSocket-Version: 13 and a Sec-WebSocket-Key. A proxy that drops the Upgrade or Connection header turns the upgrade into a plain request, and the browser gets a 200 (the page or the banner) where it expected 101.

The request head has limits. Over 8192 bytes, more than 48 headers, a header name that is not an HTTP token, a folded continuation line, or a NUL or bare CR in a value is answered 400 bad request (include/holywisp/ws.h). A browser's upgrade plus a proxy's forwarding headers fits easily. A chain of a CDN and nginx that each add their own set can get close to 48.

holyWisp never sends WebSocket pings of its own. It answers the client's. A Wisp connection with no stream traffic is silent in both directions, so the proxy's idle timeout for upgraded connections has to be longer than any quiet period you want to keep.

The client address

Every per-client limit (connections-limit-per-ip, max-concurrent-connections-per-ip, bandwidth-limit-kbps, the connect rates) and the reputation table are keyed by the client's address. Behind a proxy the TCP peer is the proxy. Unless the proxy is listed in trusted-proxy, every client counts as 127.0.0.1: the 200 new connections per 10 seconds of connections-limit-per-ip is then shared by all of them, and one abusive client's reputation is everyone's.

The holyWisp side of a proxy on the same machine:

host = 127.0.0.1
port = 6001
parse-real-ip = on            # the default
trusted-proxy = 127.0.0.1
trusted-proxy = ::1           # if the proxy connects over IPv6 loopback

How the address is read, from resolve_real_ip in src/server/conn.c and hw_real_ip in src/common/filter.c:

  1. If the peer is not in a trusted-proxy CIDR, the peer is the client and the headers are ignored.
  2. Otherwise the server takes every instance of the first trusted header the request carries (X-Forwarded-For unless you change trusted-header) as one comma list.
  3. It walks that list from the right, skips addresses of trusted proxies, and the first address that is not one is the client. Entries may be ip, ip:port, [v6] or [v6]:port.
  4. An entry that is not an address (a name, unknown, an empty one) ends the walk, and the client is the peer.

A header value longer than 511 bytes is cut by the parser, and a cut value from a trusted proxy is refused with 400 forwarding header too long, because the cut end is the part the proxy wrote. From an untrusted peer a cut header is ignored.

Name another header with trusted-header only if the proxy in front overwrites it on every request. trusted-header adds to the list, so put a trusted-headers-reset = on line before it if X-Forwarded-For should not be read at all (off does nothing). CF-Connecting-IP is set by Cloudflare and passed through untouched by nginx, so behind anything other than Cloudflare a client chooses its own value.

A proxy that shares its address

trusted-proxy = 127.0.0.1 trusts every process on the host, since all of them can connect from loopback and send an X-Forwarded-For of their choice. trusted-proxy-secret closes that: with it set, the forwarding headers count only on requests that also carry X-HolyWisp-Proxy-Secret: <secret>, compared in constant time. A request without it is treated as coming from its peer.

trusted-proxy = 127.0.0.1
trusted-proxy-secret = <long-random-secret>

The proxy then sets that header on every request it forwards (the nginx and Caddy examples below show where). The value is never echoed in a config error. The npm package does this by itself with a new secret per start (see Node package).

Connections from a trusted proxy are also exempt from max-handshakes-per-ip (128 connections of one address still sending their HTTP head). Without trusted-proxy, 128 slow clients behind the proxy are enough for the next one to get a bare 429 at accept.

nginx

A server block that terminates TLS and passes everything on the name to holyWisp:

map $http_upgrade $connection_upgrade {
    default upgrade;
    ''      close;
}

server {
    listen 443 ssl;
    listen [::]:443 ssl;
    server_name wisp.example.org;

    ssl_certificate     /etc/letsencrypt/live/wisp.example.org/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/wisp.example.org/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:6001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $remote_addr;
        # with trusted-proxy-secret set in holyWisp:
        # proxy_set_header X-HolyWisp-Proxy-Secret <long-random-secret>;

        proxy_buffering off;
        proxy_buffer_size 256k;
        proxy_buffers 4 256k;
        proxy_busy_buffers_size 256k;

        proxy_connect_timeout 10s;
        proxy_read_timeout 86400s;
        proxy_send_timeout 86400s;
    }

    location = /stats {
        allow 127.0.0.1;
        deny all;
        proxy_pass http://127.0.0.1:6001;
    }
}

What each part is for:

Directive Why
proxy_http_version 1.1, Upgrade, Connection nginx speaks HTTP/1.0 to upstreams and drops hop-by-hop headers unless told otherwise. Without these three the upgrade arrives as a plain GET.
X-Forwarded-For $remote_addr Overwrites whatever the client sent with the address nginx saw. $proxy_add_x_forwarded_for also works with holyWisp's right-to-left walk, but it appends to the client's own value, and a client that sends a long one then makes its own upgrade fail with 400 forwarding header too long.
proxy_buffer_size 256k and friends An upgraded connection is relayed through a buffer of proxy_buffer_size each way, 4 or 8 KiB by default. On a test host one connection did about 400 to 500 MiB/s with the default and about 2,000 MiB/s with 256k.
proxy_read_timeout 86400s nginx closes an upgraded connection after this long with nothing from upstream. The default 60 s ends every Wisp connection that idles for a minute.
location = /stats /stats is on the same port as the relay. Keep it off the public name unless you mean to publish it.

Each Wisp connection holds two nginx connections (client and upstream), so worker_connections and worker_rlimit_nofile bound how many clients nginx can carry.

A relay on a path

To keep the name for a site and run the relay under /wisp/:

location /wisp/ {
    proxy_pass http://127.0.0.1:6001/;
    # the same proxy_set_header, buffer and timeout lines as above
}

The trailing / on proxy_pass replaces the /wisp/ prefix with /, so a browser's GET /wisp/ reaches holyWisp as GET / and gets the web client, while an upgrade on wss://wisp.example.org/wisp/ works either way. Set webclient-wisp-url so the page offers the right URL (see The web client behind a proxy).

Behind a CDN

With Cloudflare or another CDN in front of nginx, $remote_addr is the CDN's address. Let nginx's realip module replace it with the client's before it is forwarded:

# one set_real_ip_from per published CDN range
set_real_ip_from 203.0.113.0/24;
real_ip_header CF-Connecting-IP;

203.0.113.0/24 is a documentation range standing in for the CDN's list. With that, X-Forwarded-For $remote_addr carries the client, and holyWisp still trusts only 127.0.0.1. The CDN's own WebSocket idle limit applies on top of nginx's.

Caddy

Caddy's reverse_proxy passes WebSocket upgrades without extra lines, obtains the certificate itself, and sets X-Forwarded-For to the address it saw. It ignores a client's incoming X-Forwarded-For unless you configure trusted_proxies in Caddy.

wisp.example.org {
    @stats path /stats
    respond @stats 404

    reverse_proxy 127.0.0.1:6001 {
        # with trusted-proxy-secret set in holyWisp:
        # header_up X-HolyWisp-Proxy-Secret {env.HOLYWISP_PROXY_SECRET}
        stream_close_delay 5m
    }
}

stream_close_delay (Caddy 2.7 and later) keeps upgraded connections open for that long across a Caddy config reload. Without it, a reload closes every Wisp connection at once.

The web client behind a proxy

With serve-webclient = on, holyWisp answers GET / with the browser client from examples/wisp-webclient.html. The page fills its Wisp URL field with its own origin and /, so on https://wisp.example.org/ it offers wss://wisp.example.org/. That is right when the relay is at the root.

When the page is reached at a path, or the relay is on another name, set the URL it offers:

webclient-wisp-url = wss://wisp.example.org/wisp/

The server splices it into the page as window.HOLYWISP_CONFIG.wisp. It must start with ws:// or wss:// and may not hold a space, a control byte, a quote, a backslash, < or >; anything else is refused at start with webclient-wisp-url must start with ws:// or wss:// or webclient-wisp-url contains a character that cannot go into the page.

With the UDP toggle on, the page fetches /webtransport.json from the root of the relay's origin (https://wisp.example.org/webtransport.json for wss://wisp.example.org/wisp/). Proxy that path to holyWisp as well when WebTransport is on. holyWisp answers it with Cache-Control: no-store and Access-Control-Allow-Origin: *; a caching layer in front should not keep it, since the certificate hashes in it rotate.

To serve no page at all, set serve-webclient = off. GET / then gets non-ws-response.

WebTransport does not go through the proxy

WebTransport is HTTP/3 over QUIC on UDP. nginx and Caddy do not forward a WebTransport session to a backend, so the browser talks to holyWisp's UDP listener directly. What follows from that:

  • The UDP listener binds webtransport-host, which defaults to host. With the packaged host = 127.0.0.1 it is reachable from the machine itself only; set webtransport-host = 0.0.0.0 (or the public address) and open the UDP port in the firewall.

  • The UDP port is webtransport-port, by default the same number as port. When /webtransport.json has no webtransport-url, the page dials the relay's own host and port over HTTPS, which behind nginx on 443 is UDP 443. Either bind webtransport-port = 443, or set webtransport-url = https://wisp.example.org:6001/ and open that port.

  • Ports under 1024 need CAP_NET_BIND_SERVICE, which the packaged unit drops. Add it with sudo systemctl edit holywisp:

    [Service]
    AmbientCapabilities=CAP_NET_BIND_SERVICE
    CapabilityBoundingSet=CAP_NET_BIND_SERVICE
  • An nginx with listen 443 quic holds UDP 443 itself. Give holyWisp another port or another address.

  • No proxy header is read on the UDP listener, whatever trusted-proxy says. The client address is the UDP peer.

Certificates, path rules and the rest are on WebTransport.

Checking the setup

Health through the proxy:

curl -i https://wisp.example.org/health

An upgrade through the proxy. A working path prints 101 Switching Protocols and then waits (Wisp v1 sends a binary CONTINUE right after it); a 200 means the upgrade headers were not forwarded:

curl -i --http1.1 --max-time 3 \
  -H 'Connection: Upgrade' -H 'Upgrade: websocket' \
  -H 'Sec-WebSocket-Version: 13' -H 'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==' \
  https://wisp.example.org/

holywisp-client speaks ws:// only (it answers wss:// is not supported; terminate TLS in front of the server), so test a stream with it against holyWisp's own port, or use a browser client through the proxy.

That the client address arrives: raise the log level while the server runs (sudo systemctl kill -s USR1 holywisp, once from info to debug) and open a connection. Each upgrade logs the peer and the address it resolved to:

2026-11-20T00:58:06.332Z [debug] conn: 127.0.0.1:36392 (203.0.113.7): websocket wisp-v1

127.0.0.1:36392 is nginx, 203.0.113.7 is the client. If the address in parentheses is 127.0.0.1 too, the proxy is not in trusted-proxy, the secret is missing, or the header is not being set. -s USR2 lowers the level again. Symptoms and fixes are collected on Troubleshooting.

Clone this wiki locally