Modifying Headers sent to upstream

We have a problem with the way the Host header is sent to our upstream client. The client is not expecting the port to be present, and kong is adding it (even if it is the common port for the protocol). This results in the request being incorrectly misinterpreted by the upstream client. Is there a way for us to remove the port that is appended to the Host header?

As a side note it does appear that we can do this with the EE version using the request transformer plugin, but we are not using the EE version, and don’t plan to. So this option doesn’t work.


If you are using a recent version of Kong (> 0.11), then the upstream Host header should not include the port when it is 80 or 443, if it does, would you please provide us with some more details? It may be a bug. See core/handler.lua for the related source.

Assuming there is such a bug, or that the port you are seeing is actually not the default port for said protocol, you could get away with it by setting the ngx.var.upstream_host variable (you can see this variable in the above link). Note that this interface is not public nor stable and is subject to future changes.

Also make sure that your API does not have the preserve_host attribute enabled.

Thank you @thibaultcha, We are using version 0.10 - but per your suggestion I think we will try the upgrade (we have custom plugins in use that I’m unsure of their compatibility) and see if we can incorporate that change from 0.11.

CONTINUED: We upgraded to 0.12, fixed our custom plugin, and all is well! Thank you!