Varnish & WordPress Common Troubleshooting Tips


#1

Hi guys,

From my experience, I would like to share two important tips that I found necessary to implement after using Varnish for my WordPress Blog.

When you will use Varnish, IP for comment author may return localhost address.

Example

To fix, add below snippet in your theme function.

/** Required Code for showing correct IP address */
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { 
$xffaddrs = explode(',',$_SERVER['HTTP_X_FORWARDED_FOR']); 
$_SERVER['REMOTE_ADDR'] = $xffaddrs[0]; 
}

After a new visitor post comment to WordPress, the page should jump directly to new comment, and they should see a message “Your comment is awaiting moderation” Right? But with Varnish this may not happens.

To fix, make sure to exclude Varnish for below native cookie names.

Similarly, you can do for WooCommerce and other necessary stuffs.

Hope this helps!

Thanks & Regards,
Gulshan


Breeze - WooCommerce cart bug
Hide My WP - No IP Info for Intrusions
#2

Hi @gulshankumar

Excellent find and suggestion. This is something our clients can have in place to make comments work as expected.

In case of Breeze what we have done is whenever a new comment is published the cache of that page clears and the message “Your comment is awaiting moderation” appears.


#3

Thanks for the compliment. I’d suggest, please update in documentation.


#4

I will check with DevOps and see if we can add up in our Knowledge Base.


#5

Hi @gulshankumar

I have checked that the message “Your comment is awaiting moderation” appears while varnish is enabled.


#6

There were some situation, where I found things were not working properly.