【发布时间】:2013-02-26 08:29:50
【问题描述】:
根据标题,我有一个 Node.js 应用程序,我希望能够检测请求是通过 HTTPS 还是通过 HTTP 发出的。到目前为止,我的重定向看起来像这样:
// Ensure the page is secure, or that we are running a development build
if (req.headers['x-forwarded-proto'] === 'https' || process.env.NODE_ENV === 'development') {
res.render('index');
} else {
winston.info('Request for login page made over HTTP, redirecting to HTTPS');
res.redirect('https://' + req.host);
}
这在 Nodejitsu 上运行良好,但重定向的 HTTPS 请求没有在 Azure 上设置“x-forwarded-proto”标头。
【问题讨论】:
-
看来我可以使用“x-arr-ssl”标头了。
-
据我了解,标头“x-forwarded-proto”来自一些实际的客户端。虽然重定向一些正在运行的间歇性应用程序,但这些重定向不包括 x-forwarded-proto 标头。我觉得使用其他一些参数来识别协议而不是标头信息会更好。
-
您建议使用什么? Azure 和 Nodejitsu 都使用代理将 HTTPS 流量重定向到 HTTP 服务器。那里没有其他我可以使用的东西吗?
-
您是否检查过代理中是否发生了任何自动重定向?
-
是的,我知道它会重定向。