Heroku 上的 HTTPS Node.js 应用程序 [英] HTTPS Node.js application on Heroku

查看:25
本文介绍了Heroku 上的 HTTPS Node.js 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经配置了我的 SSL 端点,我可以确认它正在工作.当我进入我的日志时,我看到以下内容:

I have configured my SSL enpoint, and I can confirm that that is working. When I go into my log, I see the following:

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 的一些信息,以及为什么所有进程都被停止.查看以下服务器文件:

I tried to track down some information on exit code 143, and why all processes are being stopped. Check out the following server file:

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'));
});

提前感谢您的反馈.如果需要,我可以提供更多详细信息.

Thanks for your feedback in advance. I can provide more details if needed.

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

请看下面我的回答.

推荐答案

我在这里找到了答案:ExpressJS 节点 HTTPS 服务器上的 Heroku 错误 H13

SSL 终止发生在 Heroku 的负载均衡器上;它们向您的应用发送纯(非 SSL)流量,因此您的应用应创建非 HTTPS 服务器."

"SSL termination occurs at Heroku's load balancers; they send your app plain (non-SSL) traffic, so your app should create a non-HTTPS server."

然后我将文件更改为:

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 一切正常.祝你好运!

Everything is working great now over https. Good Luck!

这篇关于Heroku 上的 HTTPS Node.js 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆