Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7347140
  • 博文数量: 1763
  • 博客积分: 18684
  • 博客等级: 上将
  • 技术积分: 16217
  • 用 户 组: 普通用户
  • 注册时间: 2010-06-02 10:28
个人简介

啥也没写

文章分类

全部博文(1763)

文章存档

2023年(44)

2022年(39)

2021年(46)

2020年(43)

2019年(27)

2018年(44)

2017年(50)

2016年(47)

2015年(15)

2014年(21)

2013年(43)

2012年(143)

2011年(228)

2010年(263)

2009年(384)

2008年(246)

2007年(30)

2006年(38)

2005年(2)

2004年(1)

分类: 系统运维

2021-08-04 11:45:37

官方:
github.com/akin520/nginx_cache_file/
配置如下:

点击(此处)折叠或打开

  1. server {
  2.     listen 443; # 监听端口
  3.     server_name m.demo.cn; # 站点域名
  4.     root /xq_data/xq_web/demo/; # 站点根目录
  5.     index index.html index.htm index.php; # 默认导航页


  6.     ssl on;
  7.     ssl_certificate demo.cn.crt;
  8.     ssl_certificate_key demo.cn.key;

  9.     access_log /var/log/nginx_logs/m-cache.log main;

  10.     set $proxy "";

  11.     location / {
  12.         default_type text/html;
  13.         if ($request_method = PURGE) {
  14.             content_by_lua '
  15.                 local request_uri = ngx.var.request_uri;
  16.                 local tmp_file = string.gsub(request_uri,"/","_")
  17.                 local cache_file = string.gsub(tmp_file,"&","*")
  18.                 local cmd = "rm -rf /xq_data/cache/"..ngx.var.host.."/"..cache_file .. " 2>&1"
  19.                 os.execute(cmd)
  20.                 --- clear only key
  21.                 local md5 = ngx.md5
  22.                 local key = md5(request_uri)
  23.                 local cache_ngx = ngx.shared.my_cache
  24.                 cache_ngx:delete(key)
  25.                 ngx.header["Content-type"] = "text/plain; charset=utf-8"
  26.                 ngx.header["X-Purged-Count"] = "clear"
  27.                 ngx.header["X-CMD"] = cmd
  28.                 ngx.say("OK")
  29.             ';
  30.         }
  31.         content_by_lua_file /usr/local/nginx/vhost/cache_file.lua;
  32.         }

  33.         location = /m_404.html {
  34.             root /xq_data/xq_web/demo/demo;
  35.         }

  36.         error_page 404 /m_404.html;
  37. }

阅读(1536) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~