Plugin detecting default IP – Nginx Reverse Proxy (Bluehost VPS hosting)
-
On a more recent site, I was having issues getting the plugin to work with an nginx reverse proxy (on bluehost VPS hosting); the plugin was detecting the server IP instead of the user IP, so it wasn’t able to serve the correct currency, and fell back on the default (USD). After a few months of talking to support, and nearly 100 emails, we were able to get it functioning perfectly by removing some WooCommerce code (that the support team wasn’t required to do, but helped me with nonetheless out of the kindness of their hearts). Highly recommend this plugin and the support that comes with it!
Here’s the code to remove if anyone has the same problem (may change with future woocommerce updates):
WooCommerce/includes/class-wc-geolocation.php
remove:
if ( isset( $_SERVER[‘HTTP_X_REAL_IP’] ) ) {
return $_SERVER[‘HTTP_X_REAL_IP’];
} elseif ( isset( $_SERVER[‘HTTP_X_FORWARDED_FOR’] ) ) {
// Proxy servers can send through this header like this: X-Forwarded-For: client1, proxy1, proxy2
// Make sure we always only send through the first IP in the list which should always be the client IP.
return (string) self::is_ip_address( trim( current( explode( ‘,’, $_SERVER[‘HTTP_X_FORWARDED_FOR’] ) ) ) );
} elseHope this helps anyone who had the same issue as me!
- The topic ‘Plugin detecting default IP – Nginx Reverse Proxy (Bluehost VPS hosting)’ is closed to new replies.