- 时间:2020-04-08 04:23 编辑: 来源: 阅读:
- 扫一扫,手机访问
摘要:nginx 1.0.0配ngx_cache_purge实现高效的反向代理
在功能上,Nginx已经具备Squid所拥有的Web缓存加速功能、清除指定URL缓存的功能。而在性能上,Nginx对多核CPU的利用,胜过Squid不少。另外,在反向代理、负载均衡、健康检查、后端服务器故障转移、Rewrite重写、易用性上,Nginx也比Squid强大得多。这使得一台Nginx可以同时作为“负载均衡服务器”与“Web缓存服务器”来使用。--by 张宴
下载2011-05-03更新的最新版1.3
wget [url=http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gz]http://labs.frickle.com/files/ngx_cache_purge-1.3.tar.gz[/url]
tar zxf ngx_cache_purge-1.3.tar.gz
切换到nginx目录
cd nginx-1.0.0
./configure --user=www --group=www --add-module=../ngx_cache_purge-1.3 --prefix=/usr/local/webserver/nginx --with-http_stub_status_module
make;make install
安装完成![url=http://www.1sucai.cn;/]http://www.1sucai.cn;[/url]
expires 1d;
}
location ~ /purge(/.*) {
allow all;
allow 127.0.0.1;
# deny all;
proxy_cache_purge cache_one $1$is_args$args;
}
access_log /www/logs/s.log access;
}
......
}
这样访问s.jb51.net/images/logo.gif,反向代理就会去请求[url=http://www.1sucai.cn/images/logo.gif]http://www.1sucai.cn/images/logo.gif[/url],保存在内存中,然后输出。
如果logo.gif这个文件发生了变化,则需要刷新缓存,访问s.jb51.net/purge/images/logo.gif,就会提示:Successful purge
Key : /images/logo.gif
Path: /www/proxy_cache/39aaa70038997e0e5e77beaa4392848d
如果这个文件没有被缓存过,则提示:404 Not Found
如果是已经安装过nginx了,请一定注意,使用nginx -s reload重启是无效的!一定要-s stop之后再启动,这样才会使用新版本的nginx!
我今天就没注意这点,在这上面化了N个小时!
/usr/local/webserver/nginx/sbin/nginx -V
nginx: nginx version: nginx/1.0.0
nginx: built by gcc 4.1.2 20080704 (Red Hat 4.1.2-46)
nginx: configure arguments: --user=www --group=www --add-module=../ngx_cache_purge-1.3 --prefix=/usr/local/webserver/nginx --with-http_stub_status_module
一直以为是装成功了,但反复测试均清除失败,很郁闷!明明开启了访问日志,日志也没记录任何信息!
晚上继续测试时,在nginx_error.log里看到有如下的错误提示:
2011/05/11 21:23:40 [emerg] 20976#0: unknown directive "proxy_cache_purge" in /usr/local/webserver/nginx/conf/nginx.conf:481
才确认这个模块跟本没装上,当然不能用了。后来在一个论坛看到一个人的回复说要restart,但reload是无效的。才想到前段搞nginx升级时就发现,如果不用make upgrade升级,重新编译升级的话,必须停掉,再启动才会使用新的版本!