Heroku上的HTTPS Node.js应用程序

时间:2013-07-13 15:22:45

标签: node.js heroku

我已经配置了我的SSL enpoint,我可以确认这是有效的。当我进入我的日志时,我看到以下内容:

Jul 13 08:14:10 support-dash app/web.1:  Express server listening on port 17621 
Jul 13 08:14:10 support-dash heroku/web.1:  Stopping all processes with SIGTERM 
Jul 13 08:14:11 support-dash heroku/web.1:  State changed from starting to up 
Jul 13 08:14:13 support-dash heroku/web.1:  Process exited with status 143 
Jul 13 08:15:48 support-dash heroku/router:  at=error code=H12 desc="Request timeout" method=GET path=/ host=app.supportdash.com fwd="68.63.87.85" dyno=web.1 connect=2ms service=30000ms status=503 bytes=0 
Jul 13 08:16:18 support-dash heroku/router:  at=error code=H12 desc="Request timeout" method=GET path=/favicon.ico host=app.supportdash.com fwd="68.63.87.85" dyno=web.1 connect=2ms service=30007ms status=503 bytes=0 

我尝试跟踪退出代码143上的一些信息,以及为什么所有进程都被停止。查看以下服务器文件:

var http = require('http');
var https = require('https');
var fs = require('fs');
var express = require("express");

var app = express();

app.set('port', process.env.PORT || 3000);
app.use(express.logger());

app.get('/', function(request, response) {
  response.send('Hello World 2!');
});

var privateKey = fs.readFileSync(__dirname + '/ssl/server.key').toString();
var certificate = fs.readFileSync(__dirname + '/ssl/gandiSSL.pem').toString();

var options = {
  key: privateKey,
  cert: certificate
};

https.createServer(options, app).listen(process.env.PORT, function () {
  console.log("Express server listening on port " + app.get('port'));
});

感谢您的反馈意见。如果需要,我可以提供更多细节。

------解决方案(编辑)-------

请参阅下面的答案。

1 个答案:

答案 0 :(得分:9)

我在这里找到答案:Heroku Error H13 on ExpressJS Node HTTPS Server

“在Heroku的负载均衡器上发生SSL终止;它们会发送您的应用简单(非SSL)流量,因此您的应用应该创建一个非HTTPS服务器。”

然后我将文件更改为:

var http = require('http');
var express = require("express");

var app = express();

app.set('port', process.env.PORT || 3000);
app.use(express.logger());

app.get('/', function(request, response) {
  console.log('[support dash] processing get request')
  response.send('Hello World 2!');
});

app.listen(process.env.PORT, function () {
  console.log('***** exp listening on port: ' + process.env.PORT);
});

现在通过https,一切都很好。祝你好运!