簡體   English   中英

Heroku-Web 進程未能在啟動后 90 秒內綁定到 $PORT。 TooTallNate Websockets

[英]Heroku- Web process failed to bind to $PORT within 90 seconds of launch. TooTallNate Websockets

我正在使用一個 tootallnate websockets 服務器來監聽來自網站的連接。

如何在 heroku 上連接到我的服務器?

當我的網站嘗試連接時

wss://Heroku-Name-39329.herokuapp.com/

wss://Heroku-Name-39329.herokuapp.com:5000/

我的 heroku 日志輸出。

at=error code=H10 desc="App crashed" method=GET path="/" host=wss://Heroku-Name-39329.herokuapp.com request_id=4afca002-2078-439c-85dc-ad6ef7db50d2 fwd="207.244.77.23" dyno= connect= service= status=503 bytes=

然后(仍然是 Heroku 日志)

Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 90 seconds of launch
Stopping process with SIGKILL
Process exited with status 137
State changed from starting to crashed
State changed from crashed to starting
Starting process with command `java $JAVA_OPTS -cp target/classes/:target/dependency/* v1.a1.server

我的 javascript 日志

WebSocket connection to 'wss://Heroku-Name-39329.herokuapp.com/:5000/' failed: Establishing a tunnel via proxy server failed.

我在服務器中設置的應用程序是。

String host = "";
int port = 5000;

我的檔案

web: java $JAVA_OPTS -cp target/classes/:target/dependency/* v1.a1.server

Heroku 希望您使用某個端口。

將此添加到您的 Procfile 以獲取該端口:

-Dserver.port=$PORT

所以你的看起來像這樣:Procfile

web: java $JAVA_OPTS -Dserver.port=$PORT -cp target/classes/:target/dependency

嘗試使用這個:

String host = "0.0.0.0";
int port = System.getenv("PORT");

在 Heroku 上,您必須綁定到0.0.0.0並使用分配給您的應用程序的端口,該$PORT包含在$PORT環境變量中。

從客戶端,您不需要指定端口,因此只應使用wss://Heroku-Name-39329.herokuapp.com/ (而不是帶有 5000 的端口)。

Heroku 有自己的端口號 env 變量。 在 server.js 文件中使用它。

// included process.env PORT variable for herokus specific port needed to deploy
const PORT = process.env.PORT || 8000;

所以如果不使用 PORT,它將使用 8000。heroku 將使用 PORT 變量。 完整文件示例:

const express = require('express');
const app = express();
const router = express.Router();

app.use(express.static('public'));
router.get('*',function(req, res) {
  res.sendFile(path.join(__dirname, './public/index'));
});

included process.env PORT variable for herokus specific port needed to deploy
    const PORT = process.env.PORT || 8000;
    app.listen(PORT, function(err) {
      if (err) {
        console.log(err);
        return;
      }
      console.log('listening on port 8000');
    });

application.properties添加:

server.port=${PORT:8080}

然后進入Procfile:

web: java $JAVA_OPTS -jar target/MyApp-0.0.1-SNAPSHOT.jar -Dserver.port=$PORT $JAR_OPTS

這應該夠了。

我可能遲到了,但這幫助我解決了這個問題,更改了 application-prod.yml 和 bootstrap-prod.yml 以反映 heroku 注冊表位置,並將 -Dserver.port=$PORT 添加到 $ 之后的 Proc 文件中JAVA_OPTS ,然后重新啟動! :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM