Apache Logs Show the Load Balancer's IP, Not the Client's: Fixing It Behind HAProxy

You put HAProxy in front of two Apache servers, everything balances nicely, and then you open the access log on one of the web servers. Every single request comes from the same IP: the load balancer. This guide explains why that happens, the quick fix (log the X-Forwarded-For header), and the cleaner fix with mod_remoteip, plus the detail most guides skip: the quick fix can be faked by any client. ...

December 6, 2026 · 5 min · Sysadmin Field Notes

PHP Sessions Keep Resetting Behind HAProxy: Sticky Sessions with a Cookie

Classic symptom after putting a load balancer in front of two PHP servers: users get logged out at random, a cart empties itself, a multi-step form forgets what you typed. Nothing is “broken” on either server. The problem is where PHP keeps sessions. Below is a minimal way to reproduce it, the explanation, and the fix with HAProxy’s cookie-based persistence (sticky sessions). Reproduce it in one minute Two Apache + PHP backends (apache1, apache2) behind HAProxy with balance roundrobin. On both servers, create /var/www/html/session.php: ...

December 6, 2026 · 4 min · Sysadmin Field Notes