apache - 特定 HTTP 重定向帮助 - "Request exceeded the limit of 10 internal redirects"

标签 apache .htaccess mod-rewrite redirect nginx

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

我们的设置简介:我们在端口 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 似乎没有多大帮助。非常感谢任何建议或指示!

最佳答案

您的规则导致了循环。重写引擎一遍又一遍地重新应用所有规则,直到 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 添加到最后一条规则的条件中。

关于apache - 特定 HTTP 重定向帮助 - "Request exceeded the limit of 10 internal redirects",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25091309/

相关文章:

php - 同时启用 PHP 解析器和 Include 语句

.htaccess - modrewrite - 将所有 php 文件转换为 html,这对 SEO 友好并且可以两种方式工作

reactjs - .htaccess 如何使用参数重定向到index.html,但参数值与文件夹名称相同

.htaccess - “noindex,nofollow”标题没有用htaccess设置

.htaccess - url重写mod_rewrite

php - 在此服务器上找不到请求的 URL/phpmyadmin/

apache - 如何编辑 .htaccess 文件以拒绝盗链到 .css、.inc 文件?

regex - 如何阻止对与 Apache 中常见模式匹配的 URL 的机器人请求?

ruby-on-rails - mod_passenger : Cannot connect to Unix socket 中的乘客意外错误

php - htaccess 和 css 文件