5

我有一组 Spring Boot (1.3.3),Spring Cloud (Brixton.RC2) 微服务​​在 Zuul 后面运行,并且我的 url 在重定向中被重写时遇到问题。

我的主要问题是我的网络应用程序落后于 zuul 并且在重定向期间似乎不知道主机,即使我应该设置所有必要的属性。

当我去http://test.example.com/我希望被重定向到http://test.example.com/login但我被重定向到http://machinehostname/login ...如果我直接去到http://test.example.com/login我可以看到我的登录表单并登录,但随后被重定向到http://machinehostname/但如果我手动转到http://test.example.com/我可以使用例如,在表单中的 POST 之后,我的应用程序再次正确执行重定向。

以下是我的网络应用程序的一些属性:

server.use-forward-headers = true
server.tomcat.protocol-header = X-Forwarded-Proto
server.tomcat.remote-ip-header = X-Forwarded-For

这是我的 zuul 属性:

#Server
server.port = 80
server.use-forward-headers = true 

#Zuul
zuul.add-proxy-headers = true
zuul.ignored-services = "*"

zuul.routes.api.service-id = api
zuul.routes.api.path = /api/**
zuul.routes.api.strip-prefix = true

zuul.routes.web.service-id = web
zuul.routes.web.path = /**

我在网络应用程序中的安全设置:

@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
    //@formatter:off
    httpSecurity
        .formLogin()
            .successHandler(new SavedRequestAwareAuthenticationSuccessHandler())
            .loginPage("/login")    
                .permitAll()
            .failureUrl("/login-error")
            .defaultSuccessUrl("/")
            .and()
        .logout()
            .logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
                .logoutSuccessUrl("/logged-out")
                    .permitAll()
            .and()
            .anyRequest()
                .authenticated();
    //@formatter:on
}

同样,所有 url 都正确使用服务器名称,除非它是 redirect。知道如何解决吗?

非常感谢 !

4

0 回答 0