我正在尝试创建一个在同一端口上具有多个应用程序的 Phoenix 伞形项目。使用我当前的配置,我收到此错误:
⧕ /m/i/d/p/e/portfolio on master * ⟩mix phoenix.server 13m 20s 412ms
==> rumbl
Compiling 17 files (.ex)
Generated rumbl app
[info] Running Rumbl.Endpoint with Cowboy using http://localhost:8080
[error] Failed to start Ranch listener Persona.Endpoint.HTTP in :ranch_tcp:listen([port: 8080]) for reason :eaddrinuse (address already in use)
[info] Application persona exited: Persona.start(:normal, []) returned an error: shutdown: failed to start child: Persona.Endpoint
** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Server
** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, Persona.Endpoint.HTTP}
** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
** (EXIT) {:listen_error, Persona.Endpoint.HTTP, :eaddrinuse}
** (Mix) Could not start application persona: Persona.start(:normal, []) returned an error: shutdown: failed to start child: Persona.Endpoint
** (EXIT) shutdown: failed to start child: Phoenix.Endpoint.Server
** (EXIT) shutdown: failed to start child: {:ranch_listener_sup, Persona.Endpoint.HTTP}
** (EXIT) shutdown: failed to start child: :ranch_acceptors_sup
** (EXIT) {:listen_error, Persona.Endpoint.HTTP, :eaddrinuse}
我的伞形项目的详细信息是我目前有 3 个应用程序。 1 个应用程序代理对其他 2 个应用程序的请求。代理应用程序是一个基本的即插即用应用程序。
# /apps/proxy/lib/proxy/plug.ex
...
def call(conn, _opts) do
cond do
conn.host =~ ~r{rumbl.} ->
Rumbl.Endpoint.call(conn, [])
true ->
Persona.Endpoint.call(conn, [])
end
end
...
角色应用
# /apps/persona/config/dev.exs
...
config :persona, Persona.Endpoint,
http: [port: 8080],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
cd: Path.expand("../", __DIR__)]]
。
Rumbl.app
# /apps/rumbl/config/dev.exs
config :rumbl, Rumbl.Endpoint,
http: [port: 8080],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [node: ["node_modules/brunch/bin/brunch", "watch", "--stdin",
cd: Path.expand("../", __DIR__)]]
我的要求是因为我使用 nanabox.io 进行开发和部署,它要求在端口 8080 上接收所有 http/https。
如果您的代理终端节点仍然收到所有流量,请将其他 2 个端口的端口设置为随机值,以便端口不会发生冲突。