Config apache to not use x-forwarded-host header to be a host name

9/28/2018

I got a 400 bad request when I request to Apache though K8 ingress if my request there is x-forwarded-host header more than 1 look like

www.a.com, www.b.com

I log Apache from this request, Apache use x-forwarded-host to be a host name. Apache log look like this

[core:debug] [pid 18] vhost.c(796): [client 172.17.0.7:51726] AH02415: [strict] Invalid host name 'www.a.com,www.b.com', problem near: ,www.b

[core:debug] [pid 18] vhost.c(891): [client 172.17.0.7:51726] AH00550: Client sent malformed Host header: www.a.com,www.b.com

[core:debug] [pid 18] protocol.c(1393): [client 172.17.0.7:51726] AH00569: client sent HTTP/1.1 request without hostname (see RFC2616 section 14.23): / [headers:debug] [pid 18] mod_headers.c(900): AH01503: headers: ap_headers_error_filter() 172.17.0.5:80 172.17.0.7 - - [28/Sep/2018:10:27:44 +0000] "GET / HTTP/1.1" 400 0 "-" ""

I have to config Apache don't use x-forward-host to be a host name. How I config it in Apache?

-- oonoroo
apache
kubernetes

1 Answer

9/28/2018

That header is sent by the device in front of your Apache. That device, acting as a proxy adds this header. So you are receiving it. If you do not want it in your logs, change the format descriptor of your logs.

Ex: default LogFormat

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

And the one I use on my production servers:

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

And I use this when I define the access_log:

CustomLog logs/access_log combined

If I remove the %{X-Forwarded-For}i and replace it by the default %h, the "double" host names (or IP) do not show anymore.

If this does not apply to your configuration, add your LogFormat and CustomLog directives from your configuration file so we can comment on those.

-- Nic3500
Source: StackOverflow