gpt4 book ai didi

Elixir Plug Cowboy 不使用端口 80

转载 作者:行者123 更新时间:2023-12-04 20:41:45 28 4
gpt4 key购买 nike

我有一个路由器插头

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。

最佳答案

Port 80 needs special permissions on most systems before you can bind to it. Does the user you are running this with have those permissions? Try running under sudo. -Uri Agassi



这就是问题所在。

关于Elixir Plug Cowboy 不使用端口 80,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25130562/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com