WordPress and Varnish comment IPs

If your WordPress install is behind Varnish you may have issues with Comments showing your Server IP. This will also cause problems with Spam as Akismet will not be able to check the source IP.

In the vcl_recv part of your varnish config add this

set req.http.X-Forwarded-For = client.ip;

Then edit your WordPress wp-includes/comment.php and replace REMOTE_ADDR with HTTP_X_FORWARDED_FOR
Then edit your wp-content/plugins/akismet/akismet.php and replace REMOTE_ADDR with HTTP_X_FORWARDED_FOR

Restart varnish

/etc/init.d/varnish restart

Finished, test by commenting.

Note: Users experiencing spam on PrimaryBlogger should now experience less spam and more accurate comment filtering.

If you are running Varnish 2.1.2 RPCXML will not work, you need to upgrade to 2.1.3..  You can find out your version by typing


varnishd -V

Leave a Reply

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