I am configuring multiple services in the same kong.yaml
. e.g.
services:
- host: service1.com
name: service1
port: 8000
route: ...
- host: service2.com
name: service2
port: 9000
route: ...
When I make a request from the client e.g.
curl -X GET -k https://localhost:8443/v1/service2/api -H "apiKey: service2-api-key"
It keeps getting proxied to service1 by default and getting the following error:
2021/05/14 01:46:40 [error] 26#0: *37325 [lua] balancer.lua:1064: execute(): DNS resolution failed: dns server error: 3 name error. Tried: ["(short)service1.com:(na) - cache-miss","service1.com:33 - cache-miss/scheduled/querying/dns server error: 3 name error","service1.com:1 - cache-miss/scheduled/querying/dns server error: 3 name error","service1.com:5 - cache-miss/scheduled/querying/dns server error: 3 name error"], client: 172.18.0.5, server: kong, request: "GET /v1/service2/api HTTP/2.0", host: "localhost:8443"
From the docs it mentioned that you can add a hosts
attribute to the route object and have the client make a request with the host in the header (and this works). e.g.
curl -X GET -k https://localhost:8443/v1/service2/api -H "apiKey: service2-api-key" -H "Host: service2.com"
However, I cannot change how the client makes the request since this is already in production. Is there a way that we can proxy the request without having to change the client's request to include the host (Host: <given host>
) in the header?
Also, something to note, if I completely remove service1, then it works, it defaults to service2 route without needing to include the extra Host in the header of the request.