通过HTTP请求清除nginxcaching?

我有平常的

proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=drupal:16m; proxy_cache_key "$scheme$host$request_uri"; 

build立代理caching。 我应该如何configurationnginx以允许通过HTTP请求从caching中删除特定项目?

如果您正在尝试在Drupal上进行select性页面清除,那么我会build议您阅读本文,因为它有点长。

总结这里的主要步骤:

  1. 确保你的Nginx服务器上安装了ngx_cache_purge模块。
  2. 还必须安装php-curl模块(Debian / Ubuntu的php5-curl)必须安装在您的服务器上。
  3. 通过fastcgicachingpath定义caching以供使用
  4. 使用以下代码修改处理我们的Drupal请求的服务器位置:

     location = /index.php { include /etc/nginx/fastcgi_params; fastcgi_param SCRIPT_FILENAME /var/www/$host/drupal/index.php; fastcgi_hide_header X-Drupal-Cache; #optional fastcgi_hide_header Etag; #optional fastcgi_pass php; # Cache Settings set $nocache ""; if ($http_cookie ~ SESS) { #logged in users should bypass the cache set $nocache "Y"; } if ($request_uri ~ \? ) { # Purge doesn't handle query strings yet set $nocache "Y"; } fastcgi_cache mycache; fastcgi_cache_key $host$request_uri; fastcgi_cache_valid 200 301 1d; fastcgi_ignore_headers Cache-Control Expires; fastcgi_cache_bypass $nocache; fastcgi_no_cache $nocache; add_header X-nginx-Cache $upstream_cache_status; #optional expires epoch; } 
  5. 创build一个监听localhost接口上的随机端口的新服务器。

  6. 启用“清除”和“过期”模块,并将admin / settings / purge中的代理URL设置为"http://127.0.0.1:8888"

和你做完了!

文章的来源: 带有select性页面清除的nginxcaching