Disable NGINX caching included file or variable
Disable NGINX caching included file or variable
I've created a simple geoip redirection by creating a wordpress plugin. This code is loaded to wordpress index.php and handles retrieving the user's IP, I've initially tried this in an apache server and was working fine.
However once I moved my codes to an Nginx server it caches this file and is sending all users to the cached redirection route. Is there any way to tell nginx to not cache this included file or by any chance the variable.
Could someone recommend me how to approach this issue. My current solution is creating a javascript ajax request to an independent php file. However this adds a lot of loading time to the page. I'm trying to aim to keep this all in php.
function getIP()
if (getenv('HTTP_X_FORWARDED_FOR'))
$ip = getenv('HTTP_X_FORWARDED_FOR');
elseif (getenv('HTTP_X_REAL_IP'))
$ip = getenv('HTTP_X_REAL_IP');
else
$ip = $_SERVER['REMOTE_ADDR'];
return $ip;
0
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.