Node.js   发布时间:2022-04-24  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了node.js – 如何使用node-http-proxy启用HSTS?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
在Node.js 0.8下,我在“路由器表”模式下使用Node-http-proxy,如下所示:

var httpProxy = require("http-proxy");
var config = require("./config");

proxyServer = httpProxy.createServer({
    hostnameOnly: true,router: {
        "one.example.com": "localhost:9000","two.example.com": "localhost:9001"
    },https: {
        key: config.key,cert: config.cert,// mitigate BEAST: https://community.qualys.com/blogs/securitylabs/2011/10/17/mitigaTing-the-beast-attack-on-tls
        honorCipherOrder: true,ciphers: "ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:rC4:HIGH:!MD5:!aNULL:!EDH"
    }
})
proxyServer.listen(8000)

我想添加HSTS(http严格传输安全性),以便让合规浏览器始终使用SSl.为此,我需要使用http-proxy添加标头:

Strict-Transport-Security: max-age=60000

(或其他最大年龄).如何让node-http-proxy有效地附加此标头?

解决方法

对于您的示例,我不确定这个旧问题似乎是使用http-proxy@0.8.但是,这是我用http-proxy@1.0.0做的:

var httpProxy = require('http-proxy');

// https server to decrypt TLS traffic and direct to a normal http BACkend
var proxy = httpProxy.createProxyServer({
  target: {
    host: 'localhost',port: 9009 // or whatever port your local http proxy listens on
  },ssl: {
    key: fs.readFileSync('valid-ssl-key.pem','utf8'),cert: fs.readFileSync('valid-ssl-cert.pem','utf8')
  }
}).listen(443); // httpS listener for the real server

// http server that redirects all requests to their corresponding
// https urls,and allows standards-compliant http clients to 
// prevent future insecure requests.
var server = http.createServer(function(req,res) {
  res.statusCode = 301;
  res.setHeader('LOCATIOn','https://' + req.headers.host.split(':')[0] + req.url);
  res.setHeader('Strict-Transport-Security','max-age=31536000; includeSubDomains');
  return res.end();
});

server.listen(80); // http listener for the old http clients

大佬总结

以上是大佬教程为你收集整理的node.js – 如何使用node-http-proxy启用HSTS?全部内容,希望文章能够帮你解决node.js – 如何使用node-http-proxy启用HSTS?所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。