lightweight proxy cache with nginx + ngx_cache_purge [centos 6.5]
yum install zlib-devel
yum install pcre-devel
wget http://labs.frickle.com/files/ngx_cache_purge-2.1.tar.gz
tar -zxvf ngx_cache_purge-2.1.tar.gz
wget http://nginx.org/download/nginx-1.6.0.tar.gz
tar -zxvf nginx-1.6.0.tar.gz
cd nginx-1.6.0
./configure --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-proxy-temp-path=/var/nginx/tmp --add-module=../ngx_cache_purge-2.1
make && make install
vi /etc/nginx/nginx.conf
#example
proxy_cache_path /var/nginx/cache levels=1:2 keys_zone=static:10m max_size=1000m inactive=720m;
proxy_temp_path /var/nginx/cache/tmp;
proxy_cache_key "$scheme://$host$request_uri";
server {
listen 80;
server_name caznova.org *.caznova.org;
index index.html index.htm index.php;
access_log off;
proxy_cache static;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $host;
proxy_ignore_headers Set-Cookie;
proxy_ignore_headers Cache-Control;
add_header X-Cache-Status $upstream_cache_status;
location ~* ^/(jQueryAssets|images|css|js|jscripts|flash)/(.*)$ {
proxy_cache_min_uses 1;
proxy_cache_valid 200 301 302 120m;
proxy_cache_valid 404 1m;
expires max;
proxy_pass http://backend:80;
}
location ~ /purge(/.*) {
proxy_cache_purge static "$scheme://$host$1";
}
location / {
proxy_no_cache 1;
proxy_cache_bypass 1;
proxy_pass http://backend:80;
}
}
#init.d autostart
http://wiki.nginx.org/InitScripts
#example clear cache
origin path : http://caznova.org/css/text.css
url = http://caznova.org/purge/css/text.css
ไม่มีความคิดเห็น:
แสดงความคิดเห็น