Special headers and X-Accel-Redirect

António P. P. Almeida appa at perusio.net
Mon Jun 6 18:40:20 MSD 2011


On 6 Jun 2011 15h33 WEST, kgorlo at gmail.com wrote:

> Ok,
>
> I've found solution (or workaround - if this is bug in nginx).
>
> I have to put:
>
> set $x_metadata $upstream_http_x_metadata;
>
> BEFORE
>
> rewrite ^/files(.*)$ $1 break;
>
> Could you please explain me why?

Because you're breaking the rewrite phase processing by issuing a
rewrite with a break. A break or return terminates the rewrite phase
so what you're saying to Nginx is: rewrite and do no more rewrite
phase processing on this location.

The set directive is part of the rewrite module which means that it's
processed during the rewrite phase. It's not a bug, it's the way it's
supposed to be.

        location /files {
            internal;
            rewrite ^/files(.*)$ $1 break; ## Stops rewrite phase processing here

            proxy_pass http://filestore;
            proxy_hide_header Content-Type;
            proxy_hide_header Content-Disposition;

            set $x_metadata $upstream_http_x_metadata;

            add_header X-metadata $x_metadata;
        }


So the solution is to place *all* rewrite phase directives that you
want to be processed before the rewrite with the break flag.

        location /files {
            internal;

            set $x_metadata $upstream_http_x_metadata;
            add_header X-metadata $x_metadata;

            rewrite ^/files(.*)$ $1 break;

            proxy_pass http://filestore;
            proxy_hide_header Content-Type;
            proxy_hide_header Content-Disposition;
        }

--- appa





More information about the nginx mailing list