nginx_cache_multipurge
nginx_cache_multipurge copied to clipboard
Example 1: Mimic the commercial cache_purge doesn't work
When trying to implement cache with example 1, the server always returns response 200 without the content, and when trying to purge the content, the server always returns response 403. And after checking example 1, cmp_run_if
variable not found in the location /
, was it intentional?
My environment:
Debian 10 Nginx 1.17.10
Please help.
The variable cmp_run_if
should be available in the location if the map is in the same location than in the examples. I could confirm this in tests.
Regarding the example, after some tests I think it might be incorrect and that the proxy_pass
directive has to go after the content_by_lua
call.
I have the same issue with Nginx 1.18.0
After moving proxy_pass after content_by_lua the content load succesfully. However executing curl -XPURGE http://ip-address/path is passing the PURGE request to my backend
Please find my full config
nginx.conf
map $request_method $cmp_run_if {
default 0;
PURGE 1;
}
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=my-awesome-cache:8m;
vhosts
location / {
proxy_cache my-awesome-cache;
proxy_cache_key $scheme$host$uri$is_args$args;
set $cmp_cache_key $scheme$host$uri$is_args$args;
set $cmp_cache_path "/data/nginx/cache";
content_by_lua_file /etc/nginx/lua/cache_multipurge.lua;
proxy_pass http://small_light_server;
}
I also trying to remove all proxy_pass and proxy_key related just to check. And it seems I found error
2020/08/25 06:50:36 [error] 9324#9324: *118 lua entry thread aborted: runtime error: /usr/local/luajit/share/lua/5.1/md5.lua:20: attempt to call field 'sum' (a nil value)
stack traceback:
coroutine 0:
/usr/local/luajit/share/lua/5.1/md5.lua: in function 'sumhexa'
/etc/nginx/lua/cache_multipurge.lua:75: in function 'purge_one'
/etc/nginx/lua/cache_multipurge.lua:94: in main chunk, client: 192.168.0.10, server: my.domain.com, request: "PURGE /assets/fonts/font.woff2 HTTP/1.1", host: "my.domain.com"