编程技术分享平台

网站首页 > 技术教程 正文

nginx+springboot使用https重定向的解决办法

xnh888 2024-09-09 09:46:44 技术教程 45 ℃ 0 评论

最近遇到这样一个问题,客户端发起https请求,nginx收到请求后通过http转发给springboot应用程序,当应用程序重定向时就会出现问题,返回的url变成http了,如图


解决方法如下

1、反向代理配置X-Forwarded-Proto头

proxy_pass http://127.0.0.1:9099/;
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-Proto $scheme;

2、修改springboot配置文件,将use-forward-headers设置为true

server:
  port: 9099
  use-forward-headers: true

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表