Spring OAuth2认证https重定向问题
关于Nginx
配置SSL
后,代理配置后端服务,SpringBoot
通过通过request.getScheme()
获取到http
而不是https
的问题
解决方式如下:
Nginx
代理配置增加如下内容
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Scheme $scheme;
proxy_set_header X-Forwarded-Proto $scheme;
SpringBoot
工程里application.properties
增加如下配置
server.tomcat.protocol-header=X-Forwarded-Proto # Header that holds the incoming protocol, usually named "X-Forwarded-Proto".
server.tomcat.protocol-header-https-value=https # Value of the protocol header that indicates that the incoming request uses SSL.
server.tomcat.remote-ip-header=X-Forwarded-For # Name of the http header from which the remote ip is extracted. For instance `X-FORWARDED-FOR`