栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Spring Boot 2.2.0中如何处理x-forwarded-header?(反向代理后面的Spring Web MVC)

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Spring Boot 2.2.0中如何处理x-forwarded-header?(反向代理后面的Spring Web MVC)

使用Spring Boot <= 2.1.x,您必须提供

ForwardedHeaderFilter
-Bean。从Spring Boot
2.2.0开始,您不再需要这样做。只需添加
server.forward-headers-strategy=NATIVE
server.forward-headers-strategy=frameWORK
到您的
application.properties
-file。

NATIVE
表示Servlet容器(例如undertow,tomcat)正在解析
x-forwarded-*
-header,在大多数情况下都可以。如果依靠
X-Forwarded-Prefix
比你必须使用
frameWORK
,以便
request.getContextPath()
设置正确。


例:

  1. 用户输入浏览器:
    https://mydomain.tld/my-microservice/actuator
  2. 微服务“我的微服务”(例如用户服务)应处理该请求;它在localhost:8080上运行
  3. 反向代理转发请求是这样的:
// Forwarded-Request from Reverse Proxy to your microserviceGET http://localhost:8080/actuator/X-Forwarded-Host: mydomain.tldX-Forwarded-Proto: httpsX-Forwarded-Prefix: /my-microservice

调试到HttpServletRequest中将导致:

request.getRequestURL(): "https://mydomain.tld/my-microservice/actuator/"request.getScheme(): "https"request.getContextPath(): "/my-microservice"new UrlPathHelper().getPathWithinApplication(request): "/actuator"


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/435473.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号