elixir-plug / plug_cowboy

Plug adapter for the Cowboy web server
Other
243 stars 48 forks source link

Document using loopback vs public IP addresses #61

Closed nathanl closed 3 years ago

nathanl commented 3 years ago

I wanted to document this somewhere for Phoenix users and I thought this might be the best place.

One thing I did not address: when should you use an IPv6 or IPv4 address? It appears to me from experimentation that, unlike Nginx, Cowboy will serve traffic on IPv4 if you bind to an IPv4 address, or on both IPv6 and IPv4 if you bind to an IPv6 address. I was not able to confirm that by looking at the Cowboy code, so I'm not sure, nor am I really sure when one would want to use one or the other. But maybe someone else could elaborate later.

nathanl commented 3 years ago

If this PR is merged, I would make a followup PR to Phoenix to add a reference in the comments of the generated config/runtime.exs where the IP address is set: https://github.com/phoenixframework/phoenix/blob/6605625065e2ea924bb0458335674756ad67ccdf/installer/templates/phx_single/config/runtime.exs#L20

josevalim commented 3 years ago

I was not able to confirm that by looking at the Cowboy code

This is the gen_tcp default configuration. You can pass the ipv6_v6only flag if you want only v5.

josevalim commented 3 years ago

Looks great, I have just added two minor nitpicks!

nathanl commented 3 years ago

@josevalim I addressed your feedback and documented ipv6_v6only, which was news to me (thank you!).

josevalim commented 3 years ago

:green_heart: :blue_heart: :purple_heart: :yellow_heart: :heart: