Spring MVC web app behind zuul redirect issue

五迷三道 提交于 2020-02-01 04:39:46

问题


I have a set of Spring Boot (1.3.3) with Spring Cloud (Brixton.RC2) microservices running behind Zuul and I have issues with my urls being rewritten in redirects.

My main issue is that my web app is behind zuul and seems to be unaware of host during redirects even though I should have set all necessary properties.

When I go to http://test.example.com/ I expect to be redirected to http://test.example.com/login but I get redirected to http://machinehostname/login... If I go directly to http://test.example.com/login I can see my login form and login but then get redirected to http://machinehostname/ but if i manually go to http://test.example.com/ I can use my application properly again with exeception of redirects, after a POST in a form for example.

Here are some of the properties of my web app :

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

Here is my zuul properties :

#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 = /**

My security setup in the web app :

@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
}

Again, all urls are properly using the server name unless it is a redirect. Any idea how to fix that ?

Thanks a lot !

来源:https://stackoverflow.com/questions/36881835/spring-mvc-web-app-behind-zuul-redirect-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!