X-Accel-Redirect doen't work with php pages

Igor Sysoev is at rambler-co.ru
Thu May 28 13:27:14 MSD 2009


On Wed, May 27, 2009 at 05:28:56PM +0200, Daniele Melosi wrote:

> Hi all,
> 
> i tried using X-Accel-Redirect as described on this guide:
> http://blog.kovyrin.net/2006/11/01/nginx-x-accel-redirect-php-rails/
> 
> If i use this conf:
> daniele at lara:/var/www$ cat down.php
> <?
> // And redirect user to internal location
> header("X-Accel-Redirect: /test.html");
> ?>
> 
> everything works fine but if i tried to call a php pages:
> daniele at lara:/var/www$ cat down.php
> <?
> // And redirect user to internal location
> header("X-Accel-Redirect: /test.php");
> ?>
> 
> with this error:
> [error] 18345#0: *30 rewrite or internal redirection cycle while 
> internal redirect to "/test.php" while reading response header from 
> upstream, client: 192.168.251.27, server: localhost, request: "GET 
> /down.php HTTP/1.1", upstream: "http://127.0.0.1:880/down.php"
> 
> this is my configuration:
> server {
> 	listen   80;
> 	server_name  localhost;
> 
> 	location / {
> 		root   /var/www/nginx-default;
> 		index  index.html index.htm;
> 	}
> 
> 	location ~* .php$ {
> 		proxy_pass         http://127.0.0.1:880;
> 	        proxy_redirect     off;
> 
>         	proxy_set_header   Host             $host;
>             	proxy_set_header   X-Real-IP        $remote_addr;
>             	proxy_set_header   X-Forwarded-For 
> $proxy_add_x_forwarded_for;
> 
>             	client_max_body_size       10m;
>             	client_body_buffer_size    128k;
> 
>             	proxy_connect_timeout      90;
>             	proxy_send_timeout         90;
>             	proxy_read_timeout         90;
> 
>             	proxy_buffer_size          4k;
>             	proxy_buffers              4 32k;
>             	proxy_busy_buffers_size    64k;
>             	proxy_temp_file_write_size 64k;
> 	}
> }

This is feature,

	proxy_pass         http://127.0.0.1:880;

sends to an upstream a client's original $request_uri, unless it has not been
changed by rewrite. The usual workaround using

	proxy_pass         http://127.0.0.1:880/;

but in "location ~* .php$" you can not use URI-part in proxy_pass.
You may use something like this:

 	location ~* .php$ {
 		proxy_pass         http://127.0.0.1:880;
        }

 	location ^~ /int/ {
 		proxy_pass         http://127.0.0.1:880/;
        }

And return "X-Accel-Redirect: /int/test.php"

I need to rethink proxy_pass on the analogy of root/alias.
Now proxy_pass unites semantics of root/alias in single directive:
1) "proxy_pass  host/dir/" has the alias semantics,
2) while "proxy_pass  host" has the root semantics.
3) and to complicate matters "proxy_pass $some_vars" uses a whole
   resulting as alias with regex captures: "alias /path/$1".

Probably, proxy_pass should be divided to proxy_pass and proxy_alias,
but I do not know how to name "proxy_pass $some_vars" semantics.


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list