首页 文章

Amazon Ec2实例公共IP不适用于Phoenix Elixir APP错误:原因:eaddrnotavail(无法分配请求的地址)

提问于
浏览
2

我刚买了一个亚马逊ec2实例并安装了erlang和elixir以及PostgreSQL . 只需要一个基本的凤凰应用

当我运行混合phx . 服务器它从本地主机开始http://localhost:4000/

但我想在亚马逊公共IP中运行它 .

So I put that in config/dev.exs

    Http: [ip:{1, 2, 3, 4}, port:4000}

在此之后,我创建了一个安全组并允许所有流量 .

现在,当我使用sudo mix phx.server启动应用程序时

I am getting the below error

Compiling 10 files (.ex)
Generated myapp_test app
[error] Failed to start Ranch listener myappTestWeb.Endpoint.HTTP in :ranch_tcp:listen([port: 4000, ip: {1, 2, 3, 4}]) for reason :eaddrnotavail (can't assign requested address)

[info] Application myapp_test exited: myappTest.Application.start(:normal, []) returned an error: shutdown: failed to start child: myappTestWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
        ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, myappTestWeb.Endpoint.HTTP}
            ** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
                ** (EXIT) {:listen_error, myappTestWeb.Endpoint.HTTP, :eaddrnotavail}
[info] Application phoenix_ecto exited: :stopped
[info] Application ecto exited: :stopped
[info] Application poolboy exited: :stopped
[info] Application postgrex exited: :stopped
[info] Application decimal exited: :stopped
[info] Application db_connection exited: :stopped
[info] Application connection exited: :stopped
[info] Application cowboy exited: :stopped
[info] Application cowlib exited: :stopped
[info] Application ranch exited: :stopped
[info] Application runtime_tools exited: :stopped

=INFO REPORT==== 23-Jan-2018::10:48:23 ===
    application: logger
    exited: stopped
    type: temporary
** (Mix) Could not start application myapp_test: myappTest.Application.start(:normal, []) returned an error: shutdown: failed to start child: myappTestWeb.Endpoint
    ** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
        ** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, myappTestWeb.Endpoint.HTTP}
            ** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
                ** (EXIT) {:listen_error, myappTestWeb.Endpoint.HTTP, :eaddrnotavail}

当我将公共IP放入浏览器时,它也无法正常工作 . 我是否需要安装apache或任何其他网络服务器 . 或者我是否需要在系统中的任何地方绑定amazon公共IP?

任何有关如何解决问题的见解将不胜感激谢谢

1 回答

  • 2

    在这一点上你最好的选择是开始隔离失败的东西 . 一旦你能够识别出应该工作但不能工作的组件,你就能够使你的问题更加集中 . 一些故障排除想法可以帮助您入门:

    • 你可以从机器上ping ec2公共地址吗?

    • 它有那个地址(来自ec2终端的 ip address show )?

    • ec2机器可以ping到外部ip,比如google的dns( ping 8.8.8.8 )吗?

    • 使用netcat查看端口是否真正打开: sudo nc -l 80 (在ec2主机上)和 nc <ec2-ip> 80 在您的机器上 . 然后你应该能够输入你的机器(确保你在一些字符后输入)并看到它出现在ec2主机上 .

    • 从牛仔配置中删除地址,并将其绑定到0.0.0.0(默认值),然后查看是否可以访问它 .

相关问题