nginx load forwarding source request http/https:X-Forwarded-Proto and forwarding header in nginx

Today, when troubleshooting server problems, we finally located the server because it has been processed at the operation and maintenance level. Regardless of whether the user requested https or http, our proxy server received http on port 80 regardless of whether the forwarded request was https or http. So I contacted the relevant department to find out if there is such a field available to obtain this value. The company also uses a standard header, X-Forwarded-Proto.

    The X-Forwarded-Proto (XFP) header is a standard header used to identify the protocol HTTP or HTTPS, that is, the user client actually connects to the proxy or load balancer. Servers on the backend can use the X-Forwarded-Proto request header if they want to determine the protocol used between the client and the load balancer. nginx supports reading non-nginx standard user-defined headers, but you need to use underscores_in_headers under http or server to enable underscore support for headers, and then use proxy_set_header to send the field X-Forwarded-Proto to the back-end server.

#proxy_set_header上下文:http, server, location。语法:
proxy_set_header field value;
#默认值:	
proxy_set_header Host $proxy_host;
proxy_set_header Connection close;

#开启header的下划线支持:
underscores_in_headers on;
#设置向后端proxy发送X-Forwarded-Proto字段
proxy_set_header  X-Forwarded-Proto  $http_X_Forwarded_Proto;
proxy_set_header  X-Real-IP  $remote_addr;

    In the back-end server, use $http_X_Forwarded_Proto to receive it. You can also use lowercase letters such as $http_x_forwarded_proto to receive it. You need to add http_ in front of it.

Guess you like

Origin blog.csdn.net/meimeieee/article/details/128837865