【问题标题】:Specific HTTP Redirect help - "Request exceeded the limit of 10 internal redirects"特定 HTTP 重定向帮助 - “请求超出了 10 个内部重定向的限制”
【发布时间】:2014-09-25 07:28:04
【问题描述】:

关于这个问题有很多线程。但没有一个是我的具体问题。

我们的设置介绍:我们在端口 80 上运行 Nginx,它位于 Apache 前面的端口 8889 上。

我们没有对 Nginx 或 Apache 进行任何更改,而且这种设置已经运行了一段时间。这就是为什么我们为从今天早上开始突然发生的事情而摸不着头脑。我们现在在我们的网站上收到 500 个错误。

通过查看日志,我想它们不是由 Nginx 引起的,而是由 Apache 引起的:

[Fri Aug 01 23:08:33 2014] [error] [client 100.99.98.97] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/
[Fri Aug 01 23:08:33 2014] [debug] core.c(3112): [client 100.99.98.97] r->uri = /beta/actionize, referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/
[Fri Aug 01 23:08:33 2014] [debug] core.c(3118): [client 100.99.98.97] redirected from r->uri = /beta/actionize, referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/
[Fri Aug 01 23:08:33 2014] [debug] core.c(3118): [client 100.99.98.97] redirected from r->uri = /beta/actionize, referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/
[Fri Aug 01 23:08:33 2014] [debug] core.c(3118): [client 100.99.98.97] redirected from r->uri = /beta/actionize, referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/
[Fri Aug 01 23:08:33 2014] [debug] core.c(3118): [client 100.99.98.97] redirected from r->uri = /beta/actionize, referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/
[Fri Aug 01 23:08:33 2014] [debug] core.c(3118): [client 100.99.98.97] redirected from r->uri = /beta/actionize, referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/
[Fri Aug 01 23:08:33 2014] [debug] core.c(3118): [client 100.99.98.97] redirected from r->uri = /beta/actionize, referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/
[Fri Aug 01 23:08:33 2014] [debug] core.c(3118): [client 100.99.98.97] redirected from r->uri = /beta/actionize, referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/
[Fri Aug 01 23:08:33 2014] [debug] core.c(3118): [client 100.99.98.97] redirected from r->uri = /beta/actionize, referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/
[Fri Aug 01 23:08:33 2014] [debug] core.c(3118): [client 100.99.98.97] redirected from r->uri = /beta/actionize, referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/
[Fri Aug 01 23:08:33 2014] [debug] core.c(3118): [client 100.99.98.97] redirected from r->uri = /beta/actionize, referer: http://somedomain.com/acordes/2011/01/entre-palos-y-alegrias/

在这个域的.htaccess文件中,我们有如下代码:

Options -Indexes +FollowSymLinks -MultiViews
DirectoryIndex index index.php index.htm index.html
DefaultType application/x-httpd-php

RewriteEngine On

# If someone types just the folder name
RewriteRule ^beta$ http://%{HTTP_HOST}/beta/index [L,R=301]

# If someone types the correct file, just show it
RewriteRule ^beta/(.*)$ /beta/$1 [L]

# All other URLs..
RewriteCond %{REQUEST_URI} !^(mailman|pipermail|w3c)/
RewriteRule ^(.*)$ /beta/get?u=$1 [L,QSA]

逻辑很简单。对于根目录中的所有 .htm 等文件,我们只显示它们。对于以/beta/[xyz] 开头的任何 URL,我们还会显示该文件,因为它存在于根文件夹的硬“beta”文件夹中。

但是对于以我们的域开头的所有其他 URL,我们希望将代码转发到 /beta/get?,参数是 URI 的那一部分。

例如,如果有人键入:http://EXAMPLE.com/xyz123,我们实际上希望在内部重定向到:http://EXAMPLE.com/beta/get?u=xyz123

(除了mailman或pipermail等用于我们特定邮件列表的词)

仅供参考,NGINX.CONF 文件如下:

#-------------------- START ------------------#
http {

  server_name_in_redirect       off;
  server_names_hash_max_size    10240;
  server_names_hash_bucket_size 1024;

  gzip on;
  gzip_static           on;
  gzip_disable          "MSIE [1-6]\.";
  gzip_vary             on;
  gzip_proxied          any;
  gzip_comp_level       5;  # Not a huge compression beyond this..so save CPU cycles
  gzip_buffers          16 8k;
  gzip_http_version     1.1;
  gzip_types            text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/png image/gif image/jpeg;

  connection_pool_size        256;
  client_header_buffer_size   256k;
  large_client_header_buffers 4 256k;
  client_max_body_size        200M; 

  client_body_buffer_size       128k;
  request_pool_size             64k;
  output_buffers                16 256k;

  open_file_cache               max=5000 inactive=20s; 
  open_file_cache_valid         60s; 

  include                       mime.types;
  default_type                  application/octet-stream;

  error_log                     logs/error.log warn;
  access_log                    off;
  server_tokens                 off; 
  autoindex                     off; 
  sendfile                      off;
  ignore_invalid_headers        on;    # Malware protection
  reset_timedout_connection     on;    # DDoS protection

  # Timeouts
  client_header_timeout         5;
  client_body_timeout           50;
  send_timeout                  50;
  keepalive_timeout             65;   # No need for default 65, but having some keepalive speeds things up
  resolver_timeout              1s;

  proxy_cache_path /dev/shm/proxy_cache levels=1:2 keys_zone=proxyone:200m inactive=1h max_size=2g;
  proxy_cache_key "$scheme$host$request_uri$cookie___snippa$cookie___sniplang";

  proxy_cache             proxyone;
  proxy_cache_min_uses    5;         
  proxy_cache_valid       any 60s;   
  proxy_cache_valid       200 1m; 
  proxy_cache_valid       404 0s;    
  proxy_cache_valid       410 90d;   
  proxy_cache_valid       500 502 503 504 1s;

  proxy_cache_valid       301 60m;
  proxy_ignore_headers    X-Accel-Expires Expires Cache-Control;


set_real_ip_from   192.168.1.0/24;
set_real_ip_from   192.168.2.1;
set_real_ip_from   127.0.0.1;
real_ip_header     X-Real-IP;


  server
  {
    listen 127.0.0.1:80;
    listen 74.86.191.114:80;
    listen 100.99.98.97:80;
    listen 75.126.161.225:80;
    listen 75.126.161.226:80;
    listen 10.17.32.66:80;

    server_name     EXAMPLE.com   www.EXAMPLE.com;

    root /home/EXAMPLE/public_html;
    index index.htm index.php index index.htm;

    error_page 403 = @backend;
    error_page 404 = @backend;
    error_page 405 = @backend;
    error_page 406 = @backend;
    error_page 500 = @backend;
    error_page 501 = @backend;
    error_page 502 = @backend;
    error_page 503 = @backend;
    error_page 504 = @backend;
    error_page 505 = @backend;


    # IMPORTANT FILES 
    location = /\.htaccess        { deny all; access_log off; log_not_found off; }
    location ~ /\.ht              { deny all; access_log off; log_not_found off; }
    location = /favicon.ico       { log_not_found off; access_log off; expires  max; }
    location = /robots.txt        { allow all; log_not_found off; access_log off; expires  max; }
    location = /sitemap.gz        { allow all; log_not_found off; access_log off; expires  max; }
    location = /crossdomain.xml   { allow all; log_not_found off; access_log off; expires  max; }


    location / {

      location ~.*\.(gif|jpg|png|ico|swf|rss|xml|htm|txt|js|css|gz|doc|xls|pdf|html|woff|eot|svg)$   {
        expires         max;
        try_files       $uri    @backend;
        log_not_found   off; 
      }

      proxy_pass http://100.99.98.97:8889;
      include proxy.inc;
    }

    location @backend {
      internal;
      proxy_pass http://100.99.98.97:8889;
      include proxy.inc;
    }

  }  # End of EXAMPLE.COM server block 


} # End of http block 

这可能是什么原因造成的? apache 中的loglevel debug 似乎没有多大帮助。非常感谢任何建议或指示!

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect nginx


    【解决方案1】:

    您的规则正在导致循环。重写引擎一遍又一遍地重新应用所有规则,直到 URI 停止更改。尝试添加更多限制:

    Options -Indexes +FollowSymLinks -MultiViews
    DirectoryIndex index index.php index.htm index.html
    DefaultType application/x-httpd-php
    
    RewriteEngine On
    
    # If someone types just the folder name
    RewriteRule ^beta/?$ http://%{HTTP_HOST}/beta/index [L,R=301]
    
    # If someone types the correct file, just show it
    RewriteRule ^beta/(.+)$ /beta/$1 [L]
    
    # All other URLs..
    RewriteCond %{REQUEST_URI} !^(mailman|pipermail|w3c|beta)/
    RewriteRule ^(.*)$ /beta/get?u=$1 [L,QSA]
    

    即,在/beta 的末尾添加一个可选的/,一个+ 而不是*,以确保/ 之后至少有一个字符,并将beta 添加到最后一条规则的条件。

    【讨论】:

    • 谢谢。我现在将这些移至httpd.conf 而不是.htaccess。这里所有的RewriteRules前面加一个“/”可以吗?
    • 是的,在非目录中,baded 规则需要一个 / 在前面
    猜你喜欢
    • 2013-10-04
    • 1970-01-01
    • 2019-03-08
    • 2018-03-18
    • 2013-06-07
    • 1970-01-01
    • 1970-01-01
    • 2014-08-05
    • 2017-06-01
    相关资源
    最近更新 更多