Express.js重定向到HTTPS并发送index.html

Express.js重定向到HTTPS并发送index.html,第1张

Express.js重定向到HTTPS并发送index.html

Heroku在负载均衡器级别终止SSL连接,因此

req.secure
永远不会成立,因为您到heroku的负载均衡器的连接未使用SSL,因此创建了无限重定向循环。

您必须改为检查

X-Forwarded-Proto
标题:

if(req.headers["x-forwarded-proto"] === "https"){  // OK, continue  return next();};res.redirect('https://'+req.hostname+req.url);

编辑:您还可以设置

app.enable("trustproxy")
为自动检查标题。参见http://expressjs.com/guide/behind-
proxies.html



欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/zaji/5642127.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存