Aide spécifique à la redirection HTTP – “La requête a dépassé la limite de 10 redirections internes”

Il y a beaucoup de discussions sur ce problème. Mais aucun n’a mon problème spécifique.

Introduction à notre configuration: nous exécutons Nginx sur le port 80, qui se trouve devant Apache sur le port 8889.

Nous n’avons rien changé dans Nginx ou Apache, et cette configuration fonctionne depuis longtemps. C’est pourquoi nous nous gratons la tête pour ce qui est arrivé soudainement à ce début de matinée. Nous recevons maintenant 500 erreurs sur notre site Web.

En regardant le journal, je suppose qu’ils ne sont pas causés par Nginx, mais par 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/ 

Dans le fichier .htaccess de ce domaine, nous avons le code suivant:

 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] 

La logique est simple. Pour tous les fichiers qui sont au format .htm, etc., nous les affichons. Pour toute URL commençant par /beta/[xyz] nous /beta/[xyz] également le fichier tel qu’il existe dans le dossier “beta” du dossier racine.

Mais pour toutes les autres URL commençant par notre domaine, nous voulons transférer le code vers /beta/get? avec le paramètre étant cette partie de l’URI.

Exemple, si quelqu’un tape: http://EXAMPLE.com/xyz123 , nous voulons réellement redirect en interne vers: http://EXAMPLE.com/beta/get?u=xyz123

(Sauf lorsque les mots mailman ou pipermail, qui sont utilisés pour nos listes de diffusion spécifiques)

Juste pour info, le fichier NGINX.CONF est comme ci-dessous:

 #-------------------- 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 

Qu’est-ce qui pourrait causer cela? Le loglevel debug dans Apache ne semble pas aider beaucoup. J’apprécie beaucoup les conseils ou les conseils!

Vous êtes en train de créer une boucle. Le moteur de réécriture réapplique toutes les règles encore et encore jusqu’à ce que l’URI cesse de changer. Essayez d’append des restirctions supplémentaires:

 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] 

À savoir, une option / à la fin de just /beta , un + au lieu d’un * pour s’assurer qu’il y a au moins un caractère après le / , et append la beta aux conditions de la dernière règle.