Forum: NGINX Internal redirects to upstream

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.
B9340b8cfd6b4038536e58327ef648c9?d=identicon&s=25 Arvind Jayaprakash (Guest)
on 2009-05-06 20:33
(Received via mailing list)
Is it possible to do an internal redirect to another url within nginx?

Say I access url "/u1" which is handled by an upstream server. I need to
be able to return a redirect to url "/u2" which is not a file but needs
to be sent back to the upstream server (possibly different from the
first one).

X-Accel-Redirect seems to be for cases when /u2 maps to a file.
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2009-05-06 21:00
(Received via mailing list)
Hello!

On Wed, May 06, 2009 at 11:54:50PM +0530, Arvind Jayaprakash wrote:

> Is it possible to do an internal redirect to another url within nginx?
>
> Say I access url "/u1" which is handled by an upstream server. I need to
> be able to return a redirect to url "/u2" which is not a file but needs
> to be sent back to the upstream server (possibly different from the
> first one).
>
> X-Accel-Redirect seems to be for cases when /u2 maps to a file.

No, X-Accel-Redirect just accepts uri and does internal redirect.
It has no knowledge of how /u2 will be handled - by static module,
proxy module, fastcgi or whatever.

Maxim Dounin
B9340b8cfd6b4038536e58327ef648c9?d=identicon&s=25 Arvind Jayaprakash (Guest)
on 2009-05-06 21:55
(Received via mailing list)
On May 06, Maxim Dounin wrote:
>>
>> X-Accel-Redirect seems to be for cases when /u2 maps to a file.
>
>No, X-Accel-Redirect just accepts uri and does internal redirect.
>It has no knowledge of how /u2 will be handled - by static module,
>proxy module, fastcgi or whatever.

Excellent.

Can any response headers sent by /u1 be transferred as request headers
when making the request to /u2 ?
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2009-05-06 23:57
(Received via mailing list)
Hello!

On Thu, May 07, 2009 at 01:19:28AM +0530, Arvind Jayaprakash wrote:

> >> first one).
> when making the request to /u2 ?
Any upstream response headers are available as $upstream_http_*.
But they will be cleared as soon as upstream module in /u2 will
start working, so you have to save them somewhere at rewrite
phase, e.g.:

    location /u2 {
        set $v $upstream_http_x_my_header;
        proxy_set_header X-My-Header $v;
        proxy_pass ...
    }

Maxim Dounin
This topic is locked and can not be replied to.