繁体   English   中英

nginx后面的node.js应用程序可以使该节点应用程序确定连接是http还是https

[英]node.js app behind nginx can the node app figure out if the connection is http or https

我有一个在nginx反向代理后面的服务器上运行的node.js应用程序。 Nginx已设置为同时处理HTTP和HTTPS并将它们转发到同一node.js应用程序。 node.js应用程序能否确定请求是否来自http或https?

另外,客户端的JS是否可以找出它是在http还是https上?

编辑:为客户端找到一种解决方案:

if (window.location.protocol != "https:")

有没有比这更好的方法了?

只需将自定义标头从nginx添加到节点,通常是

proxy_set_header X-Forwarded-Proto $scheme;

在节点中,它将出现在request.headers['x-forwarded-proto']

参考文献:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM