【问题标题】:node.js app behind nginx can the node app figure out if the connection is http or httpsnginx后面的node.js应用程序可以让节点应用程序确定连接是http还是https
【发布时间】:2014-09-26 05:13:09
【问题描述】:

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

另外,客户端的JS是否可以判断它是在http还是https?

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

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

还有比这更好的方法吗?

【问题讨论】:

    标签: javascript node.js http nginx https


    【解决方案1】:

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

    proxy_set_header X-Forwarded-Proto $scheme;
    

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

    参考资料:

    【讨论】:

      猜你喜欢
      • 2017-05-15
      • 2020-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-24
      • 2011-07-20
      • 2011-10-30
      • 1970-01-01
      相关资源
      最近更新 更多