首页 > 解决方案 > spring boot 重定向到本地 url

问题描述

我正在使用带有spring-security的spring-boot。

    override fun configure(http: HttpSecurity) {
    http.csrf().disable()
        .authorizeRequests()
            .antMatchers("/login").permitAll()
        .anyRequest().authenticated()
}

我遇到的问题是,当我使用: https://my-domain.com/testPath

而不是将我重定向到https://my-domain.com/login它重定向到 http://10.100.15.40:8541/ (这是它的内部 IP 和端口)

这里有一些日志:

2019-06-27 08:20:31.031 DEBUG 7 --- [nio-8541-exec-1] o.s.s.w.s.HttpSessionRequestCache        : DefaultSavedRequest added to Session: DefaultSavedRequest[http://10.100.15.40:8541/testPath]
2019-06-27 08:20:31.040 DEBUG 7 --- [nio-8541-exec-1] o.s.s.web.DefaultRedirectStrategy        : Redirecting to 'http://10.100.15.40:8541/login'
2019-06-27 08:23:50.634 DEBUG 7 --- [nio-8541-exec-2] o.s.s.w.s.DefaultSavedRequest            : requestURL: arg1=http://10.100.15.40:8541/testPath; arg2=http://10.100.15.40:8541/testPath (property equals)
2019-06-27 08:23:50.634 DEBUG 7 --- [nio-8541-exec-2] o.s.s.w.s.DefaultSavedRequest            : serverName: arg1=10.100.15.40; arg2=10.100.15.40 (property equals)

任何人都知道我在哪里可以将其配置为不使用内部 ip?

标签: spring-bootspring-security

解决方案


我发现了问题所在。问题是spring应用程序在代理后面。并且代理服务器没有发送标头 X-Forwarded-For。为了解决这个问题,我需要正确配置代理服务器。


推荐阅读