使用nginx重写规则获取“太多重定向”错误

时间:2015-03-16 13:43:58

标签: redirect nginx rewrite http-status-code-301

这是nginx.conf 有一个问题继续重定向。
我收到了“太多重定向”的错误 有什么问题?

我想要“/aaa/test.do”uri到http 不是“/aaa/test.do”uri到https。
请帮忙。感谢。

map $uri $example_org_preferred_proto {
    default https;
    ~^/aaa/test.do http;
}

........

 server {
        listen       80;
        server_name  www.test.com;

        charset utf-8;

        if ($example_org_preferred_proto = "https") {
            return 301 https://$server_name$request_uri;
        }

        location / {
           proxy_set_header Host                $host;
           proxy_set_header X-Real-IP            $remote_addr;
           proxy_set_header X-Forwarded-Host    $host;
           proxy_set_header X-Forwarded-Server    $host;
           proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
           proxy_set_header        Host $http_host;
           proxy_redirect off;
           proxy_buffering off;
           proxy_connect_timeout 60;
           proxy_read_timeout 60;
           proxy_pass   http://wwwtestcom;
        }
}


# HTTPS server
#
server {
    listen       443;
    server_name  www.test.com;

    charset utf-8;

    ssl                  on;
    ssl_certificate      D:/nginx-1.7.10/ssl/cert.pem;
    ssl_certificate_key  D:/nginx-1.7.10/ssl/key.pem;

    ssl_session_timeout  5m;

    ssl_protocols  SSLv3 TLSv1;
    ssl_ciphers  !ADH:RC4+RSA:+HIGH:!EXP:+eNULL:AES256-SHA;
    ssl_prefer_server_ciphers   on;

    if ($example_org_preferred_proto = "http") {
        return 301 http://$server_name$request_uri;
    }

    location / {
       proxy_set_header Host                $host;
       proxy_set_header X-Real-IP            $remote_addr;
       proxy_set_header X-Forwarded-Host    $host;
       proxy_set_header X-Forwarded-Server    $host;
       proxy_set_header X-Forwarded-For        $proxy_add_x_forwarded_for;
       proxy_set_header        Host $http_host;
       proxy_redirect off;
       proxy_buffering off;
       proxy_connect_timeout 60;
       proxy_read_timeout 60;
       proxy_pass   http://wwwtestcom;
       proxy_ssl_session_reuse off;
    }

1 个答案:

答案 0 :(得分:0)

此处缺少引号(" http"和" https"):

map $uri $example_org_preferred_proto {
    default "https";
    ~^/aaa/test.do "http";
}

另外,我建议为HTTP和HTTPS服务器定义单独的访问和错误日​​志。检查这些日志文件中的消息将帮助您快速调试问题。