Deployment
To make your relay publicly accessible with TLS, run Wisp behind Caddy, which provisions and renews certificates automatically.
# Run wisp
docker run -d --restart always -p 127.0.0.1:7777:7777 -v wisp-data:/data \
ghcr.io/privkeyio/wisp --spider-admin npub1yourkey...
# Install Caddy for automatic TLS
sudo apt install -y caddy
Create /etc/caddy/Caddyfile:
relay.yourdomain.com {
respond /metrics 404
reverse_proxy localhost:7777
}
Reload Caddy:
sudo systemctl restart caddy
Your relay is now live at wss://relay.yourdomain.com.
Behind a proxy: set
trust_proxy = trueandtrusted_proxies = "127.0.0.1"(the proxy’s address) in the[security]section ofwisp.tomlso per-IP connection limits and IP allow/deny lists see the real client IP from Caddy’sX-Forwarded-Forheader instead of127.0.0.1.trust_proxywith an emptytrusted_proxieshonors the header from every peer, so a client that reaches the relay port directly can spoof any IP.Without
trust_proxy, every client shares the proxy’s IP, so all per-IP controls become relay-wide: not onlymax_connections_per_ip, but also theevents_per_minuteandqueries_per_minuterate limits and the IP allow/deny lists. One busy client then gets everyonerate-limited. wisp warns when it ignores anX-Forwarded-FororX-Real-IPheader, and the wording depends on the socket peer:
- From a peer that could be a proxy (loopback, RFC 1918, CGNAT
100.64.0.0/10, link-local, IPv6 ULAfc00::/7) whiletrust_proxyis off, the warning names the peer and suggeststrust_proxy = truetogether withtrusted_proxiesset to it.- From such a peer while
trust_proxyis on but the peer is missing from a non-emptytrusted_proxies(for example a container gateway such as10.0.3.1), the warning says the peer is not intrusted_proxies; add it if it is your proxy.- From a public peer while
trust_proxyis off, the warning only notes that a client sent the header. If you don’t run a reverse proxy this is client-supplied and can be ignored. A public peer missing fromtrusted_proxiesis not logged.Each kind of peer (could-be-proxy, public) is logged at most once an hour, so a direct client cannot crowd out the proxy warning.
wisp_forwarded_header_ignored_totalon/metricscounts every ignored forwarded header.
Limiting connections per source
max_connections_per_ip is applied during the WebSocket upgrade, because that is the first
point at which wisp knows the client IP. A connection that completes the TCP handshake and
then sends nothing never reaches it. Those connections are bounded — they are closed after
10s if no request arrives — but until then they occupy a worker slot, so a single source can
hold max_conn slots per worker by reconnecting.
Capping concurrent connections per source address closes that, and it belongs at the edge,
where connections arrive. Apply it wherever the public port is, not on the relay port.
Behind a reverse proxy every connection reaches wisp from 127.0.0.1, so a per-IP rule on the
relay port would either do nothing or throttle the proxy itself.
Exposed directly — limit on the relay port:
# nftables
nft add rule inet filter input tcp dport 7777 ct count over 10 reject
# iptables
iptables -A INPUT -p tcp --dport 7777 \
-m connlimit --connlimit-above 10 --connlimit-mask 32 -j REJECT
Behind a proxy — limit on the public port instead:
iptables -A INPUT -p tcp --dport 443 \
-m connlimit --connlimit-above 10 --connlimit-mask 32 -j REJECT
Caddy has no built-in per-connection limiter, so with the Caddyfile above the firewall rule is the control. If you front wisp with nginx instead, it can do this itself:
limit_conn_zone $binary_remote_addr zone=perip:10m;
server {
listen 443 ssl;
location = /metrics { return 404; }
location / {
limit_conn perip 10;
proxy_pass http://127.0.0.1:7777;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Set the limit above max_connections_per_ip (default 10) so the edge only rejects what wisp
would have refused anyway. --connlimit-mask 32 counts per address; lower it to limit per
subnet. Note that any of these only constrain a single source: they do not help against a
flood distributed across many addresses, which is what max_conn and the request timeout
bound.