[英]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.