因为网站的访问量愈来愈大,用户播放视频,都要从web服务器拿文件,并且又是动态链接,要调用一个php-cgi进程,这样的话很浪费资源,因此要加缓存服务器。可是问题来了,squid 默认是不缓存动态页面的,google 了半天,发现不少人的文章没有一个说到正点上的。最后本身不停的作测试,看squid.conf.documented,把问题解决了,因此就记录下来,以便之后你们遇到一样的问题。好解决。 列子:php
http://www.nginxs.com/nginx/Grec.php?id=eric&b.php?=aaa
首选用 curl 抓 head头。html
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 对应的部分nginx
# 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.confweb
nginx $> vim /usr/local/squid/etc/squid.conf # 添加以下: acl nginx urlpath_regex ^/nginx/Grec.php acl QUERY urlpath_regex cgi-bin \? \.php no_cache allow nginx 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 而后访问网站查看 日志vim
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/- p_w_picpath/jpeg
1282112874.919 176 xxx.xxx.xx.xxx TCP_MEM_HIT/200 155673 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- p_w_picpath/jpeg
1282112874.946 203 xxx.xxx.xx.xxx TCP_MEM_HIT/200 237069 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- p_w_picpath/jpeg
1282112874.948 225 xxx.xxx.xx.xxx TCP_MEM_HIT/200 228811 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- p_w_picpath/jpeg
1282112874.973 230 xxx.xxx.xx.xxx TCP_MEM_HIT/200 195373 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- p_w_picpath/jpeg
1282112874.985 242 xxx.xxx.xx.xxx TCP_MEM_HIT/200 241978 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- p_w_picpath/jpeg
1282112875.021 197 xxx.xxx.xx.xxx TCP_MEM_HIT/200 201420 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- p_w_picpath/jpeg
1282112875.032 185 xxx.xxx.xx.xxx TCP_MEM_HIT/200 259924 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- p_w_picpath/jpeg
1282112875.046 160 xxx.xxx.xx.xxx TCP_MEM_HIT/200 226011 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- p_w_picpath/jpeg
1282112875.071 176 xxx.xxx.xx.xxx TCP_MEM_HIT/200 256656 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- p_w_picpath/jpeg
1282112875.106 177 xxx.xxx.xx.xxx TCP_MEM_HIT/200 223641 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- p_w_picpath/jpeg
1282112875.125 167 xxx.xxx.xx.xxx TCP_MEM_HIT/200 223972 GET http://www.nginxs.com/nginx/Grec.php? - NONE/- p_w_picpath/jpeg