首页 > squid > squid 缓存动态连接

squid 缓存动态连接

2010年8月27日 eric 发表评论 阅读评论

由于网站的访问量越来越大,用户播放视频,都要从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

分类: squid 标签: , ,
  1. 2010年8月29日20:05 | #1

    I would like to exchange links with your site

  2. 2010年9月14日16:18 | #2

    一楼的还说起洋文了,想换链接就直接说了。。

  3. 2010年9月15日16:22 | #3

    这位仁兄?

  4. 2011年6月13日09:39 | #4

    Thanks for you sharing.That is good article.I like it.

  5. 2011年6月13日09:40 | #5

    I read with great interest.Thanks for you sharing.

  6. 2011年6月13日09:41 | #6

    Your article looks great!Thanks for you sharing. I love it.

  7. 2011年6月20日17:07 | #7

    This information is useful to us.That is very kind of you to write this share for us, thanks a lot.

  8. 2011年8月2日16:21 | #8

    I will keep your new article. I really enjoyed reading this post, thanks for sharing.

  9. 2011年8月2日16:24 | #9

    The article is very good, I like it very much.

您必须在 登录 后才能发布评论.