关于用nginx代理安装ssl SERVER变量没有X-Forwarded-Proto

发布时间 2023-12-05 12:14:55作者: 闲时一点

用nginx代理ssl ,但是仍旧走http,所以一般SERVER变量中的相关http协议的都还是https,所以需要

X-Forwarded-Proto(转发协议),可以判断是否https。但如果没有该变量需要自己加在请求头中

在nginx的配置加上如下图的:

proxy_set_header X-Forwarded-Proto  $scheme;
location / {
		#naxsi
		include naxsi.rules;
		#naxsi_white
		include naxsi_white.rules;
		proxy_set_header Accept-Encoding '';
		proxy_redirect off;
		proxy_set_header X-Real-IP $remote_addr;
		proxy_set_header X-Forwarded-Proto  $scheme;
		proxy_set_header Host $host;
		proxy_http_version 1.1;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
		proxy_set_header From-Https on;
		proxy_pass http://127.0.0.1:80;
    }