Thanks. Is it possible to do a proxy_pass to a different location? I tried proxy_pass to a different location and that didn't work.
On Wednesday, June 7, 2017 at 11:11:14 PM UTC-7, tokers wrote:
Hi
Let's suppose that you have two location A and B, in the location A, you can set some directives about proxy_cache and proxy_pass to location B, the location B is where you can use content_by_lua generating contents.
Frankly, i don't think this is a good solution. :(
On Wednesday, June 7, 2017 at 9:19:27 AM UTC+8, Gaurav Saxena wrote:
Hi,
I am doing some calculation in a location that generates content using 'content_by_lua'. I would like this calculation to be cached for a period of time. I have tried couple things but none of those work. I would appreciate any insight you have to make this work.
proxy_cache_path /tmp/cache levels=1:2 keys_zone=my_cache:8m max_size=30m inactive=2m;
server {
listen 9001;
location /test {
proxy_cache my_cache;
proxy_cache_valid 200 2m;
proxy_cache_min_uses 1;
proxy_cache_key "fooo";
proxy_ignore_headers Expires Cache-Control;
content_by_lua '
local res = ngx.location.capture("/main")
ngx.status = res.status
ngx.print(res.body)
';
more_set_headers "X-Cache-Status: $upstream_cache_status";
}
location /main {
proxy_cache my_cache; # this line is crucial or the cache will be disabled!
proxy_cache_valid 200 2m;
proxy_cache_min_uses 1;
proxy_cache_key "roooo";
proxy_ignore_headers Expires Cache-Control;
content_by_lua '
local res = ngx.location.capture("/index.html")
ngx.status = res.status
for key, value in pairs(res.header) do
ngx.log (ngx.NOTICE, "copying header key:"..key.." value="..value)
ngx.header[key] = value
end
ngx.say("time :", ngx.now())
ngx.say("cache-status: ", res.header["X-Cache-Status"])
ngx.print(res.body)
';
expires 2m;
}
location /index.html {
return 200 "hoooofooookoooo";
}
}
Both /main and /test are not doing any caching and for every request I can see the updated time. I am not sure what I am doing wrong.