问题设置生产端口号 - (RuntimeError) 期望设置 PORT 环境变量

Issue setting production port number - (RuntimeError) expected the PORT environment variable to be set

我正在使用 edeliver 在 aws 上进行部署。部署 运行 正常,但是当我尝试使用 curl localhost:8888 访问控制台中的站点时,出现 connection refused 错误。

如果我尝试使用 ./rel/bin/app_name console 启动应用程序,我会得到一个 (RuntimeError) expected the PORT environment variable to be set。但是我的 config/prod.exs 看起来像这样。

use Mix.Config

config :elixir_deploy, ElixirDeployWeb.Endpoint,
  load_from_system_env: true,
  http: [port: 8888],
  ssl: false,
  url: [host: "example.com", port: 80],
  cache_static_manifest: "priv/static/cache_manifest.json"

config :logger, level: :info

import_config "prod.secret.exs"

我在这里错过了什么?如果我在手动启动前设置 PORT=8888 它会起作用,但我宁愿使用 edeliver

自动启动

您需要将 load_from_system_env 设置为 false(或者只删除该行)。当它是 true 时,Phoenix 默认生成的 endpoint.ex 将使用 PORT 环境变量的值,如果找不到,则会引发错误。

if config[:load_from_system_env] do
  port = System.get_env("PORT") || raise "expected the PORT environment variable to be set"
  {:ok, Keyword.put(config, :http, [:inet6, port: port])}
else
  {:ok, config}
end

Source