Spring-cloud-netflix: Can i use eureka to create nginx.conf for nginx dynamic loadBanance

Created on 14 Dec 2015  路  5Comments  路  Source: spring-cloud/spring-cloud-netflix

question

Most helpful comment

Hi Dave,

I didn't expect anything like this in Spring Cloud Netflix. So I`m totally fine with your answer.

However, let me clarify one or two things:

  • NGINX maps URL locations to backend servers in the proxy_pass directive. Your mapping options are versatile, e.g. your could map api.my.com/foo-service to an internal IP 10.0.0.19. These mappings are defined in the configuration file nginx.conf. Now if you're in a scaling environment, you don't want to hardcode these IPs be make these dynamic.
  • There is a specific integration between NGINX and Consul called Consul Template. It generates the config file mentioned above and can trigger NGINX to reload it. It's easy to imagine to have the same for Eureka. BTW, this works also with the NGINX basic edition - not only with the Plus edition.
  • The "on-the-fly configuration API" is based on HTTP. Although there's no dedicated Java client, integrating this generic API isn't very hard.

As I said in the beginning, I didn't expect this to be included in Spring Cloud Netflix. I think this would be worth a separate project.

All 5 comments

The question makes no sense to me. If anyone has any insight please comment.

The OP is asking for the integration between NGINX and Eureka. The former has to be configured through the nginx.conf file to be become aware of existing service instances and changes of their status. This information can be derived from the service registry of course.

This article from NGINX describes this integration when using Consul for service discovery. The project Consul Template reads information from Consul and generates the respective config file for NGINX.

On behalf of the OP: Does Spring Cloud Netflix provide the same to integrate Eureka with NGINX?

OK, that is helpful - the article is about the pattern, not the details of an implementation. The pattern is dynamically re-configuring a reverse proxy Nginx, using a service registry (so presumably the proxy has to be resolvable by clients of all the services, using a mapping from subdomain to service name or something). If any support for such a feature was provided in Spring Cloud it wouldn't really make sense for it to be Netflix specific, so something based on Spring Cloud Commons would be appropriate.

It looks to me like Nginx out of the box wouldn't really support this pattern anyway - you'd need the paid-for version (Nginx Plus), which has a configuration API. If there is a Java client for this API we could certainly see about how to integrate it. (But probably not in Spring Cloud Netflix.)

Hi Dave,

I didn't expect anything like this in Spring Cloud Netflix. So I`m totally fine with your answer.

However, let me clarify one or two things:

  • NGINX maps URL locations to backend servers in the proxy_pass directive. Your mapping options are versatile, e.g. your could map api.my.com/foo-service to an internal IP 10.0.0.19. These mappings are defined in the configuration file nginx.conf. Now if you're in a scaling environment, you don't want to hardcode these IPs be make these dynamic.
  • There is a specific integration between NGINX and Consul called Consul Template. It generates the config file mentioned above and can trigger NGINX to reload it. It's easy to imagine to have the same for Eureka. BTW, this works also with the NGINX basic edition - not only with the Plus edition.
  • The "on-the-fly configuration API" is based on HTTP. Although there's no dedicated Java client, integrating this generic API isn't very hard.

As I said in the beginning, I didn't expect this to be included in Spring Cloud Netflix. I think this would be worth a separate project.

You can do this by monitoring registry changes and modifying nginx.conf

there is a demo:
https://github.com/codingmiao/ngineureka

Was this page helpful?
0 / 5 - 0 ratings