Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


subrequest proxy cache #125

biancalana opened this Issue · 7 comments

2 participants



First, thank you for this awesome nginx module !

I'm writting some lua code to intercept all requests, dispatching then to a proxy cache internal location and make account of request rate, response status and cache status.

Everything is working except that cache isn't working.

Follow my nginx.conf:

worker_processes 1;

error_log /var/log/nginx-error.log debug;

events {
worker_connections 1024;

http {
include mime.types;

log_format full '$remote_addr $remote_user [$time_local] ' '"$host"->$proxy_host->$upstream_addr ' '"$request" $status($upstream_status) ' '$bytes_sent/$gzip_ratio($sent_http_content_type) ' '$request_time($upstream_response_time) ' '$upstream_cache_status';

access_log /var/log/nginx-access.log full;

sendfile on;
keepalive_timeout 65;

proxy_buffering on;
proxy_buffer_size 8k;
proxy_buffers 256 8k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_temp_path /opt/nginx/cache/tmp;
proxy_cache_path /opt/nginx/cache/ levels=1:2:2 keys_zone=STATIC:1000m inactive=1d max_size=4g;

location / {

default_type 'text/plain';

content_by_lua '

ngx.ctx.nuri = "/PROXY" .. ngx.var.request_uri;

local res = ngx.location.capture("/PROXY" .. ngx.var.request_uri,
                                                               { share_all_vars = true});

ngx.log(ngx.ERR, "cache_status(", ngx.var.upstream_cache_status, ")")


location /PROXY {

rewrite_by_lua 'local uri =, "^/PROXY/(.*)", "/$1", "o")


When a request is issued, the subrequest is done and the request hit the backend but ngx.var.upstream_cache_status variable is still empty... I can see that the response from the backend is begin stored in cache directory, but the subsequent requests are not served from cache and still hit the backend

I had never done anything like that and don't know if it's supposed to work, anybody has already did something like ?


Hi agentzh!

I tried to put:

    more_set_headers "X: $upstream_cache_status";

inside /PROXY (subrequest) location and fetch res.headers["X"] in parent location but it´s still does not work...


Thank you for the suggestion, I had to recompile to meet this "order" but that still does not work.


Any updates on this issue?


Consider it resolved.

@agentzh agentzh closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.