Heroku 上的 Phoenix 部署未能绑定 $PORT
Phoenix deployment on Heroku failed to bind $PORT
我在 heroku 服务器上部署我的应用程序时遇到了很大的问题。我是在 phoenix 网页的教程帮助下完成的。但它不起作用。下面你可以看到我使用的日志和配置。
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
我不确定这是否是问题所在,但您可以尝试更换
http: [port: System.get_env("PORT")]
与
http: [port: {:system, "PORT"}]
至少那是我在我的应用程序中使用的。您还可以阅读文档以获取更多信息 http://www.phoenixframework.org/docs/heroku
heroku destroy 项目名
heroku 创建
出于某种奇怪的原因,它现在可以工作了...
非常感谢您的帮助。
我 运行 解决了这个问题,对我来说,修复如下(从 上的答案复制)。
修复是双重的:
- 使用 phoenix buildpack 配置并导出 PORT,如下所示:config_vars_to_export=(DATABASE_URL PORT)
- 避免在不重新编译应用程序的情况下更改 MIX_ENV,因为该行为不受支持,如此处所述。
我遇到了类似的问题。
添加一个单行的 Procfile web: mix phoenix.server
解决了它。
由于 Recreation 解决了问题,我怀疑问题出在 loading 环境变量上。
有一次我在本地遇到了类似的问题。我的观察
- mix phoenix.server(你可能会看到编译某某文件的消息)
- 已停止服务器
- Export/Change zshrc/bashrc 文件中的 env 变量并获取它
- 启动服务器(您可能看不到该编译消息,因为您的代码库中没有更改,因此您的 new/edited env 变量不会得到反映)
- 如果你只是在该文件中添加一个 space 将使其编译并采用该环境变量。
您的问题的原因可能是: 在服务器 running/deployed 之后设置 env 变量,因为 env 变量在编译期间本身被转换为值。
我在使用 docker 部署 phoenix 伞形项目时遇到了类似的问题。
我已经采取了这些步骤:
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),但不存在。所以我们必须以某种方式 "stub" 它 prod.exs。但是我们必须在 运行 步骤(运行 时间配置)上提供真正的 $PORT。因此,您必须确保将 config/prod.secret.exs
重命名为 config/releases.exs
(https://hexdocs.pm/phoenix/releases.html#runtime-configuration 处的第 1 步)或者只是创建 config/releases.exs
来重写 $PORT(可能还有其他一些应用程序)环境变量 - 例如 $SECRET_KEY_BASE).
UPD:正如@Daniel 提到的 - releases
是 Elixir 1.9 的一个特性。
我在 heroku 服务器上部署我的应用程序时遇到了很大的问题。我是在 phoenix 网页的教程帮助下完成的。但它不起作用。下面你可以看到我使用的日志和配置。
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
我不确定这是否是问题所在,但您可以尝试更换
http: [port: System.get_env("PORT")]
与
http: [port: {:system, "PORT"}]
至少那是我在我的应用程序中使用的。您还可以阅读文档以获取更多信息 http://www.phoenixframework.org/docs/heroku
heroku destroy 项目名
heroku 创建
出于某种奇怪的原因,它现在可以工作了...
非常感谢您的帮助。
我 运行 解决了这个问题,对我来说,修复如下(从
修复是双重的:
- 使用 phoenix buildpack 配置并导出 PORT,如下所示:config_vars_to_export=(DATABASE_URL PORT)
- 避免在不重新编译应用程序的情况下更改 MIX_ENV,因为该行为不受支持,如此处所述。
我遇到了类似的问题。
添加一个单行的 Procfile web: mix phoenix.server
解决了它。
由于 Recreation 解决了问题,我怀疑问题出在 loading 环境变量上。
有一次我在本地遇到了类似的问题。我的观察
- mix phoenix.server(你可能会看到编译某某文件的消息)
- 已停止服务器
- Export/Change zshrc/bashrc 文件中的 env 变量并获取它
- 启动服务器(您可能看不到该编译消息,因为您的代码库中没有更改,因此您的 new/edited env 变量不会得到反映)
- 如果你只是在该文件中添加一个 space 将使其编译并采用该环境变量。
您的问题的原因可能是: 在服务器 running/deployed 之后设置 env 变量,因为 env 变量在编译期间本身被转换为值。
我在使用 docker 部署 phoenix 伞形项目时遇到了类似的问题。
我已经采取了这些步骤:
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),但不存在。所以我们必须以某种方式 "stub" 它 prod.exs。但是我们必须在 运行 步骤(运行 时间配置)上提供真正的 $PORT。因此,您必须确保将 config/prod.secret.exs
重命名为 config/releases.exs
(https://hexdocs.pm/phoenix/releases.html#runtime-configuration 处的第 1 步)或者只是创建 config/releases.exs
来重写 $PORT(可能还有其他一些应用程序)环境变量 - 例如 $SECRET_KEY_BASE).
UPD:正如@Daniel 提到的 - releases
是 Elixir 1.9 的一个特性。