Ssl 在heroku上使用https
我正试图让我在heroku上的应用程序成为“https everywhere”。到目前为止,该应用程序如下所示:Ssl 在heroku上使用https,ssl,heroku,Ssl,Heroku,我正试图让我在heroku上的应用程序成为“https everywhere”。到目前为止,该应用程序如下所示: "use strict"; console.log('working'); //Initial setup var path, https, privateKey, certificate, port, cdjshelp, util, cookies, oauth, twitter, crypto, _, options, express, auth, lodash, dust,
"use strict";
console.log('working');
//Initial setup
var path, https, privateKey, certificate, port, cdjshelp, util, cookies, oauth, twitter, crypto, _, options, express, auth, lodash, dust, dustjs,
dustjsHelpers, commonDustjsHelpers, app, db, fs, mongoose, mongooseTimes, Comment, Bird, Sighting, Site, User,
Backbone, io;
//node modules, express and dust declarations
path = require('path');
util = require('util');
fs = require('fs');
https = require('https');
privateKey = fs.readFileSync('./config/privatekey.pem').toString();
certificate = fs.readFileSync('./config/certificate.pem').toString();
crypto = require('crypto');
//APP Defn...
app = require('./config/appSetup')(dustjs);
//******** SERVER CONFIG **********//
var port = process.env['PORT'] = process.env.PORT || 4000; // Used by https on localhost
options = {
key: privateKey,
cert: certificate
}
https.createServer(options, app).listen(port, function() {
console.log("Express server listening with https on port %d in %s mode", this.address().port, app.settings.env);
});
我使用openSSL CLI生成了privatekey.pem和certificate.pem,并将它们作为选项加载
我知道heroku有一个程序,如果你使用DNS记录让应用程序服务于你自己的域。我知道你必须完成上面列出的程序。我没有重新映射任何url或更改任何记录-我的url是birdsapp.heroku.com
Heroku使用背驮式SSL,因此,如果您设置http服务器,您的应用程序将响应https请求,而无需任何其他配置。问题是http路由仍然可用,所以我坚持只设置https服务器-但是它超时了,日志中没有任何内容,所以我认为SSL设置有问题
上述设置是否正确?这是在heroku上执行基本https服务器的最佳方法吗?好的,实际上比这简单得多 您只需创建一个http服务器:
//******** SERVER CONFIG **********//
var port = process.env['PORT'] = process.env.PORT || 4000;
http.createServer(app).listen(port, function() {
console.log("Express server listening with http on port %d in %s mode", this.address().port, app.settings.env);
});
并添加路由重定向:
app.all('*', function(req, res, next) {
if (req.headers['x-forwarded-proto'] != 'https')
res.redirect('https://' + req.headers.host + req.url)
else
next() /* Continue to other routes if we're not redirecting */
});
heroku负责其余的工作,设置一个http服务器,它是http服务器的镜像,并使用它们的证书等。是EFF的一个工具。它确保在浏览器中使用HTTP上的HTTPS(SAN和一些断开的站点)。我不相信它使用公钥/私钥对。我没有读Heroku,但看起来您正在构建代理服务器。