Getting ip address fowarded as conn host instead of domain on liveview reconnect(sometimes)

I’m having socket reconnection issues sometimes on reconnect, refreshing usually fixes this. Looking at the logs, my phoenix app sometimes is receiving an ip address instead of a domain as the host in the “conn”. I am parsing the host of the conn and routing based on subdomain so this causes issues.

eg. :erlang.binary_part(“127.0.0.1”, 0, -3) instead of :erlang.binary_part(“sub.domain.com”, 0, -3)

Anyone experiencing similar issues?

Are you rewriting based on x-forwarded-for? We don’t do this by default in Phoenix so it’s possible some clients are sending the Host header differently.

Ensure this is in your endpoint config for prod. Note that host: nil will dynamically redirect to the host of the current request, which is probably want you want here if you have different subdomains:

  force_ssl: [rewrite_on: [:x_forwarded_proto], host: nil]

I am using

  plug Plug.RewriteOn, [:x_forwarded_host, :x_forwarded_port, :x_forwarded_proto]

before my subdomain router.

Do I need to configure force ssl on prod.exs as well?

ah, the other thing to look at is fly dedicates ipv4 addresses to your app (fly ips list) so it’s possible the logs you are seeing are not related to the “issues sometimes on reconnect”, but instead someone crawling the ipv4 address space and hitting your app at the same time?

1 Like

@chrismccord I think you are correct! I might be having some other issues, but the weird domains are just internet noise. Thanks for the help!

1 Like