WordPress wrong comment ip

WordPress wrong comment IP

wordpress wrong comment ip

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;#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!

Rating: 5.0/5. From 1 vote.
Please wait...


Jules is the owner and author of ISPIRE.ME. He's a Linux System Engineer, Tech fanatic and an Open Source fan.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Translate »