【问题标题】:Spring boot (with security) behind Kong reverse proxy not working correctlyKong反向代理后面的Spring boot(带安全性)无法正常工作
【发布时间】:2017-11-17 22:46:07
【问题描述】:

我有一个通过 Keycloak 安全的 Spring Boot 服务。 该服务工作正常:http://localhost:8080/api/resource(受限制)并且只有在通过 keycloak 进行身份验证后才能访问。

@Override
protected void configure(HttpSecurity http) throws Exception {
    super.configure(http);
    http.authorizeRequests().antMatchers("/open/*").permitAll()
    .anyRequest().authenticated();
}

现在我使用 Kong 作为外部世界的反向代理:该条目是(例如):https://gateway.example.com/customer 重定向到 http://localhost:8080

调用https://gateway.example.com/customer/api/resource 后,出现问题,而不是调用https://gateway.example.com/customer/sso/login 它调用https://gateway.example.com/sso/login,所以我得到“404 Not Found”。

似乎安全部分已删除,或者说忽略该位置的“客户”。

有可能更正位置吗?

谢谢

【问题讨论】:

    标签: java spring-boot spring-security-oauth2 kong


    【解决方案1】:

    如果您正在使用按路径匹配的路由并且您不会将其剥离,则需要将 strip_path 设置为 true

    检查documentation

    【讨论】:

      【解决方案2】:

      我知道这个问题很老了,但刚刚发生了这种情况。在 application.properties 中,尝试使用此设置:

      server.use-forward-headers=true
      

      这将告诉 Spring Boot 转发与代理相关的请求,而不是您的应用。

      【讨论】:

        猜你喜欢
        • 2019-06-13
        • 2023-04-08
        • 1970-01-01
        • 2019-05-31
        • 1970-01-01
        • 2020-09-05
        • 2017-06-09
        • 2021-11-02
        • 2020-02-09
        相关资源
        最近更新 更多