zuul重定向问题背后的Spring MVC Web应用程序

时间:2016-04-27 06:21:51

标签: spring-security spring-boot netflix-zuul spring-cloud-netflix

我有一套Spring Boot(1.3.3),其中Spring Cloud(Brixton.RC2)微服务在Zuul后面运行,我的网址被重定向重写了。

我的主要问题是我的网络应用程序落后于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
}

同样,所有网址都正确使用服务器名称,除非它是重定向。知道怎么解决这个问题吗?

非常感谢!

0 个答案:

没有答案