简体   繁体   中英

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

I have a node.js app running on a server behind a nginx reverse proxy. Nginx is setup to handle both HTTP and HTTPS and forward both to the same node.js app. Is it possible for the node.js app to figure out if the request came from http or https?

Also, is it possible for the JS on the client side to figure out if its on http or https?

EDIT: found one solution for client side:

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

is there a better way than this?

Just add custom header from nginx to node Usually it's

proxy_set_header X-Forwarded-Proto $scheme;

and in node it will appear in request.headers['x-forwarded-proto'] .

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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