We have 2 domains that point to our single Zuul ELB. Both sites use a lot of the same services so although our production environment will be setup a little different right now we only have the one Zuul ELB.
How can we route the same path to different services based on the domain name?
I would like to end up with something like this:
zuul:
host: http://a-zuul-host.elb.amazonaws.com:80
ignoredServices: '*'
routes:
app1:
path: /
domain: app1.com
serviceId: APP_1_SERVICE
app2:
path: /
domain: app2.com
serviceId: APP_2_SERVICE
Is this even possible or would I be required to setup another zuul instance?
Setting up Zuul API Gateway Server There are three steps to set up the Zuul API Gateway: Create a component for the Zuul API Gateway. Decide the things that the Zuul API Gateway should do. All the important requests are configured to pass through the Zuul API Gateway.
zuul dynamic routing Gateway service is the only access to traffic. Don't stop the service. So dynamic routing is particularly necessary. Database dynamic routing is based on event refresh mechanism to modify zuul's routing properties.
Creating Zuul Server Application The Zuul Server is bundled with Spring Cloud dependency. You can download the Spring Boot project from Spring Initializer page https://start.spring.io/ and choose the Zuul Server dependency. Add the @EnableZuulProxy annotation on your main Spring Boot application.
Zuul is an edge service that proxies requests to multiple backing services. It provides a unified “front door” to your system, which allows a browser, mobile app, or other user interface to consume services from multiple hosts without managing cross-origin resource sharing (CORS) and authentication for each one.
Here is one possible solution:
Here is a sample code:
zuul:
ignored-patterns: /health, /info
routes:
wildcard:
path: /**
url: /**
stripPrefix: false
You've to ignore /health because it is going to be matched with the wildcard routing rule, and will cause a problem -- should be mapped to one of spring actuators instead, so we ignore it and let everything be handled as before.
For the domain configurations here is a sample:
domain:
service_1:
domain-matcher: https://api_1.com:[0-9]+
url: https://service_1.com
service_2:
domain-matcher: https://api_2.com:[0-9]+
url: https://service_2.com
In your filter now just have to set our host based on the matching domain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With