NGINX、GeoIP、Varnish:重定向次数过多

NGINX、GeoIP、Varnish:重定向次数过多

我有两台服务器。一台在新加坡 (data.example.me),另一台在欧洲 (eu.data.example.me)。

我希望当用户访问我的网站时,网站能够从最近的服务器为他们提供服务。

我使用 GeoIP 模块在 Signapore 服务器上配置了 Nginx。

当我从欧洲访问该网站 (data.example.me) 时,出现“ERR_TOO_MANY_REDIRECTS”错误。从其他地方访问该网站则一切正常。

这是欧洲服务器上的配置。它已安装 Varnish。

# 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";
}

在新加坡的Nginx服务器上配置如下。

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;
    }

答案1

重定向代码302 Found很可能是由您的应用程序而不是 nginx 返回的,因为您的 nginx 配置中没有对临时重定向的引用。

相关内容