NullOranje

NullOranje

Phoenix won't respond on IPv4

I’m trying to setup a Vagrant box using generic/freebsd12 as the base image. I cannot get my Phoenix application to listen on IPv4 addresses inside the VM. It will respond to IPv6 as expected, so I know it works.

config :bison_app, BisonWeb.Endpoint,
  http: [
    port: String.to_integer(System.get_env("PORT") || "4000")
  ],
  url: [host: System.get_env("HOST") || "app.local"],
  cache_static_manifest: "priv/static/cache_manifest.json",
  secret_key_base: secret_key_base

From inside the VM:

$ curl -4 localhost:4000
curl: (7) Failed to connect to localhost port 4000: Connection refused

$ curl -6 localhost:4000
<HTML response>

Most Liked

jarmo

jarmo

Managed to solve it. I’m in the process of migrating from Ubuntu Linux to FreeBSD and for some reason on Ubuntu Linux Phoenix did bind to the IPv4, but using the same code and configuration on FreeBSD did bind only on IPv6.

I tried all tricks on changing config/config.exs, config/prod.exs and config/prod.secret.exs, but it turned out that the problem was in the lib/my_app_web/endpoint.ex where in init function had the following line:

{:ok, Keyword.put(config, :http, [:inet6, port: port])}

Changing it to:

{:ok, Keyword.put(config, :http, [:inet, port: port])}

I’m pretty sure that this line has been on inet6 for the entire time of the project and it was generated by phx.new at the time of project creation. Just bear in mind that this is a legacy Phoenix application running version 1.5.1 and might not have the same generated file when creating a new Phoenix application today.

bortzmeyer

bortzmeyer

On Linux, by default, an “inet6” socket also accepts IPv4 (you can disable that with the sysctl option net.ipv6.bindv6only or by adding {ipv6_v6only: true} to your socket options). On FreeBSD, it is not the case by default. You can enable a similar behaviour by adding ipv6_ipv4mapping=YES in /etc/rc.conf. See rc.conf(5)

Last Post!

jarmo

jarmo

This problem even persists on FreeBSD 14 when applying the changes in endpoint.ex as described above by me?

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement