【问题标题】:Phoenix deployment on Heroku failed to bind $PORTHeroku 上的 Phoenix 部署无法绑定 $PORT
【发布时间】:2020-03-05 19:48:59
【问题描述】:

在 heroku 服务器上部署我的应用程序时遇到了很大的问题。我在凤凰网页的教程的帮助下完成了它。但它不起作用。下面你可以看到我使用的日志和配置。

heroku 日志

2016-02-07T04:28:55.623435+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web
process failed to bind to $PORT within 60 seconds of launch
2016-02-07T04:28:55.623435+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-02-07T04:28:56.344649+00:00 heroku[web.1]: State changed from starting to c
rashed
2016-02-07T04:28:56.348324+00:00 heroku[web.1]: Process exited with status 137
2016-02-07T09:54:29.124036+00:00 heroku[web.1]: State changed from crashed to st
arting
2016-02-07T09:54:34.703208+00:00 heroku[web.1]: Starting process with command `m
ix run --no-halt`
2016-02-07T09:55:35.386922+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web
process failed to bind to $PORT within 60 seconds of launch
2016-02-07T09:55:35.386922+00:00 heroku[web.1]: Stopping process with SIGKILL
2016-02-07T09:55:36.330258+00:00 heroku[web.1]: State changed from starting to c
rashed
2016-02-07T09:55:36.323082+00:00 heroku[web.1]: Process exited with status 137
2016-02-07T12:14:35.182306+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/" host=kpsz.herokuapp.com request_id=7de0ee97-14cf-46f9-
a9a3-cbffa09ac379 fwd="83.7.11.212" dyno= connect= service= status=503 bytes=
2016-02-07T12:14:35.850018+00:00 heroku[router]: at=error code=H10 desc="App cra
shed" method=GET path="/favicon.ico" host=kpsz.herokuapp.com request_id=4e9b1979
-deb6-497b-80b2-655615f43d01 fwd="83.7.11.212" dyno= connect= service= status=50
3 bytes=

配置 prod.exs

config :kpsz, Kpsz.Endpoint,
  http: [port: System.get_env("PORT")],
  url: [host: "example.com", port: 80],
  cache_static_manifest: "priv/static/manifest.json",
  secret_key_base: System.get_env("SECRET_KEY_BASE")

config :kpsz, Kpsz.Repo,
  adapter: Ecto.Adapters.Postgres,
  url: System.get_env("DATABASE_URL"),
  pool_size: 20

【问题讨论】:

  • 这也发生在我身上。我想知道这是否是 buildpack 的错误。
  • 重新创建 heroku 应用程序为我修复了它
  • 发生这种情况时您是否更改了 Heroku 上的 MIX_ENV?

标签: heroku elixir phoenix-framework


【解决方案1】:

我不确定这是否是问题,但您可以尝试更换

http: [port: System.get_env("PORT")]

http: [port: {:system, "PORT"}]

至少这是我在我的应用程序中使用的。您还可以阅读文档以获取更多信息http://www.phoenixframework.org/docs/heroku

【讨论】:

    【解决方案2】:

    我遇到了类似的问题。 添加带有一行web: mix phoenix.server 的Procfile 解决了它。

    【讨论】:

      【解决方案3】:

      heroku 销毁项目名称

      heroku 创建

      由于某些奇怪的原因,它现在可以工作了......

      非常感谢您的帮助。

      【讨论】:

        【解决方案4】:

        我遇到了这个问题,对我来说,修复方法如下(复制自 this question 上的答案)。

        修复是双重的:

        1. 使用 phoenix buildpack 配置并导出 PORT,如下所示:config_vars_to_export=(DATABASE_URL PORT)
        2. 避免在不重新编译应用的情况下更改 MIX_ENV,因为该行为不受支持,如此处所述。

        【讨论】:

          【解决方案5】:

          娱乐解决了问题,我怀疑问题出在加载环境变量上。

          有一次我在当地遇到了类似的问题。我的观察

          1. mix phoenix.server(你可能会看到编译过的某某文件的消息)
          2. 停止服务器
          3. 导出/更改 zshrc/bashrc 文件中的 env 变量并获取它
          4. 启动服务器(您可能看不到该编译消息,因为您的代码库中没有更改,因此您的新/编辑的 env 变量不会得到反映)
          5. 如果您只是在该文件中添加一个空格,它将使其编译并获取该环境变量。

          您的问题的原因可能是:在服务器运行/部署后设置环境变量,因为环境变量在编译期间转换为值。

          【讨论】:

            【解决方案6】:

            我在使用 docker 部署凤凰伞项目时遇到了类似的问题。 我已采取以下步骤:
            Heroku https://hexdocs.pm/phoenix/heroku.html#deploying-to-heroku-using-the-container-stack
            Dockerfile https://hexdocs.pm/phoenix/releases.html#containers
            我也看过其他链接,但这两个是最好的。


            该 Dockerfile 的唯一问题是它在不存在的构建步骤中需要 $PORT(和 $SECRET_KEY_BASE)。所以我们必须以某种方式在 prod.exs 中“存根”它。但是我们必须在运行步骤(运行时配置)上提供真正的 $PORT。因此,您必须确保将config/prod.secret.exs 重命名为config/releases.exshttps://hexdocs.pm/phoenix/releases.html#runtime-configuration 的第一步)或创建config/releases.exs,这将重写 $PORT(可能还有其他一些应用程序环境变量 - 例如,$SECRET_KEY_BASE )。

            UPD:正如@Daniel 提到的那样 - releases 是 Elixir 1.9 的一项功能。

            【讨论】:

            • 你应该提到releases是一个新特性,当被问到这个问题时,只有一个hacky解决方法可以在运行时获取环境变量。
            猜你喜欢
            • 2020-06-10
            • 2021-11-01
            • 2020-04-17
            • 2021-11-20
            • 2013-08-23
            • 2020-07-17
            • 1970-01-01
            • 1970-01-01
            • 2021-09-17
            相关资源
            最近更新 更多