Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plug.Adapters.Cowboy.http not accepting port: anything not 4000 #76

Closed
mkolosick opened this issue Aug 5, 2014 · 1 comment
Closed

Comments

@mkolosick
Copy link

I have a Router plug

defmodule Rest do
  use Plug.Router
  import Plug.Conn

  plug :match
  plug :dispatch

  get "/hello" do
    send_resp(conn, 200, "Hello, world!")
  end

  match _ do
    send_resp(conn, 404, "oops")
  end

  def start do
    Plug.Adapters.Cowboy.http Rest, [], port: 80
  end

  def stop do
    Plug.Adapters.Cowboy.shutdown Rest.HTTP
  end
end

However, when calling Rest.start I get

{:error,
 {{:shutdown,
   {:failed_to_start_child, :ranch_acceptors_sup,
    {{:badmatch, {:error, :eacces}},
     [{:ranch_acceptors_sup, :init, 1,
       [file: 'src/ranch_acceptors_sup.erl', line: 30]},
      {:supervisor, :init, 1, [file: 'supervisor.erl', line: 243]},
      {:gen_server, :init_it, 6, [file: 'gen_server.erl', line: 306]},
      {:proc_lib, :init_p_do_apply, 3, [file: 'proc_lib.erl', line: 239]}]}}},
  {:child, :undefined, {:ranch_listener_sup, Rest.HTTP},
   {:ranch_listener_sup, :start_link,
    [Rest.HTTP, 100, :ranch_tcp, [port: 200], :cowboy_protocol,
     [env: [dispatch: [{:_, [],
         [{:_, [], Plug.Adapters.Cowboy.Handler, {Rest, []}}]}]],
      compress: false]]}, :permanent, :infinity, :supervisor,
   [:ranch_listener_sup]}}}

If I remove the port: 80, there is no problem calling Rest.start, and the server listens on port 4000.

I am using Elixir v0.15.0.

@Psli
Copy link

Psli commented Aug 5, 2014

You can't bind to port below 1024 as a normal user.
Try start your process as root user using:
sudo mix run --no-halt yourfile.exs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants