玖叶教程网

前端编程开发入门

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

最近遇到这样一个问题,客户端发起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

发表评论:

控制面板
您好,欢迎到访网站!
  查看权限
网站分类
最新留言