[英]Heroku- Web process failed to bind to $PORT within 90 seconds of launch. TooTallNate Websockets
I'm using a tootallnate websockets server listening for connections from a website.我正在使用一个 tootallnate websockets 服务器来监听来自网站的连接。
How do I make a connection to my server on heroku?如何在 heroku 上连接到我的服务器?
When my website tries to connect at当我的网站尝试连接时
wss://Heroku-Name-39329.herokuapp.com/
or或
wss://Heroku-Name-39329.herokuapp.com:5000/
My heroku logs output.我的 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=
And then(Still Heroku Logs)然后(仍然是 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
My javascript logs我的 javascript 日志
WebSocket connection to 'wss://Heroku-Name-39329.herokuapp.com/:5000/' failed: Establishing a tunnel via proxy server failed.
My Apps set within the server are.我在服务器中设置的应用程序是。
String host = "";
int port = 5000;
My Procfile我的档案
web: java $JAVA_OPTS -cp target/classes/:target/dependency/* v1.a1.server
Heroku wants you to use a certain port. Heroku 希望您使用某个端口。
Add this to your Procfile to get that port:将此添加到您的 Procfile 以获取该端口:
-Dserver.port=$PORT
So yours would look like this: Procfile所以你的看起来像这样:Procfile
web: java $JAVA_OPTS -Dserver.port=$PORT -cp target/classes/:target/dependency
Try using this:尝试使用这个:
String host = "0.0.0.0";
int port = System.getenv("PORT");
On Heroku, you must bind to 0.0.0.0
and use the port assigned to your app, which is contained in the $PORT
environment variable.在 Heroku 上,您必须绑定到0.0.0.0
并使用分配给您的应用程序的端口,该$PORT
包含在$PORT
环境变量中。
From the client, you will not need to specify a port, so only wss://Heroku-Name-39329.herokuapp.com/
should be used (not the one with 5000).从客户端,您不需要指定端口,因此只应使用wss://Heroku-Name-39329.herokuapp.com/
(而不是带有 5000 的端口)。
Heroku has its own env variable for its port number. Heroku 有自己的端口号 env 变量。 use this in the server.js file.在 server.js 文件中使用它。
// included process.env PORT variable for herokus specific port needed to deploy
const PORT = process.env.PORT || 8000;
so if not using PORT it will use 8000. heroku will use the PORT variable.所以如果不使用 PORT,它将使用 8000。heroku 将使用 PORT 变量。 full file example:完整文件示例:
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');
});
Into application.properties
add:在application.properties
添加:
server.port=${PORT:8080}
then into Procfile:然后进入Procfile:
web: java $JAVA_OPTS -jar target/MyApp-0.0.1-SNAPSHOT.jar -Dserver.port=$PORT $JAR_OPTS
This should be enought.这应该够了。
I might be late to the party but this helped me solve this problem, change the application-prod.yml and bootstrap-prod.yml to reflect the heroku registry location and add -Dserver.port=$PORT to the Proc file after the $JAVA_OPTS , then relaunch!我可能迟到了,但这帮助我解决了这个问题,更改了 application-prod.yml 和 bootstrap-prod.yml 以反映 heroku 注册表位置,并将 -Dserver.port=$PORT 添加到 $ 之后的 Proc 文件中JAVA_OPTS ,然后重新启动! :) :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.