<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GzV8.com &#187; Squid</title>
	<atom:link href="http://www.gzv8.com/archives/category/squid/feed" rel="self" type="application/rss+xml" />
	<link>http://www.gzv8.com</link>
	<description>互联网引擎</description>
	<lastBuildDate>Thu, 06 Jan 2011 04:08:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>squid配合nginx的gzip压缩的完美解决方案</title>
		<link>http://www.gzv8.com/archives/213</link>
		<comments>http://www.gzv8.com/archives/213#comments</comments>
		<pubDate>Thu, 11 Mar 2010 07:25:55 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Nginx]]></category>
		<category><![CDATA[Squid]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[压缩]]></category>

		<guid isPermaLink="false">http://www.gzv8.com/?p=213</guid>
		<description><![CDATA[Squid3.0之前，一直不能完美支持http1.1。所以对gzip内容的支持，始终有很多问题。我也看过很多帖子，号称解决了这个问题。但是其实一直没有把问题说清楚。我今天试着把问题的原因和解决方法彻底说清楚。
squid不支持常见的gzip压缩的原因，有以下两点:
1,   squid只支持gzip的静态压缩，不支持动态压缩。具体一点说，就是response header里必须有content-length, 不可以用chunked方式。
2,   response header中必须有Vary : Accept-Encoding
只要具备以上几点，squid就可以完美的识别压缩和不压缩的内容。
下面说一下nginx针对这个问题的解决方案:
nginx默认的NginxHttpGzipModule, 采用的是chunked方式的动态压缩，而squid是不支持的。需要使用http_gzip_static_module这个模块，进行pre-compress。
具体方法如下:
ngx_http_gzip_static_module was introduced in nginx 0.6.24. You must enable support at compile time:
./configure &#8211;with-http_gzip_static_module &#8230;
配置文件写法:
gzip          on
gzip_static on;
gzip_http_version 1.0;
gzip_proxied        any;
gzip_disable        &#8220;MSIE [1-6]\.&#8221;;
gzip_comp_level     9;
注意，这里没有加入gzip_vary on;。这是因为http_gzip_static_module这个模块，只给没压缩的内容加入了vary header，而不是所有内容都加。
所以不能打开这个参数。可以在nginx.conf中手动设置vary header。这样不管压缩与否，返回的文件都会被加上Vary: Accept-Encoding。
至此，nginx的gzip压缩，就能够被squid完美支持了。如果你使用Http1.0，就会返回你没压缩的内容。如果你使用http1.1，并且发送Accept-Encoding:gzip,deflate，就会返回压缩后的内容。
PS: 我又发现了一个问题，就是squid的cache保存问题。按照文档上说，squid是根据url来缓存对象的。
   也就是说，一个url应该只保留一个cache。如果你交替的申请压缩的和不压缩的内容，是会出现反复MISS的情况的。
   但是我实际测试的过程中，发现不是这样的，交替的申请压缩的和不压缩的内容，是会一直HIT的。这说明squid是同时保存两份cache的(压缩的和不压缩的)。
]]></description>
			<content:encoded><![CDATA[<p>Squid3.0之前，一直不能完美支持http1.1。所以对gzip内容的支持，始终有很多问题。我也看过很多帖子，号称解决了这个问题。但是其实一直没有把问题说清楚。我今天试着把问题的原因和解决方法彻底说清楚。</p>
<p>squid不支持常见的gzip压缩的原因，有以下两点:</p>
<p>1,   squid只支持gzip的静态压缩，不支持动态压缩。具体一点说，就是response header里必须有content-length, 不可以用chunked方式。</p>
<p>2,   response header中必须有Vary : Accept-Encoding</p>
<p>只要具备以上几点，squid就可以完美的识别压缩和不压缩的内容。</p>
<p>下面说一下nginx针对这个问题的解决方案:</p>
<p>nginx默认的NginxHttpGzipModule, 采用的是chunked方式的动态压缩，而squid是不支持的。需要使用http_gzip_static_module这个模块，进行pre-compress。</p>
<p>具体方法如下:</p>
<p>ngx_http_gzip_static_module was introduced in nginx 0.6.24. You must enable support at compile time:</p>
<p>./configure &#8211;with-http_gzip_static_module &#8230;</p>
<p>配置文件写法:</p>
<p>gzip          on</p>
<p>gzip_static on;</p>
<p>gzip_http_version 1.0;<br />
gzip_proxied        any;<br />
gzip_disable        &#8220;MSIE [1-6]\.&#8221;;</p>
<p>gzip_comp_level     9;</p>
<p>注意，这里没有加入gzip_vary on;。这是因为http_gzip_static_module这个模块，只给没压缩的内容加入了vary header，而不是所有内容都加。<br />
所以不能打开这个参数。可以在nginx.conf中手动设置vary header。这样不管压缩与否，返回的文件都会被加上Vary: Accept-Encoding。</p>
<p>至此，nginx的gzip压缩，就能够被squid完美支持了。如果你使用Http1.0，就会返回你没压缩的内容。如果你使用http1.1，并且发送Accept-Encoding:gzip,deflate，就会返回压缩后的内容。</p>
<p>PS: 我又发现了一个问题，就是squid的cache保存问题。按照文档上说，squid是根据url来缓存对象的。<br />
   也就是说，一个url应该只保留一个cache。如果你交替的申请压缩的和不压缩的内容，是会出现反复MISS的情况的。<br />
   但是我实际测试的过程中，发现不是这样的，交替的申请压缩的和不压缩的内容，是会一直HIT的。这说明squid是同时保存两份cache的(压缩的和不压缩的)。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gzv8.com/archives/213/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>批量更新 squid 缓存</title>
		<link>http://www.gzv8.com/archives/201</link>
		<comments>http://www.gzv8.com/archives/201#comments</comments>
		<pubDate>Thu, 11 Mar 2010 07:20:16 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Squid]]></category>
		<category><![CDATA[批量]]></category>
		<category><![CDATA[更新]]></category>
		<category><![CDATA[缓存]]></category>

		<guid isPermaLink="false">http://www.gzv8.com/?p=201</guid>
		<description><![CDATA[Squid 目录 bin 文件夹下有个 squidclient 的工具,用于查看缓存信息,更新缓存&#8230;.的功能..
使用的方法是：
./squidclient -r &#8220;http://www.gzxxx.cn/&#8221;
更多的参数使用,可以查看 ./squidclient -h
但如果遇上大批量的文件需要更新，例如一个文件夹下所有的图片。
用下边这个小脚本可以让你省事省心。
#!/bin/sh
squidcache_path=&#8221;/data/cache&#8221;  # Squid 的缓存目录
squidclient_path=&#8221;/usr/local/squid/bin/squidclient&#8221;  # squidclient 的路径
grep -a -r $1 $squidcache_path/* &#124; strings &#124; grep &#8220;http:&#8221; &#124; awk -F&#8217;http:&#8217; &#8216;{print &#8220;http:&#8221;$2;}&#8217; &#62; cache_list.txt
for url in `cat cache_list.txt`; do
$squidclient_path -m PURGE -p 3128 $url   # 3128 端口根据你squid的http 设置自行修改
done
############
把上边脚本内容存为 clear_squid_cache.sh 并赐予可执行权限
复制代码用法：
    然后在 squid.conf 中加入下边的配置并令其生效
 acl PURGE method PURGE
 http_access allow PURGE
 http_access [...]]]></description>
			<content:encoded><![CDATA[<p>Squid 目录 bin 文件夹下有个 squidclient 的工具,用于查看缓存信息,更新缓存&#8230;.的功能..</p>
<p>使用的方法是：</p>
<p>./squidclient -r &#8220;<a href="http://www.gzxxx.cn/">http://www.gzxxx.cn/</a>&#8221;</p>
<p>更多的参数使用,可以查看 ./squidclient -h</p>
<p>但如果遇上大批量的文件需要更新，例如一个文件夹下所有的图片。<br />
用下边这个小脚本可以让你省事省心。</p>
<p>#!/bin/sh</p>
<p>squidcache_path=&#8221;/data/cache&#8221;  # Squid 的缓存目录</p>
<p>squidclient_path=&#8221;/usr/local/squid/bin/squidclient&#8221;  # squidclient 的路径</p>
<p>grep -a -r $1 $squidcache_path/* | strings | grep &#8220;http:&#8221; | awk -F&#8217;http:&#8217; &#8216;{print &#8220;http:&#8221;$2;}&#8217; &gt; cache_list.txt</p>
<p>for url in `cat cache_list.txt`; do</p>
<p>$squidclient_path -m PURGE -p 3128 $url   # 3128 端口根据你squid的http 设置自行修改</p>
<p>done<br />
############</p>
<p>把上边脚本内容存为 clear_squid_cache.sh 并赐予可执行权限</p>
<p>复制代码用法：</p>
<p>    然后在 squid.conf 中加入下边的配置并令其生效</p>
<p> acl PURGE method PURGE<br />
 http_access allow PURGE<br />
 http_access deny PURGE</p>
<p>    最后使用脚本：</p>
<p>　　1、清除所有Flash缓存（扩展名.swf）：<br />
　　./clear_squid_cache.sh swf</p>
<p>　　2、清除URL中包含sina.com.cn的所有缓存：<br />
　　./clear_squid_cache.sh sina.com.cn</p>
<p>　　3、清除文件名为zhangyan.jpg的所有缓存：<br />
　　./clear_squid_cache.sh zhangyan.jpg</p>
]]></content:encoded>
			<wfw:commentRss>http://www.gzv8.com/archives/201/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

