按照本教程,一切都在本地進行。將我的應用程序部署到 Heroku 并在瀏覽器上訪問該應用程序后,我收到503 錯誤和消息:應用程序錯誤 應用程序發生錯誤,無法提供您的頁面。請稍后重試。如果您是應用程序所有者,請檢查您的日志以了解詳細信息。日志說:2015-09-08T16:31:53.976824+00:00 heroku[web.1]: State changed from crashed to starting2015-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: 394612015-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 launch2015-09-08T16:32:56.471550+00:00 heroku[web.1]: Stopping process with SIGKILL2015-09-08T16:32:57.390752+00:00 heroku[web.1]: Process exited with status 1372015-09-08T16:32:57.404208+00:00 heroku[web.1]: State changed from starting to crashed2015-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)?如何更好地調試并修復應用程序以使其運行?
2 回答

梵蒂岡之花
TA貢獻1900條經驗 獲得超5個贊
當您通過heroku部署應用程序時,它不允許您指定端口號。
換句話說,您不能將 Web 服務的端口號指定為8000或其他,heroku 在運行時決定端口號。
因此,您不能使用以下代碼:
log.Fatal(http.ListenAndServe(":8000", router))
您可以做的是獲取heroku 的運行時端口。
簡而言之,只需使用以下代碼:
log.Fatal(http.ListenAndServe(":" + os.Getenv("PORT"), router))

偶然的你
TA貢獻1841條經驗 獲得超3個贊
您的應用程序需要偵聽所有網絡連接。如果它只偵聽本地主機,heroku 的進程觀察器將無法檢測到您綁定了端口,也無法向您的應用程序發送請求。
這意味著而不是:
http.ListenAndServe("127.0.0.1:"+port, nil)
您需要致電:
http.ListenAndServe(":"+port, nil)
另請參閱 Heroku 開始使用 Go 應用程序:https : //github.com/heroku/go-getting-started/blob/master/cmd/go-getting-started/main.go#L27
- 2 回答
- 0 關注
- 209 瀏覽
添加回答
舉報
0/150
提交
取消