我用Lua模块制作了一个反向图像代理服务器。 我发现“位置”中的lua块之后,无论我设置了什么代理设置,都可以进行一些测试。
当我尝试删除所有Lua块并且proxy_cache运行良好
proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=my_cache:10m max_size=1g inactive=60s use_temp_path=off;
lua_package_path '/usr/local/openresty/lualib/?/init.lua;;';
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/local/openresty/nginx/html;
index index.html index.htm;
}
location /mongo3 {
resolver 172.31.0.2 ipv6=off;
set $cdn "";
add_header Cache-Control "public, max-age=60";
proxy_cache my_cache;
proxy_cache_methods GET;
proxy_cache_key "$scheme$request_method$host$request_uri";
proxy_cache_valid 200 302 304 5m;
proxy_cache_valid 404 1m;
rewrite_by_lua_block{
mongol = require "resty.mongol"
conn = mongol:new()
conn:set_timeout(3000)
ngx.sleep(1) #-- this is for test --
ok,err = conn:connect()
local db = conn:new_db_handle('products')
... extract from database ...
ngx.var.cdn = 'http://cdn.com'..r["goto"]
}
proxy_pass $cdn;
}
完成上述设置后,由于“ ngx.sleep(1)”,总是会响应1秒以上
如何设置“命中高速缓存”时忽略“ rewrite_by_lua_block”?