標籤:blog http io color ar os 使用 sp for
1.編譯安裝
安裝cache_purge模組,可以參考我寫的:http://bbs.linuxtone.org/thread-6875-1-1.html
nginx的server配置:
- server
- {
- listen 80;
- server_name 54yancheng.com www.54yancheng.com;
- #purge cache files
- location ~ /purge(/.*)
- {
- #設定只允許指定的IP或IP段才可以清除URL緩衝,加入你的squid伺服器的ip地址。
- allow 114.244.0.0/16;
- allow 192.168.0.0/16;
- deny all;
- proxy_cache_purge cache_one $host$1$is_args$args;
- error_page 405 =200 /purge$1; #處理squidclient purge的時候出現的405錯誤
- }
- #用if判斷$request_method是PURGE時,轉到/purge/這個location裡去處理
- if ( $request_method = "PURGE" ) {
- rewrite ^(.*)$ /purge$1 last;
- }
- #pass files
- location /
- {
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- proxy_pass http://54yancheng;
- }
- #cache files
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
- {
- add_header X-Cache HIT_from_www.54yancheng.com;
- proxy_cache cache_one;
-
- proxy_cache_valid 200 304 12h;
- proxy_cache_valid 301 302 1m;
- proxy_cache_valid any 1m;
-
- proxy_cache_key $host$uri$is_args$args;
- proxy_set_header Host $host;
- proxy_set_header X-Forwarded-For $remote_addr;
- proxy_pass http://54yancheng;
- expires 365d;
- access_log off;
- }
- #web log
- #access_log off;
- access_log /data/logs/access_www.54yancheng.com.log combined;
- }
複製代碼
2.squidclient清除樣本:
- # squidclient -h 192.168.0.111 -p 80 -m PURGE -v http://www.54yancheng.com/ads/6739984.gif
- headers: ‘PURGE http://www.54yancheng.com/ads/6739984.gif HTTP/1.0
- Accept: */*
- ‘
- HTTP/1.1 200 OK
- Server: Nginx
- Date: Mon, 13 Sep 2010 03:05:02 GMT
- Content-Type: text/html
- Content-Length: 290
- Connection: close
- <html>
- <head><title>Successful purge</title></head>
- <body bgcolor="white">
- <center><h1>Successful purge</h1>
- <br>Key : www.54yancheng.com/ads/6739984.gif
- <br>Path: /data/cache/nginx_cache/3/6d/e70fbe8e578b27440e8f2e60269966d3
- </center>
- <hr><center>Apache</center>
- </body>
- </html>
複製代碼
3.指令碼清查多台同配置的nginx cache,並輸出狀態
在實際生產中,業務用多台nginx的cache做叢集實現負載平衡,這個指令碼就是實現清除多nginx伺服器cahce的功能。
- #!/bin/sh
- #利用squidclient的PURGE清除多nginx伺服器cache指令碼
- #bbs:www.linuxtone.org
- #by:hamgua
- echo "nginx purge $1"
- echo "----------------------------"
- for i in {1..3};do
- echo "host:192.168.0.$i"
- echo "status:`/usr/local/squid2/bin/squidclient -h 192.168.0.$i -p 80 -m PURGE -v $1 2>&1 |grep "^<center>"|awk -F‘[><]‘ ‘{print $5}‘`"
- echo "----------------------------"
- done
複製代碼
指令碼使用樣本:
- # ./purge.sh http://www.54yancheng.com/ads/6739984.gif
複製代碼
- nginx purge http://www.54yancheng.com/ads/6739984.gif
- ----------------------------
- host:192.168.0.1
- status:Successful purge
- ----------------------------
- host:192.168.0.2
- status:404 Not Found
- ----------------------------
- host:192.168.0.3
- status:404 Not Found
- ----------------------------
複製代碼
參考文章:
安裝配置參考我寫的:http://bbs.linuxtone.org/thread-6875-1-1.html
squidclient清除nginx cache,參考sudone的文章:http://sudone.com/nginx/nginx_cache_purge.html
linuxtone網站伺服器nginx版塊:http://bbs.linuxtone.org/forumdisplay.php?fid=22&filter=type&typeid=1
張宴 使用Nginx的proxy_cache緩衝功能取代Squid[原創] http://blog.s135.com/nginx_cache/
nginx cache 使用 【轉】