如何让凤凰听IPv6?

时间:2016-09-21 02:08:27

标签: ipv6 phoenix-framework cowboy

我很难找到有关让凤凰城(以及牛仔和牧场)收听IPv4和IPv6的信息。

我正在使用Ubuntu 16.04运行VPS。它具有IPv4和IPv6地址。 运行printf时,它显示static void Main(string[] args) { Console.WriteLine( "Please enter the number of numbers you would like to find the average for, or add together: "); int numofnum = int.Parse(Console.ReadLine()); int[] numbers = new int[numofnum]; Console.WriteLine("Would you like to find the average or sum of these numbers? (average/sum)"); var avsu = Console.ReadLine(); var sum = 0; if (avsu != "average" && avsu != "sum") { return; } for (var i = 0; i < numofnum; i++) { Console.Write("Please enter Number " + i + " to add: "); numbers[i] = int.Parse(Console.ReadLine()); } for (var i = 0; i < numofnum; i++) { Console.WriteLine("You entered the following values: "); Console.WriteLine("Number " + i + ": " + numbers[i]); } if (avsu == "sum") { sum = numbers.Sum(); Console.WriteLine("The sim of these numbers is: " + sum); } if (avsu == "average") { var average = sum / numbers.Length; Console.WriteLine("The average of these numbers is: " + average); } } 仅侦听IPv4,并在Phoenix config中指定端口。 而其他流程(如netstat -tulpn)能够同时监听IPv4和IPv6。

我已尝试在beam中指定epmd之类的端口,但由于无法解析为整数而导致崩溃。

有人能指出我正确的方向吗?我是否需要以某种方式添加自定义牛仔听众?

我宁愿不必在前面运行Nginx来收听IPv6流量。

Config我试过了:

"::4000"

堆栈跟踪(看起来像Phoenix只需要一个整数端口):

config.exs

这也是凤凰config :my_app, MyApp.Endpoint, http: [port: "[::]:4000"] 和牛仔** (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

2 个答案:

答案 0 :(得分:5)

config :my_app, MyApp.Endpoint,
  http: [port: 4000, ip: {0, 0, 0, 0, 0, 0, 0, 0}]

这告诉Phoenix要监听所有IPv6地址。它还会监听IPv4。

我原本以为这只是IPv6,因为netstat -tulpn只显示beamtcp6而不是tcp。但经过测试,很明显它也在将IPv4视为&#34; IPv4映射的IPv6地址。&#34;

IP元组格式是Erlang类型inet:ip6_address()

答案 1 :(得分:4)

根据https://hexdocs.pm/phoenix/endpoint.html,您也可以仅使用:inet6。这对我有用:

config :my_app, MyApp.Endpoint,
  http: [:inet6, port: 4000],