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

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5cf83bed3cc81f9190504721d6103287?d=identicon&s=25 Daniele Melosi (Guest)
on 2009-05-27 17:39
(Received via mailing list)
Hi all,

i tried using X-Accel-Redirect as described on this guide:

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:, server: localhost, request: "GET
/down.php HTTP/1.1", upstream: ""

this is my configuration:
server {
  listen   80;
  server_name  localhost;

  location / {
    root   /var/www/nginx-default;
    index  index.html index.htm;

  location ~* .php$ {
          proxy_redirect     off;

           proxy_set_header   Host             $host;
               proxy_set_header   X-Real-IP        $remote_addr;
               proxy_set_header   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;

7f006226eff37eaa07b1e8b96f521cb2?d=identicon&s=25 Kiril Angov (Guest)
on 2009-05-27 22:20
(Received via mailing list)
cat test.php?
5cf83bed3cc81f9190504721d6103287?d=identicon&s=25 Daniele Melosi (Guest)
on 2009-05-28 09:20
(Received via mailing list)
Kiril Angov 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)"; ?>
5640e332954fc0006aea97a155ce0afd?d=identicon&s=25 Igor Sysoev (Guest)
on 2009-05-28 11:42
(Received via mailing list)
On Wed, May 27, 2009 at 05:28:56PM +0200, Daniele Melosi 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,


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


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

   location ~* .php$ {

   location ^~ /int/ {

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.