【问题标题】:Elixir Plug Cowboy not using port 80Elixir Plug Cowboy 不使用端口 80
【发布时间】:2014-09-27 15:04:34
【问题描述】:

我有一个路由器插头

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

但是,当我调用 Rest.start 时,我得到了

{: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]}}}

如果我去掉端口:80,调用Rest.start没有问题,服务器监听4000端口。

我正在使用 Elixir v0.15.0。

【问题讨论】:

  • 端口 80 在大多数系统上需要特殊权限才能绑定到它。与您一起运行此程序的用户是否具有这些权限?尝试在sudo 下运行。
  • {{:badmatch, {:error, :eacces}} 这意味着牛仔/牧场无法绑定到端口并且权限被拒绝。有关 linux 系统错误的更多信息:www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/…

标签: elixir cowboy


【解决方案1】:

端口 80 在大多数系统上需要特殊权限才能绑定到它。与您一起运行此程序的用户是否具有这些权限?尝试在 sudo 下运行。 -Uri Agassi

这就是问题所在。

【讨论】:

  • 很高兴知道它有帮助
猜你喜欢
  • 2019-02-10
  • 2019-11-04
  • 1970-01-01
  • 1970-01-01
  • 2014-04-14
  • 2021-11-15
  • 2017-05-10
  • 1970-01-01
  • 2016-04-20
相关资源
最近更新 更多