spring-cloud / spring-cloud-netflix

Integration with Netflix OSS components
http://cloud.spring.io/spring-cloud-netflix/
Apache License 2.0
4.87k stars 2.44k forks source link

Is it possible to override the basePath used in eureka templates? #2046

Open MikeSebetichB opened 7 years ago

MikeSebetichB commented 7 years ago

Hi, it seems that the basePath used in eureka freemarker templates (like this one) can not be overridden and is hard coded to '/' in the EurekaController. Can you please tell me if my understanding is correct? Thank you for your help.

spencergibb commented 7 years ago

Can you describe why you want to change the basePath?

MikeSebetichB commented 7 years ago

Sure, I have my eureka server hosted under http://myserver/somePath. Since the basePath is assumed to be '/' the template is trying to load static content from http://myserver/. For example, the template tries to load http://myserver/eureka/css/wro.css but it should load http://myserver/somePath/eureka/css/wro.css. I'm open to other suggestions on how to resolve this if I can do something other than changing the basePath (I have to host it under somePath though). Thank you for your help.

spencergibb commented 7 years ago

Try setting eureka.dashboard.path

MikeSebetichB commented 7 years ago

I looked into that but let me expand on something. http://myserver/somePath is the route to the root of my eureka service. i.e. that path is created outside of the eureka service itself. If I set eureka.dashboard.path=somePath I would then need to access the dashboard from http://myserver/somePath/somePath. Hosting the root of my service under http://myserver/somePath is unfortunately a constraint.

spencergibb commented 7 years ago

It's not something we support at this time.

MikeSebetichB commented 7 years ago

Understood, thank you for your responses.

mgrafl commented 6 years ago

Hi, I ran into a similar use case: When the eureka server is behind a gateway (e.g., zuul reverse proxy), the zuul route prefix is stripped and is put into the x-forwarded-prefix header. So, it would be nice if the basePath was configurable or was picked up from the x-forwarded-prefix header.

xeniumlee commented 5 years ago

By use ingress-nginx in k8s, there're 2 annotations for rewrite in this case (but deprecated in 0.22.0): nginx.ingress.kubernetes.io/add-base-url nginx.ingress.kubernetes.io/base-url-scheme

The generated nginx conf is: set_escape_uri $escaped_base_uri $baseuri; subs_filter '(<(?:H|h)(?:E|e)(?:A|a)(?:D|d)(?:[^">]|"[^"]*")*>)' '$1<base href="https://$http_host/xxxx/$escaped_base_uri">' ro;

I guess similar conf is required in other gateways, if eureka use static basePath.

abaschen commented 5 years ago

Bumping this issue. same as Spring Boot Admin they handle the base path (almost) the same way as you do. Very troublesome when behind a Zuul Proxy for example.