Closed ahmadnassri closed 9 years ago
I can easily fix this, but it may lead to some problems. I believe the reason we decided to change the Host
header to reflect the target url's host, is because it created issues with the Virtual Host resolution: some servers that handle more than one host, use the Host
header to determine the Virtual Host that should process the request.
We need to better test this. If we find out that it can cause problems, then this needs to be a flag when adding the API, like preserve_host = true | false
.
Specifically, we need to understand if this is really required: https://github.com/Mashape/kong/blob/master/kong/resolver/access.lua#L179
The fix to this issue would be to comment that line, and add the following nginx directive before the proxy_pass
instruction:
proxy_set_header Host $host;
as mentioned, I believe both solutions are valid (in different scenarios) therefore, should be flag ... or a feature of request transform plugin
I have added the preserve_host
flag (default false
) when adding a new API.
When setting up Kong in-front of an API service that relies on the Host header for routing (e.g. Kong itself), Kong uses the
target_url
in the proxied request.it should either:
Host
header all the way through (perhaps this should be the default?)Host
header to be set at the time of creation as an additional property of the API object.alternatively the
request-transformer
plugin could be used here, however, currently attempting to overwrite theHost
header withrequest-transformer
does nothing. (see #445)detailed example: