2
votes

I just bought an Amazon ec2 instance and installed erlang and elixir and PostgreSQL. Just put a basic Phoenix app.

When I run mix phx. Server It is starting in local host http://localhost:4000/

But I want to run that in Amazon public IP.

So I put that in config/dev.exs

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

After this i have created a security group and allowed all traffic.

Now when i start the app using 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}

When i put the public IP in browser also it is not working. Do i need to install apache or anyother webserver. Or Do i need to bind the amazon public IP anywhere in system?

Any insight on how to fix the issue will be greatly appreciated Thanks

1

1 Answers

2
votes

Your best bet at this point is to start isolating what is failing. Once you can identify components that should be working and aren't, you'll be able to make your question more focused. Some troubleshooting ideas to get you started:

  1. can you ping the ec2 public address from your machine?
  2. does it have that address (ip address show from the ec2 terminal)?
  3. can the ec2 machine ping out to an external ip, like google's dns (ping 8.8.8.8)?
  4. use netcat to see if the port is truly open: sudo nc -l 80 (on the ec2 host) and nc <ec2-ip> 80 on your machine. Then you should be able to type in your machine (make sure you hit enter after some characters) and see it appear on the ec2 host.
  5. remove the address from your cowboy config, and let it bind to 0.0.0.0 (the default), then see if you can reach it.