亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在反向代理后面嵌入 Tomcat 的 Spring Boot 應用程序在請求

在反向代理后面嵌入 Tomcat 的 Spring Boot 應用程序在請求

牧羊人nacy 2022-12-28 16:24:55
這個問題似乎已被多次詢問,但對于這種特殊情況,我還沒有找到合適的解決方案。該應用程序是一個 Spring Boot 1.5.x,它使用嵌入式 Tomcat 服務器并在 Openshift 上運行。后者有一個帶有 HTTPS 路由的路由器,該路由終止 TLS 隧道并通過 HTTP 將流量轉發到應用程序 pod。此外,它還插入 X-Forwarded- 標頭(包括 X-Forwarded-Proto 標頭),以便使用 https 協議組成應用程序重定向。我已經server.use-forward-headers: true在 Spring Boot 應用程序中配置并測試了它:1) OK -> https://ocproute/myapp/將 302 重定向到我的主頁,保持 https 協議(Tomcat RemoteIpValve 處理了它)。2) FAIL -> https://ocproute/myapp(注意沒有尾部斜杠)將 302 重定向到http://ocproute/myapp/如您所見,由于尚未調用 RemoteIpValve,它已將協議更改為 http) .日志顯示 Tomcat 的 Http11InputBuffer 收到請求并在某個時候重定向它而不考慮 X-Forwarded-Proto 標頭。這怎么能解決?
查看完整描述

2 回答

?
阿波羅的戰車

TA貢獻1862條經驗 獲得超6個贊

你可以在你的 springboot 配置中設置這個道具:

server.tomcat.use-relative-redirects=true

參考:https ://github.com/spring-projects/spring-boot/issues/22908


查看完整回答
反對 回復 2022-12-28
?
守候你守候我

TA貢獻1802條經驗 獲得超10個贊

為了完成這項工作,我必須禁用自定義 Tomcat 上下文的上下文根重定向:


@Configuration

class TomcatConfiguration : EmbeddedServletContainerCustomizer {


    override fun customize(container: ConfigurableEmbeddedServletContainer) {

        val factory = container as TomcatEmbeddedServletContainerFactory

        factory.tomcatContextCustomizers = listOf(CustomCustomizer())


    }


    class CustomCustomizer : TomcatContextCustomizer {

        override fun customize(context: Context) {

            context.mapperContextRootRedirectEnabled = false

            context.addServletContainerInitializer(WsSci(), null)

        }

    }


}


查看完整回答
反對 回復 2022-12-28
  • 2 回答
  • 0 關注
  • 154 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號