Heroku Go 应用崩溃

标签 heroku go http-status-code-503

正在关注 this tutorial ,一切都在本地工作。在我将我的应用程序部署到 Heroku 并在浏览器上访问该应用程序后,我收到了一个503 错误和消息:

Application Error An error occurred in the application and your page could not be served. Please try again in a few moments. If you are the application owner, check your logs for details.

日志说:

2015-09-08T16:31:53.976824+00:00 heroku[web.1]: State changed from crashed to starting
2015-09-08T16:31:56.174376+00:00 heroku[web.1]: Starting process with command `mywebsite`
2015-09-08T16:31:59.312461+00:00 app[web.1]: Listening on port: 39461
2015-09-08T16:32:56.471550+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2015-09-08T16:32:56.471550+00:00 heroku[web.1]: Stopping process with SIGKILL
2015-09-08T16:32:57.390752+00:00 heroku[web.1]: Process exited with status 137
2015-09-08T16:32:57.404208+00:00 heroku[web.1]: State changed from starting to crashed
2015-09-08T16:32:57.645135+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=boiling-eyrie-6897.herokuapp.com request_id=ec26... fwd="xx.xxx.xxx.xxx" dyno= connect= service= status=503 bytes=
2015-09-08T16:32:58.233774+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=boiling-eyrie-6897.herokuapp.com request_id=ef40...fwd="xx.xxx.xxx.xxx" dyno= connect= service= status=503 bytes=

我知道错误是什么,但是这么小的教程应用程序怎么会导致启动超时 (R10)?

我怎样才能更好地调试它并修复应用程序使其运行?

最佳答案

当您通过 heroku 部署应用时,它不允许您指定端口号
换句话说,您不能将 Web 服务的端口 号指定为8000 或其他名称,heroku 在运行时决定端口号。
所以,你不能使用下面的代码:

    log.Fatal(http.ListenAndServe(":8000", router))

你可以做的是,获取 heroku 的运行时端口。
简而言之,只需使用以下代码:

    log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), router))

关于Heroku Go 应用崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32463004/

相关文章:

javascript - Socket.io 需要很长时间才能触发断开连接事件

python - 在heroku-18堆栈上部署python 3.6.5 Django应用程序

javascript - Heroku Node 部署 "internal server error"

postgresql - 未应用过滤器(即空的“Where”子句)时,使用Golang网络表单从Postgres获取所有记录

go - 在golang中旋转 slice 的有效方法

rest - 在什么情况下 REST API 应该返回 HTTP Status 503

ruby-on-rails - WebSocket 握手期间出错 : Unexpected response code: 503

go - 如何获取记录器的文件和函数名称

Python请求库异常处理

javascript - 如何在 tampermonkey 中捕获状态 503