Cannot access websockets over DNS

Hi, I’m trying to configure remote access to my Homeassistant through NGINX reverse proxy. I have set up port forwarding and the proxy and everything seems to work except websockets.

My Homeassistant is running on port 8123 and NGINX is running on 80 and 443 with Let’sEncrypt SSL certificates.

When I try to access Homeassistant through local IP over https on port 443, everything works, websockets and all, but when I try to access it from the internet via DNS I can’t connect to a websocket. Static files are working fine, only websocket is unreachable, in the web developer tools in my browser I get no response for the websocket request so I’m guessing it’s timing out.

Do you have any ideas why this might be? I thought maybe router settings but since both ports 443 and 80 work that hopefully shouldn’t be a problem.

EDIT: When I try ws = new WebSocket in console with the URL it manages to open the websocket and I see 101 response in the network tab, when I compare the two requests only difference is Sec-WebSocket-Key

EDIT2: Trying multiple new WebSocket one after the other has about 50% success rate, some are resolved in milliseconds, others take up to 6 seconds, so I’m guessing my internete connection is to blame for these problems

I know this post is a bit old, but I encountered the same problem when trying to access Home Assistant from a WireGuard VPN. DNS requests went through without a problem except for websockets.
The only way to solve this problem was to change my DNS record from a CNAME type to an A type.

No idea where the problem really came from, but if this helps anyone…