凤凰伞应用程序与同一端口上的子域

时间:2017-08-01 07:35:59

标签: elixir web-deployment phoenix-framework continuous-deployment nanoboxio

我正在尝试在同一个端口上创建一个包含多个应用程序的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进行开发和部署,并且需要所有http/https be received on port 8080

1 个答案:

答案 0 :(得分:1)

如果您的代理端点仍然收到所有流量,请将其他2的端口设置为随机的端口,以便端口不会发生冲突。