I have a setup where I am using Varnish/Hitch >> HAProxy >> Apache
. It works except for a problem where the client IP address isn't being passed correctly to the backend Apache server. The Apache log shows the IP address of the machine HAProxy is running on.
My Varnish command line contains:
varnishd -b 127.0.0.1:8080 -a 127.0.0.1:8000,PROXY
Hitch has this:
backend = "[127.0.0.1]:8000"
write-proxy-v2 = on
HAProxy is configured with:
defaults
option forwardfor
mode http
frontend CacheFrontend
bind *:8080
backend apache
server apache web01:80
In Apache I am using the remoteip_module
and have this in httpd.conf
RemoteIPHeader X-Forwarded-For
From what I've read, there is no reason for me to change the log format in Apache when using this module.
I'm unsure where the misconfiguration is.
EDIT:
Here's a short PHP script showing what is being passed to Apache:
<?php
echo $_SERVER['HTTP_X_FORWARDED_FOR'] . PHP_EOL;
echo $_SERVER['REMOTE_ADDR'] . PHP_EOL;
<redacted_client_ip>, 127.0.0.1
10.7.7.107
10.7.7.107
is the IP of the HAProxy machine.