I have managed to get NGINX GEOIP by Country to redirect, the following is what I have done:
nginx.conf
http {
##
# Add GeoIP to NGINX
##
geoip_city /usr/share/GeoIP/GeoLiteCity.dat;
geoip_country /usr/share/GeoIP/GeoIP.dat;
...
}
in my host file I placed the following
map $geoip_city_country_code $closest_server {
default example.com;
NZ nz.example.com;
CA ca.example.com;
US us.example.com;
GB gb.example.com;
}
server {
...
server_name example.com nz.example.com ca.example.com us.example.com gb.example.com;
...
if ($closest_server != $host) {
rewrite ^ $scheme://$closest_server$request_uri break;
}
What I need it to do is to redirect to the closest server but also allow the user to select another international subdomain and not redirect.
Secondly, I need to exclude search engine bots to be excluded from these rules.
Any assistance would be great.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
@bris4171 did you solve this? I have the same issue, how to allow the user to select another international subdomain and not redirect.
@bris4171 I found a solution, how to allow the user to select another international subdomain and not redirect - with http referer.
map $http_cf_ipcountry $regional_server {
default "en.example.org";
"US" "example.org";
}
if ($regional_server != $host) {
set $lang A;
}
if ($http_referer !~* "example.") {
set $lang "${lang}B";
}
if ($lang = AB) {
rewrite ^ $scheme://$regional_server$request_uri break;
}
$http_cf_ipcountry - I use cloudflare geoip solution
Now users can change subdomain
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.