How to route from either forwarded or x-forwarded-host header?

Hi there.

We have a setup where a custom built router forwards requests to our kong server. We have configured Kong to serve routes via the hosts directive ( as per https://docs.konghq.com/1.2.x/admin-api/#add-route ).

Imagine we have two sites, site1.example.org and site2.example .org

Kong has several services and routes configured, one though has a hosts entry of site1.example .org, another has site2.example .org

The kong server has a hostname of kong.example .org

A user types into their browser site1.example.org and hits our load balancer ( this bit works )
Our custom router forwards that request to kong.example .org ( this bit works )
Kong does not route that request as per the hostname entered in the users browser ( site1.example .org )
If I log onto the Kong server and curl localhost and pass the header Host: site1.example .org ( this works ).

Our custom router populates the Host Header with Host: kong.example.org but populates the forwarded header with the correct name ( site1.example.org ), it also populates x-fowarded-host header with site1.example .org.

My question is, how do I tell Kong to route the request based on either the x-forwarded-host or forwarded header?

I’ve seen loads of documentation around passing the clients IP address upstream by setting trusted_ip in kong.conf. I’ve also tried adding preserve_host to the route but no joy.

Please could someone offer their guidance for me to get around this issue.

Many thanks

N.B. cause I’m a new user I can only post 5 links :confused:

Chris

@chridster Hi, and welcome!

It is not possible at the moment to configure Kong’s router with other headers than Host. But good news, since we are precisely working on this feature as we are speaking, and it should land in Kong 1.3 (to be released before the end of this month). The PR is a work in progress, visible here:

Best,

1 Like

Hey @thibaultcha, thanks for reaching out so quickly.

That’s great news about the new functionality coming very soon. The same thing happened when I needed to configure kong declaratively, you guys were very close to implementing that, now I use it all the time.

There is a work around and that’s by creating a couple new DNS entries and pointing each one to the kong server. We can then modify our router to use those DNS entries for each site.

Again thanks for the expert advice, I’ll stop trying to create crazy configuration to get around it.

Keep up the great work Kong folks

All the best

Chris