我正在努力寻找有关让 Phoenix(以及 Cowboy 和 Ranch)同时监听 IPv4 和 IPv6 的信息。
我在 Ubuntu 16.04 的 VPS 上运行。它同时具有 IPv4 和 IPv6 地址。
跑步时netstat -tulpn
它表明beam
仅侦听 IPv4,并使用 Phoenix 配置中指定的端口。
而其他进程,例如epmd
,能够侦听 IPv4 和 IPv6。
我尝试指定一个端口,例如"::4000"
in my config.exs
,但由于无法解析为整数而崩溃。
有人能指出我正确的方向吗?我是否需要以某种方式添加自定义牛仔侦听器?
我宁愿不必在前面运行 Nginx 来监听 IPv6 流量。
我尝试过的配置:
config :my_app, MyApp.Endpoint,
http: [port: "[::]:4000"]
堆栈跟踪(看起来 Phoenix 仅需要一个整数端口):
** (Mix) Could not start application my_app: MyApp.start(:normal, []) returned an error: shutdown: failed to start child: MyApp.Endpoint
** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Server
** (EXIT) an exception was raised:
** (ArgumentError) argument error
:erlang.binary_to_integer("[::]:4000")
(phoenix) lib/phoenix/endpoint/server.ex:32: Phoenix.Endpoint.Server.to_port/1
(phoenix) lib/phoenix/endpoint/server.ex:28: Phoenix.Endpoint.Server.default/3
(phoenix) lib/phoenix/endpoint/server.ex:17: anonymous fn/5 in Phoenix.Endpoint.Server.init/1
(elixir) lib/enum.ex:1623: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix) lib/phoenix/endpoint/server.ex:15: Phoenix.Endpoint.Server.init/1
(stdlib) supervisor.erl:294: :supervisor.init/1
(stdlib) gen_server.erl:328: :gen_server.init_it/6
(stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
这也是凤凰{:phoenix, "~> 1.2.0"}
和牛仔{:cowboy, "~> 1.0"}