因爲網站的訪問量愈來愈大,用戶播放視頻,都要從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