简介:此缓存设置用到了第三方模块purge,使用的时候就在源链接和访问的具体内容之间加入关键字"/purge/"即可。
如:访问http://192.168.0.1/a.png 会生成a.png的缓存文件;
只要通过http://192.168.0.1/purge/a.png就可以将生成的缓存清除掉了。
一、获取安装包
获取安装包: wget http://nginx.org/download/nginx-1.7.9.tar.gz
获取缓存清理模块: wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
二、安装nginx
[[email protected]]# tar -xvzf nginx-1.7.9.tar.gz [[email protected]]# tar -zxvf ngx_cache_purge-2.3.tar.gz [[email protected]]# cd nginx-1.7.9 [[email protected]]# ./configure --prefix=/usr/local/nginx \ --add-module=../ngx_cache_purge-2.3 [[email protected]]# make[[email protected]]# make install
三、配置nginx(主要添加加粗字体部分)
[[email protected]]cd /usr/local/nginx [[email protected]]vi ./conf/nginx.conf
用加粗字体替换掉原来的部分
worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; client_body_buffer_size 512k; proxy_connect_timeout 10; proxy_read_timeout 180; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; proxy_temp_path /home/mpeg/cache_n/temp; proxy_cache_path /home/mpeg/cache_n levels=1:2 keys_zone=content:20m inactive=1d max_size=100m; keepalive_timeout 65; server {
listen 8055; server_name localhost; location / { proxy_cache content; proxy_cache_valid 200 302 304 206 24h; proxy_cache_valid any 1d; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_cache_key $host$uri$is_args$args; proxy_pass http://192.168.0.1:80; } location ~ /pure(/.*) { allow 192.0.0.0/24; deny all; proxy_cache_purge content $host$host$1$is_args$args; }
error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
四、说明
/********************************************* 此段为注释: ---------------------------------------------- client_body_buffer_size 512k; proxy_connect_timeout 10; proxy_read_timeout 180; proxy_send_timeout 5; proxy_buffer_size 16k; proxy_buffers 4 64k; proxy_busy_buffers_size 128k; proxy_temp_file_write_size 128k; proxy_temp_path /home/mpeg/cache_n/temp; //这个是临时缓存文件存放的路径 proxy_cache_path /home/mpeg/cache_n levels=1:2 keys_zone=content:20m inactive=1d max_size=100m; //这个路径是最终真实文件的缓存路径 keepalive_timeout 65; ------------------------------------------------------- location / { proxy_cache content; proxy_cache_valid 200 302 304 206 24h; //你要缓存的http状态码和它们的缓存时间 proxy_cache_valid any 1d; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_cache_key $host$uri$is_args$args; //缓存文件的命名规则 proxy_pass http://192.168.0.1:80; //nginx代理的服务器地址 } --------------------------------------------------------- location ~ /pure(/.*) { //这个location主要就是把url中带/pure/的链接筛选出来,然后执行我们刚才安装的那个第三方清理缓存的模块。 allow 192.0.0.0/24; deny all; proxy_cache_purge content $host$host$1$is_args$args; } **********************************************
时间: 2024-10-01 07:06:52