Categories: SolutionsWordpress

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

Jules

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

Recent Posts

HTTP/2 SSL Offloading with Hitch and Varnish

HTTP/2 SSL Offloading with Hitch and Varnish Since Chrome browsers showing you insecure warning on…

7 years ago

File changed as we read it GlusterFS issue

File changed as we read it GlusterFS issue Recently i had trouble running Backups of…

8 years ago

Running multiple instances of varnish using systemd

Running multiple instances of varnish using systemd If you have not yet found a complete…

8 years ago

HTTP/2 SSL Offloading with Haproxy and Nginx

HTTP/2 SSL Offloading with Haproxy and Nginx After HTTP/2 becoming more an more prominent regarding SSL…

8 years ago

Get Real IP with Haproxy Tomcat Jira Confluence using x-forwarded-for

Get Real IP with Haproxy Tomcat Jira Confluence using x-forwarded-for Everyone knows the Problem. Get…

8 years ago

Review TDS2 How to backtest using tick data with Metatrader 4

Review TDS2 How to backtest using tick data with Metatrader 4 in this Review TDS2…

8 years ago

This website uses cookies.