Express无法绑定到Heroku上的端口443

时间:2015-02-01 07:24:43

标签: node.js heroku express

我们今晚推出了针对我们的Node应用程序的重大更新,无法将我们的Express应用程序绑定到443用于我们的SSL端点...

var httpsOptions = {
    key: fs.readFileSync( __dirname + '/certs/' + config.ssl.key),
    cert: fs.readFileSync( __dirname + '/certs/' + config.ssl.crt)
};
httpsServer = https.Server(httpsOptions, app);
httpsServer.listen(config.httpsPort, function(){
console.info("HTTPS listening on port " + config.httpsPort);
});

(config.httpsPort = 443)

2015-02-01T07:13:27.151996+00:00 app[web.1]: Bugsnag: Error: listen EACCES
2015-02-01T07:13:27.152004+00:00 app[web.1]: at errnoException (net.js:905:11)
2015-02-01T07:13:27.152005+00:00 app[web.1]: at Server.listen2 (net.js:1024:19)
2015-02-01T07:13:27.152007+00:00 app[web.1]: at Server._listen2 (/app/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/index.js:71:23)
2015-02-01T07:13:27.152008+00:00 app[web.1]: at listen (net.js:1065:10)
2015-02-01T07:13:27.152010+00:00 app[web.1]: at Server.listen (net.js:1139:5)
2015-02-01T07:13:27.152012+00:00 app[web.1]: at Server. (/app/server.js:110:25)
2015-02-01T07:13:27.152015+00:00 app[web.1]: at Server.g (events.js:180:16)
2015-02-01T07:13:27.152017+00:00 app[web.1]: at Server.emit (events.js:92:17)
2015-02-01T07:13:27.152019+00:00 app[web.1]: at net.js:1056:10
2015-02-01T07:13:27.152021+00:00 app[web.1]: at /app/nodemodules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31
2015-02-01T07:13:27.152023+00:00 app[web.1]: at /app/node_modules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/glue.js:188:31
2015-02-01T07:13:27.152026+00:00 app[web.1]: at process.tickDomainCallback (node.js:486:13)
2015-02-01T07:13:27.152027+00:00 app[web.1]: at process. (/app/nodemodules/newrelic/node_modules/continuation-local-storage/node_modules/async-listener/index.js:18:15)

此代码与早期版本几乎完全相同,早期版本运行正常。

2 个答案:

答案 0 :(得分:2)

1024以下的所有端口都是特权 - 只有root用户才能绑定它。

在Heroku web dyno上,你应该只绑定到PORT env var指定的端口,因为Heroku希望在那里找到一个正在运行的应用程序。如果您不这样做,它将在60秒后关闭您的网络动态,并显示R10 Boot Timeout错误消息。

此外,您无法在那里绑定HTTPS,因为Heroku之前运行了一个负载均衡器,并且它终止了SSL / TLS。您的web dyno接收纯HTTP流量。

答案 1 :(得分:0)

虽然我不明白以前的版本是如何在app上使用heroku而且appb上非常相似的代码却没有,但问题是我不明白Heroku路由是如何工作的。即使您有SSL端点,也始终绑定到他们为您提供的端口。