Forum: NGINX X-Accel-Redirect doen't work with php pages

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Daniele M. (Guest)
on 2009-05-27 19:39
(Received via mailing list)
Hi all,

i tried using X-Accel-Redirect as described on this guide:
http://blog.kovyrin.net/2006/11/01/nginx-x-accel-r...

If i use this conf:
daniele@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@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;
  }
}

Daniele
Kiril A. (Guest)
on 2009-05-28 00:20
(Received via mailing list)
cat test.php?
Daniele M. (Guest)
on 2009-05-28 11:20
(Received via mailing list)
Kiril A. ha scritto:
> cat test.php?

I didn't add because it doesn't work with any php pages, test.php is a
simple php pages:
daniele@lara:/var/www$ cat test.php
<? echo "test (from PHP)"; ?>
daniele@lara:/var/www$
Igor S. (Guest)
on 2009-05-28 13:42
(Received via mailing list)
On Wed, May 27, 2009 at 05:28:56PM +0200, Daniele M. wrote:

> ?>
> internal redirect to "/test.php" while reading response header from
>     index  index.html index.htm;
>
>               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.
This topic is locked and can not be replied to.