Running on ec2 giving error

[error] Failed to start Ranch listener MyAppWeb.Endpoint.HTTP in :ranch_tcp:listen([:inet6, {:port, 80}]) for reason :eacces (permission denied)

[info] Application MyApp exited: MyApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: MyAppWeb.Endpoint
** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, MyAppWeb.Endpoint.HTTP}
** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
** (EXIT) {:listen_error, MyAppWeb.Endpoint.HTTP, :eacces}
** (Mix) Could not start application MyApp: MyApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: MyAppWeb.Endpoint
** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Handler
** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, MyAppWeb.Endpoint.HTTP}
** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
** (EXIT) {:listen_error, MyAppWeb.Endpoint.HTTP, :eacces}MyApp

my endpoint settings
load_from_system_env: true,
http: [port: {:system, β€œPORT”}],
url: [host: β€œxxxxx.eu-west-2.compute.amazonaws.com”, port: 80],
server: true,
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [ ]

iex giving this error when listening to tcp
iex(1)> :gen_tcp.listen(443, [])
{:error, :eacces}
iex(2)> :gen_tcp.listen(80, [])
{:error, :eacces}

Os ubuntu 16
please help

1 Like

I think it’s just because a non-root running process is not allowed to use ports below 1024. I guess an easy solution to implement is just to use nginx to listen on 80 & 443 then forward requests to your app (changing the app to listen on whatever others ports above 1024), another solution is to run the beam process as root, or if using systemd create a socket handler

1 Like

I would heavily suggest against letting your application run as root. That is just asking for trouble. Setting up something like NGINX or HAProxy to listen on port 80 and redirect to some other port would be the better decision.

4 Likes

[info] Running MyAppWeb.Endpoint with Cowboy using http://:::4000

on 4000 its not working with
url: [host: β€œxxxxx.eu-west-2.compute.amazonaws.com”, port: 4000],

its working on my other ubuntu server but not working on aws

The url is used for creating static assets urls, is not related to starting the cowboy server. Have you checked your endpoint.ex init?

You probably still need to open port 4000 within your AWS security groups.

The port for cowboy to bind to is specified in :http or :https config options, not :url.

thank you i reliazed that was my mistake its working fine now

thank you fixed.