问题
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