Having trouble with WordPress wrong comment IP behind a Loadbalancing environment or especially Varnish / HAProxy?
Getting local IP address in comment posts e.g.?
Solutions is here!
If you have properly set your X-Forwarded-For field into your Header or don’t even know that this option exist 😉 you have also add this to your applications running behind such setup.
First solution: To get rid with it on WordPress all you have to do is a little PHP magic by rewriting your remote_addr
variable with your X-Forwarded-For one.
Fire up your preferred text editor and add this to your wp-config.php
file:
$behindproxy = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']); $_SERVER['REMOTE_ADDR'] = $behindproxy[0];
The second solution: If you are using Nginx as Webserver you can take advantage of the Module called HttpRealipModule by adding this to your nginx.conf
http section:
http { set_real_ip_from 192.168.1.2;#Replace with Varnish/HAProxy Server IP real_ip_header X-Forwarded-For; ....
Bear in mind that you have to set the correct Varnish/HAProxy Server IP. It’s very important! Else it won’t resolve correct.
That’s usually all you have to do if your HTTP header is delivering the x-forwarded-for field.
Enjoy it!
HTTP/2 SSL Offloading with Hitch and Varnish Since Chrome browsers showing you insecure warning on…
File changed as we read it GlusterFS issue Recently i had trouble running Backups of…
Running multiple instances of varnish using systemd If you have not yet found a complete…
HTTP/2 SSL Offloading with Haproxy and Nginx After HTTP/2 becoming more an more prominent regarding SSL…
Get Real IP with Haproxy Tomcat Jira Confluence using x-forwarded-for Everyone knows the Problem. Get…
Review TDS2 How to backtest using tick data with Metatrader 4 in this Review TDS2…
This website uses cookies.