Trying to configure domain based routing so that there are multiple APIs at path / proxied by the same Tyk gateway.
Is this supported? I sure hope the answer is yes.
All searches lead to old documentation which talks about Host Manager and NGINX.
Ideally we don’t have to run NGINX in front of Tyk to inject paths that Tyk uses for routing and then strips before proxying to target API servers.
There is a domain property listed in API Definition, however even though I’ve set it differently for two different API configurations with / path, the log indicates:
time=“Nov 18 22:13:03” level=info msg=“–> Loading API: test”
time=“Nov 18 22:13:03” level=info msg=“----> Tracking: tyk-test.com”
time=“Nov 18 22:13:03” level=info msg=“----> Checking security policy: JWT”
time=“Nov 18 22:13:03” level=info msg=“----> Setting Listen Path: /”
time=“Nov 18 22:13:03” level=info msg=“–> Loading API: www”
time=“Nov 18 22:13:03” level=error msg=“Duplicate listen path found, skipping. API ID: 1”
time=“Nov 18 22:13:03” level=warning msg=“----> Skipped!”
The domain for www was tyk-www.com.
Hi, can you share your
Can you also share your two api definitions?
Out of the box, you can have multiple apis on the same listen path provided the domains that are assigned in the API definition are different between the two, and domain management is enabled in the gateway (which by default it is - but it looks like it’s missing from your Tyk.conf).
Enabling domains is done with:
In the Tyk.conf file.
Success!!! Thanks, that fixed it.
One concern/question. When the browser URL includes a host like www.foo.com and the Tyk API domain is set to foo.com, it returns 404. It seems the API domain needs to include the host too.
Is that expected? If the answer is yes, then technically it isn’t a domain, but a hostname and domain.
It took me quite a bit of hacking before figuring it out as I only put the domain in the Tyk API config and included the host www in the browser URL. The API Object Domain definition documentation could ideally have a bit more explanation and include the fact that the tyk.conf enable_custom_domains needs to be set to true. If those had been there it would have taken me minutes instead of hours to get domain (really hostname) routing working.
It’s the hostname that is required, and it’s an explicit match, subdomain flattening such as www -> root needs to be handled elsewhere - apologies for the confusion.