title: Getting “Too many redirects” error with nginx rewrite rule
body: <p>this is nginx.conf.<br>
  There is a problem that continues to redirect.<br>
  i am getting a "too many redirects" error.<br>
  What's problems?</p>
  
  <p>i want "/aaa/test.do" uri to http.<br>
  not "/aaa/test.do" uri to https.<br>
  please help. Thanks.</p>
  
  <pre><code>map $uri $example_org_preferred_proto {
      default https;
      ~^/aaa/test.do http;
  }
  </code></pre>
  
  <p>........</p>
  
  <pre><code> 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;
      }
  </code></pre>