These are chat archives for spring-cloud/spring-cloud

15th
Apr 2016
Darek Kaczyński
@kaczynskid
Apr 15 2016 09:07

Hi! I have Spring Cloud Eureka Server and want to access it through nginx reverse proxy. I have a problem with Eureka Dashboard as it has the base URL set like this:

<base href="<@spring.url basePath/>">

which results in:

<base href="/">

and invalid links to JS and CSS. I tried setting server.use-forward-headers=true but it did not help. Any suggestions?

Darek Kaczyński
@kaczynskid
Apr 15 2016 09:22
To make it work I had to add another propxy_pass for /eureka endpoint for the dasboard to access WRO resources. But is there a better way to do it?
Dave Syer
@dsyer
Apr 15 2016 11:04
I guess the freemarker macro might need to be fixed (Spring MVC not Spring Cloud)
I find that odd though
Dave Syer
@dsyer
Apr 15 2016 11:10
Please open an issue in JIRA and paste a link
Darek Kaczyński
@kaczynskid
Apr 15 2016 11:12
@dsyer in Spring Boot project?
Darek Kaczyński
@kaczynskid
Apr 15 2016 11:20
btw, the same issue is with Hystrix dashboard; I always get:
<base href="/hystrix/">
Matúš Hennel
@me3x
Apr 15 2016 12:19
I’m trying to fix a bug, but I broke a test with my pull request.
The test seems to be unrelated to a change
Marcin Grzejszczak
@marcingrzejszczak
Apr 15 2016 12:20
can you paste the stacktrace with formatting?
Matúš Hennel
@me3x
Apr 15 2016 12:22
```

```Condition not satisfied:

['me', '/a/b/c/d/anotherservice'].every { expectedServiceName -> services.any { service -> expectedServiceName == service.name } }
|
false

at org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryHealthIndicatorWithNestedStructureISpec.twoServicesArePresentedInHealthEndpoint(ZookeeperDiscoveryHealthIndicatorWithNestedStructureISpec.groovy:44)
at org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryHealthIndicatorWithNestedStructureISpec.should return a response that app is in a healthy state when nested folders in zookeeper are present(ZookeeperDiscoveryHealthIndicatorWithNestedStructureISpec.groovy:39)```
Marcin Grzejszczak
@marcingrzejszczak
Apr 15 2016 12:23
so basically it seems that you broke the Dependenceis functionality
that test registers an app under a nested folder in Zookeeper
Matúš Hennel
@me3x
Apr 15 2016 12:24
I see that you assert that it is under /a/b/c/d
but where do you specify under which folder it is registered?
I see :)
config is below
Marcin Grzejszczak
@marcingrzejszczak
Apr 15 2016 12:28
:+1:
Dave Syer
@dsyer
Apr 15 2016 12:29
@kaczynskid the problem seems to be in Spring (https://jira.spring.io/browse/spr)
(and hystrix dashboard is identical in implementation)
Actually, maybe the problem is in your app
Did you configure the container for being behind a proxy?
Darek Kaczyński
@kaczynskid
Apr 15 2016 12:54
@dsyer that's where I found the server.use-forward-headers=true flag, that unfortunately did not help; I use standard X-Forwarded-For and X-Forwarded-Proto headers, so I did not add any Tomcat specific configuration; now I tried setting server.tomcat.internal-proxies=172\\.17\\.\\d{1,3}\\.\\d{1,3} to match the docker subnet, but still no change
Dave Syer
@dsyer
Apr 15 2016 12:55
I'm not sure, actually, what the issue is
Dave Syer
@dsyer
Apr 15 2016 13:01
You're not rendering ports and addresses anyway
just a path
Darek Kaczyński
@kaczynskid
Apr 15 2016 13:02

my nginx config is quite simple:

upstream registry {
  server registry:8765 fail_timeout=0;
}

server {
  listen 80;
  server_name example.com;
  return 301 https://$host$request_uri;
}

server {
  listen 443;
  server_name example.com;

  client_max_body_size 1g;

  ssl on;
  ssl_certificate /etc/nginx/ssl/wild.thawte.chained.cer;
  ssl_certificate_key /etc/nginx/ssl/private-key-for-example.pem;

  location /registry {
    return 302 /registry/;
  }

  location /registry/ {
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;
    proxy_set_header        X-Forwarded-Host $host;
    proxy_pass              http://registry/;
  }

  location /eureka {
    return 302 /eureka/;
  }

  location /eureka/ {
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;
    proxy_set_header        X-Forwarded-Host $host;
    proxy_pass              http://registry/eureka/;
  }
}

The registry hostname is refering to a docker link to a container running a @SpringBootApplication with @EnableEurekaServer with following configuration:

server:
  port: 8765
  use-forward-headers: true
  tomcat:
    internal-proxies: 172\\.17\\.\\d{1,3}\\.\\d{1,3}

spring:
  application:
    name: registry

eureka:
  instance:
    hostname: localhost
    preferIpAddress: true
  client:
    registerWithEureka: false
    fetchRegistry: true
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
  server:
    waitTimeInMsWhenSyncEmpty: 0
Dave Syer
@dsyer
Apr 15 2016 13:02
The path isn't different when you come through a proxy, unless the proxy is monkeying with it
Yeah, so you are monkeying with the path.
You send /registry to / (in the backend)
and the backend (Eureka) has no way to know that you want it to be at /registry
Darek Kaczyński
@kaczynskid
Apr 15 2016 13:05
I tired:
eureka:
  dashboard:
    path: /registry
Dave Syer
@dsyer
Apr 15 2016 13:05
Right, that's probably on the right track.
Or even just server.context-path=/registry
Darek Kaczyński
@kaczynskid
Apr 15 2016 13:07

and changed in nginx:

  location /registry/ {
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header        X-Forwarded-Proto $scheme;
    proxy_set_header        X-Forwarded-Host $host;
    proxy_pass              http://registry/registry/;
  }

but I still got:

<base href="/">
<link rel="stylesheet" href="eureka/css/wro.css">

in the resulting HTML

Dave Syer
@dsyer
Apr 15 2016 13:08
That doesn't look right.
What version of Spring Cloud are you using?
This is with server.context-path=/registry?
Darek Kaczyński
@kaczynskid
Apr 15 2016 13:10
no, with:
eureka:
  dashboard:
    path: /registry
I'll try server.context-path=/registry
Dave Syer
@dsyer
Apr 15 2016 13:10
I don't think that does what you need
Darek Kaczyński
@kaczynskid
Apr 15 2016 13:11
but I think this will mess up my hystrix dshboard, that is not running of the same app
Dave Syer
@dsyer
Apr 15 2016 13:11
"of the same app"?
Darek Kaczyński
@kaczynskid
Apr 15 2016 13:11
because then I'll have /registry/hystrix on the backend, while I'd like /hystrix on the proxy
Dave Syer
@dsyer
Apr 15 2016 13:11
You have @EnableHystrixDashboard in the same app?
Darek Kaczyński
@kaczynskid
Apr 15 2016 13:12
yes
and @EnableZuulProxy as well, for the record
Dave Syer
@dsyer
Apr 15 2016 13:12
Yeah, you're going to have to be creative
None of those were designed to be running in the same app but using different paths
Darek Kaczyński
@kaczynskid
Apr 15 2016 13:13
I could go with a subdomain for the registry, instead of a /registry sub-path...
Dave Syer
@dsyer
Apr 15 2016 13:14
Yeah, that would work.
Darek Kaczyński
@kaczynskid
Apr 15 2016 13:14
I think this would be the easiest solution
Dave Syer
@dsyer
Apr 15 2016 13:14
Excellent
Pedro Alvarado
@PedroAlvarado
Apr 15 2016 13:18
@dsyer Per our conversation yesterday around @ExportMetricReader, I simply added a MetricsEndpointMetricReader bean and all the metrics became available for export. Moreover, I implemented a splunk MetricWriter with success . Thanks for your help.
Darek Kaczyński
@kaczynskid
Apr 15 2016 13:19

but it would still be nice if setting:

eureka:
  dashboard:
    path: /registry

would affect not only HTML, but all the resources needed for Eureka dashboard; than you could remove:

<base href="<@spring.url basePath/>">

form the FreeMarker template and it would all work based on relative links, I think...

Dave Syer
@dsyer
Apr 15 2016 15:12
I have a feeling that breaks something else