Spring redirect url issue when behind Zuul proxy

后端 未结 2 1012
有刺的猬
有刺的猬 2021-02-20 11:24

I\'ve been trying to get to the bottom of a strange redirection issue for the past 2 days without success.

Based on the spring-cloud example projects, I\'ve configured E

相关标签:
2条回答
  • 2021-02-20 11:57

    As you can see RedirectView ignores X-FORWARDED-* headers. Simply put, you can't use "redirect:/account".

    Instead instantiate a RedirectView and configure it accordingly:

    RedirectView redirect = new RedirectView("account");
    redirect.setHosts(new String[]{ request.getHeader("X-FORWARDED-HOST") });
    

    Since Spring Framework 4.3 (currently RC1) setHosts method is available.

    0 讨论(0)
  • 2021-02-20 12:07

    If you are using tomcat as embeded server in your backend app, you could use this settings (application.properties, yml, etc):

    server.tomcat.remote_ip_header=x-forwarded-for
    server.tomcat.protocol_header=x-forwarded-proto
    

    Or more generic way:

    server.use-forward-headers=true
    
    0 讨论(0)
提交回复
热议问题