【问题标题】:Issue setting production port number - (RuntimeError) expected the PORT environment variable to be set问题设置生产端口号 - (RuntimeError) 需要设置 PORT 环境变量
【发布时间】:2017-11-02 09:05:08
【问题描述】:

我正在使用 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 自动启动

【问题讨论】:

  • 你确定你没有在后面的配置中覆盖http端口配置吗?
  • @Dogbert 是的,其他的只有开头的use Mix.Config,结尾的config :logger, level: :infoimport_config "prod.secret.exs"

标签: elixir phoenix-framework edeliver


【解决方案1】:

您需要将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

【讨论】:

  • 我正忙着让它在下一行工作。看不到树木的福雷斯特。谢谢。
猜你喜欢
  • 1970-01-01
  • 2010-09-29
  • 2019-08-04
  • 1970-01-01
  • 2020-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-07
相关资源
最近更新 更多