Report this

What is the reason for this report?

NGINX GeoIP Redirect and Search Engine Bots

Posted on June 10, 2020

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.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.