0

I own two servers. One in Singapore (data.example.me) and other one in Europe (eu.data.example.me).

I want the website to serve the users from their closest server when they visit my website.

I configured Nginx on Signapore server using GeoIP Module.

I get "ERR_TOO_MANY_REDIRECTS" when visiting the website (data.example.me) from Europe. From other places it is working fine.

This is the configuration on Europe Server. It has Varnish installed.

# Marker to tell the VCL compiler that this VCL has been adapted to the
# new 4.0 format.
vcl 4.0;

# Default backend definition. Set this to point to your content server.
backend default {
.host = "139.51.1.1"; // Points to Nginx Server in Singapore
.port = "80";
}

On Nginx Server in Singapore configuration is as follows.

map $geoip_city_continent_code $closest_server {
default data.example.me;
EU      eu.data.example.me;
}

    server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm index.nginx-debian.html /_h5ai/public/index.php;

    server_name data.example.me eu.data.example.me;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            autoindex on;

            # Site Settings (DDOS & Other Stuff)
            limit_req zone=one burst=10 nodelay;
            limit_conn addr 5;

            # Bandwidth Control
            limit_rate_after 102400K;
            limit_rate 5120K;
    }

    client_body_timeout 5s;
    client_header_timeout 5s;

    #GeoIP
     if ($closest_server != $host) {
rewrite ^ $scheme://$closest_server$request_uri break;
}

    # pass PHP scripts to FastCGI server
    #
    location ~ \.php$ {
            include snippets/fastcgi-php.conf;
    #
    #       # With php-fpm (or other unix sockets):
            fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    #       # With php-cgi (or other tcp sockets):
    #       fastcgi_pass 127.0.0.1:9000;
    }

    location ~ /\.ht {
            deny all;
    }
    }

    server {
    listen 80;
    server_name 139.59.123.176;

    return 301 $scheme://data.vineethp.me$request_uri;
    }
0

The 302 Found redirect code is most likely returned by your application instead of nginx, since there is no reference to a temporary redirect in your nginx configuration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.