Spring OAuth2认证https重定向问题


关于Nginx配置SSL后,代理配置后端服务,SpringBoot通过通过request.getScheme()获取到http而不是https的问题

解决方式如下:

  1. 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;
  1. 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`

huang.xinghui

Programmer

huang-x-h huangxinghui


Published