Hello!
On Tue, Jan 14, 2014 at 6:27 PM, david.richardson wrote:
> I have a location that proxies to another server requiring custom
> information about the authenticated remote user.
> I would prefer to do this by adding a header to the request:
> proxy_set_header X-Authenticated-User-ID $http_x_authenticated_user_id;
> X-Authenticated-User-ID is set in an access_by_lua.
>
I've tested the following minimal example for your use case on my side
and it works perfectly:
location = /t {
access_by_lua '
ngx.req.set_header("X-Authenticated-User-ID", "12345")
';
proxy_pass http://127.0.0.1:$server_port/fake;
proxy_set_header X-Authenticated-User-ID $http_x_authenticated_user_id;
}
location = /fake {
echo "received header in /fake: $http_x_authenticated_user_id";
}
Accessing /t gives
$ curl localhost:8080/t
received header in /fake: 12345
I'm using nginx 1.5.8 with ngx_lua 0.9.4 on Linux x86_64.
> I've been unsuccessful reading the custom header in my proxied location
> block - it appears that location blocks are processed before the access
> phase.
> Is this correct?
>
No, it's not the case.
access_by_lua runs in the "access" phase, which is always *before* the
"content" phase where ngx_proxy runs.
Regards,
-agentzh