squid 缓存动态连接
由于网站的访问量越来越大,用户播放视频,都要从web服务器拿文件,而且又是动态连接,要调用一个php-cgi进程,这样的话很浪费资源,所以要加缓存服务器。但是问题来了,squid 默认是不缓存动态页面的,google 了半天,发现很多人的文章没有一个说到正点上的。最后自己不停的做测试,看squid.conf.documented,把问题解决了,所以就记录下来,以便以后大家遇到同样的问题。好解决。
列子:
http://www.nginxs.com/nginx/Grec.php?id=eric&b.php?=aaa
首选用 curl 抓 head头。
nginx $> curl -I http://www.nginxs.com/nginx/Grec.php HTTP/1.1 200 OK Server: nginx Date: Fri, 27 Aug 2010 06:49:43 GMT Content-Type: text/html; charset=utf-8 Connection: keep-alive Vary: Accept-Encoding X-Powered-By: PHP/5.2.13 Set-Cookie: PHPSESSID=2d4523a7c6a5a54dbb20f64f3bc04be3; path=/ Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache
看红字部分,然后在看 squid.conf.documented 对应的部分
# options: override-expire # override-lastmod # reload-into-ims # ignore-reload # ignore-no-cache # ignore-no-store # ignore-must-revalidate # ignore-private # ignore-auth # refresh-ims #
把 Cache-Control 的信息,squid对应有违规则 那么我们修改 squid.conf
nginx $> vim /usr/local/squid/etc/squid.conf # 添加如下: acl duxiucache urlpath_regex ^/nginx/Grec.php acl QUERY urlpath_regex cgi-bin \? \.php no_cache allow duxiucache no_cache deny QUERY refresh_pattern -i ^http://www.nginxs.com/nginx/Grec.php 1440 50% 10080 override-expire override-lastmod reload-into-ims ignore-reload ignore-no-cache ignore-no-store ignore-must-revalidate
保存 重启 squid
然后访问网站查看 日志
nginx $> tailf /usr/local/squid/var/logs/access.log 1282112874.863 124 xxx.xxx.xx.xxx TCP_MEM_HIT/200 225990 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg 1282112874.919 176 xxx.xxx.xx.xxx TCP_MEM_HIT/200 155673 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg 1282112874.946 203 xxx.xxx.xx.xxx TCP_MEM_HIT/200 237069 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg 1282112874.948 225 xxx.xxx.xx.xxx TCP_MEM_HIT/200 228811 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg 1282112874.973 230 xxx.xxx.xx.xxx TCP_MEM_HIT/200 195373 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg 1282112874.985 242 xxx.xxx.xx.xxx TCP_MEM_HIT/200 241978 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg 1282112875.021 197 xxx.xxx.xx.xxx TCP_MEM_HIT/200 201420 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg 1282112875.032 185 xxx.xxx.xx.xxx TCP_MEM_HIT/200 259924 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg 1282112875.046 160 xxx.xxx.xx.xxx TCP_MEM_HIT/200 226011 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg 1282112875.071 176 xxx.xxx.xx.xxx TCP_MEM_HIT/200 256656 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg 1282112875.106 177 xxx.xxx.xx.xxx TCP_MEM_HIT/200 223641 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg 1282112875.125 167 xxx.xxx.xx.xxx TCP_MEM_HIT/200 223972 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- image/jpeg
转载请注明:文章转载自:Eric's linux and nginx! (http://www.nginxs.com)
本文地址:http://www.nginxs.com/linux/250.html
I would like to exchange links with your site
一楼的还说起洋文了,想换链接就直接说了。。
这位仁兄?
Thanks for you sharing.That is good article.I like it.
I read with great interest.Thanks for you sharing.
Your article looks great!Thanks for you sharing. I love it.
This information is useful to us.That is very kind of you to write this share for us, thanks a lot.
I will keep your new article. I really enjoyed reading this post, thanks for sharing.
The article is very good, I like it very much.