Ave Nix-ers,
I’m going out of my mind trying to switch from Strfry to Haven, two Nostr relays, both with a NixOS module. Strfry works, Haven works on its own, but behind NGINX with the exact same configuration that works for Strfry, it doesn’t. Technically they work in the exact same way and implement the exact same protocol; I see no reason why I’m getting a 400 Bad Request via NGINX > Haven, while I get the expected HTML with NGINX > Strfry or directly on localhost with Haven.
They both use WebSockets, they both exchange JSON on a specific port (I choose the same switching them, so entirely not touching the vhost config. I put both on 127.0.0.1:21498and NGINX proxyPass with the very same config:
I can connect normally to both via localhost, but with Strfry curl-ing to my hostname I got text/html as expect, while to Haven I got just 400 Bad Requestwith nothing helpful from both NGINX and Haven logs, with Haven NGINX seems to return 400 before even trying to pass something to Haven.
This sounds like it could be related to subtle differences in how Haven handles WebSocket upgrades and header validation compared to Strfry, even if the protocol is technically the same. I’d suggest double-checking NGINX’s proxy_http_version, Upgrade, and Connection headers, and also testing with explicit proxy_set_header Connection $connection_upgrade; to ensure compatibility.
I ran into a somewhat similar situation while working on deployment automation and testing workflows using blox scripts, where slight proxy and header handling differences caused unexpected 400 errors. In my case, adjusting WebSocket upgrade handling and request buffering fixed it.
You might also want to try temporarily disabling SSL and ACME to rule out TLS-related issues.
I actually tried replicating the NGINX headers via curl directly on localhost; if I pass -H "Upgrade: websocket", it fails no matter what else I do, but if I don’t pass it, it works. It still works with -H "Connection: Upgrade" and every other header passed manually via curl… Even inserting -H "Sec-WebSocket-Key: SomeGarbageString” -H “Sec-WebSocket-Version: 13” without -H “Upgrade: websocket” works…
proxy_http_version is 1.1, I don’t think I can set it for a specific vhost BTW.