官方:
github.com/akin520/nginx_cache_file/
配置如下:
-
server {
-
listen 443; # 监听端口
-
server_name m.demo.cn; # 站点域名
-
root /xq_data/xq_web/demo/; # 站点根目录
-
index index.html index.htm index.php; # 默认导航页
-
-
-
ssl on;
-
ssl_certificate demo.cn.crt;
-
ssl_certificate_key demo.cn.key;
-
-
access_log /var/log/nginx_logs/m-cache.log main;
-
-
set $proxy "";
-
-
location / {
-
default_type text/html;
-
if ($request_method = PURGE) {
-
content_by_lua '
-
local request_uri = ngx.var.request_uri;
-
local tmp_file = string.gsub(request_uri,"/","_")
-
local cache_file = string.gsub(tmp_file,"&","*")
-
local cmd = "rm -rf /xq_data/cache/"..ngx.var.host.."/"..cache_file .. " 2>&1"
-
os.execute(cmd)
-
--- clear only key
-
local md5 = ngx.md5
-
local key = md5(request_uri)
-
local cache_ngx = ngx.shared.my_cache
-
cache_ngx:delete(key)
-
ngx.header["Content-type"] = "text/plain; charset=utf-8"
-
ngx.header["X-Purged-Count"] = "clear"
-
ngx.header["X-CMD"] = cmd
-
ngx.say("OK")
-
';
-
}
-
content_by_lua_file /usr/local/nginx/vhost/cache_file.lua;
-
}
-
-
location = /m_404.html {
-
root /xq_data/xq_web/demo/demo;
-
}
-
-
error_page 404 /m_404.html;
-
}
阅读(1742) | 评论(0) | 转发(0) |