spring security nginx https proxy 问题

spring boot 应用如果使用了nginx 的proxy 对于spring security 可能会存在退出,重定向到http 跨域的问题(但是我们实际是https)

参考解决方法

  • nginx 配置
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto      $scheme;
  • Spring boot 配置
    application.yaml
server:
  tomcat:
    remoteip:
      protocol-header: X-Forwarded-Proto
      remote-ip-header: X-Forwarded-For

说明

注意spring boot 版本不同版本以上配置可能会不一样,以上在spring boot 2.5.13 测试通过

参考资料

https://tomcat.apache.org/tomcat-8.0-doc/api/org/apache/catalina/valves/RemoteIpValve.html
https://github.com/spring-projects/spring-framework/blob/v4.3.3.RELEASE/spring-web/src/main/java/org/springframework/web/filter/ForwardedHeaderFilter.java
https://docs.spring.io/spring-boot/docs/2.1.x/reference/html/howto-security.html

posted on   荣锋亮  阅读(469)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2021-04-22 cube.js 调度&&查询队参考参数
2021-04-22 cube.js 自定义首页显示信息
2020-04-22 How We Spotted and Fixed a Performance Degradation in Our Python Code
2020-04-22 nodejs 基础镜像的一个参考
2020-04-22 几款不错的基于web 的sql编辑器
2019-04-22 python 集成cython 简单测试
2019-04-22 click python cli 开发包

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示