Hello!
On Fri, Sep 7, 2012 at 8:09 AM, Jane C wrote:
> Thanks a lot for introducing me to openresty-en mailing list. Looks like I
> need to join the group before I can post any comment. I'll do it late
> today.
>
You can post to the list without subscription but your posts will
require group admins' moderation. You're very welcome to join though
;)
> The log_subrequest works. However I want to have the original request (its
> url) in log and don't need the subrequest to be logged.
> I tried your alternative method. I added "set $cache_status
> $upstream_cache_status;" in location /sub (or /main) and use $cache_status
> in log_format, still no cache status appeared in log file. Not sure why
> the $cache_status can't be shared between /main and /sub.
>
Nginx variables are not shared between the Nginx subrequests and their
parents in ngx_lua by default. You need to explicitly assign the value
of $upstream_cache_status from the subrequest (via your custom
subrequest response header) to the nginx variable in your main
request.
Here is a complete example:
location /main {
set $my_cache_status '';
content_by_lua '
local res = ngx.location.capture("/sub")
local cache_status = res.header["X-Cache-Status"]
ngx.var.my_cache_status = cache_status -- assign to
$my_cache_status here!
ngx.say("cache-status: ", cache_status) ';
}
}
location /sub {
proxy_cache static; # this line is crucial or the cache will
be disabled!
proxy_pass http://127.0.0.1:$server_port/index.html;
more_set_headers "X-Cache-Status: $upstream_cache_status";
}
location /index.html {
expires 10d;
}
Still cc'ing the openresty-en mailing list :)
Best regards,
-agentzh