upcache
Version:
nginx proxy cache key protocols implementations
49 lines (41 loc) • 1.12 kB
Plain Text
location /.well-known/fetch {
internal;
content_by_lua_block {
local redis = require "resty.redis"
local red = redis:new()
red:set_timeouts(1000, 1000, 1000)
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
ngx.log(ngx.ERR, "Failed to connect to redis", err)
return
end
local res = red:get(ngx.var.query_string)
red:set_keepalive(10000, 100)
if res == ngx.null then
return ngx.exit(404)
end
ngx.print(res)
}
}
location /.well-known/store {
internal;
client_max_body_size 20M;
client_body_buffer_size 20M;
content_by_lua_block {
local redis = require "resty.redis"
local red = redis:new()
red:set_timeouts(1000, 1000, 1000)
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
ngx.log(ngx.ERR, "Failed to connect to redis", err)
return
end
ngx.req.read_body()
ok, err = red:set(ngx.var.query_string, ngx.req.get_body_data())
red:set_keepalive(10000, 100)
if not ok then
ngx.log(ngx.ERR, "Failed to store", err)
return ngx.exit(404)
end
}
}