Problem with rewrite or internal redirection cycle

Maxim Dounin mdounin at
Thu Jul 19 14:28:06 UTC 2012


On Wed, Jul 18, 2012 at 11:55:49AM -0400, drakerc wrote:

> Hello
> I have recently moved my website from Litespeed to nginx. I had to
> change some lines in my PHP script to use x-sendfile function and
> because of it I also had to change my nginx config. Unfortunately, when
> I'm executing my PHP script, I receive 500 Internal Server Error. My
> error.log says:
> 2012/07/18 17:39:52 [error] 23510#0: *20011855 rewrite or internal
> redirection cycle while internal redirect to "/index.php", client:
>, server:, request: "GET [...]
> I'm not sure what's causing this problem and how to fix it and I really
> need your help.

Your config with your script produce an infinite loop.  Most likely 
it's due to fact that after X-Accel-Redirect request ends up in 
location /, and then redirected to /index.php as file isn't found, 
and then again after X-Accel-Redirect request ends up in location 
/ and so on.

>         location / {
>         client_max_body_size 1024m;
>         try_files $uri $uri/ /index.php?q=$uri&$args;


> location /downloads {
> internal;
> }


> My PHP script snippet that uses x-sendfile:
> $filename_directoo = '/'.$cat_dir.'/'.$file_url;
> header("X-Accel-Redirect:".$filename_directoo);
> header('Content-Disposition: attachment; filename="'.$filename.'"');

It looks like "location /downloads" was added to avoid the above 
loop, but you don't refer it in X-Accel-Redirect.

Maxim Dounin

More information about the nginx mailing list