当前位置: 移动技术网 > 网络运营>服务器>Windows > 独立主机/VPS 一键开启IIS的GZIP方法

独立主机/VPS 一键开启IIS的GZIP方法

2019年06月01日  | 移动技术网网络运营  | 我要评论
windows服务器设置方法:
下载地址:
下载gzip批处理文件,解压到任意位置,双击运行iis6-set-gzip.cmd 即可迅速设置好gzip。
特别提示若您的网站启用了cdn技术,则请勿开启gzip功能,否则会导致用户端访问为空白的情况,设置好后,可以通过 来测试压缩结果,如图:

gzip可以压缩静态htm\html\css\js\asp\aspx\php 等格式文件,根据格式不同文件包含的内容不同,压缩率并不相同。

优点:可以加快网站访问速度,降低带宽的占用率。

缺点:会消耗更多的cpu资源压缩网页。

因此在您设置后如果您的cpu占用很高,请在iis--网站--属性--服务里,取消http压缩的勾,并重启iis。(建议:vps上超过10个站的不要开启该压缩功能)

 

压缩后的缓存文件会存放在c:\windows\iis temporary compressed files  因此建议在iis--网站--属性--服务,设置一个大小,避免c盘被占满了。如图:

linux服务器设置方法:

apache上利用gzip压缩算法进行压缩的模块有两种:mod_gzip 和mod_deflate。要使用gzip web压缩,请首先确定你的服务器开启了对这两个组件之一的支持。虽然使用gzip同时也需要客户端浏览器的支持,不过不用担心,目前大部分浏览器都已经支持gzip了,如ie、mozilla firefox、opera、chrome等。

通过查看http头,我们可以快速判断使用的客户端浏览器是否支持接受gzip压缩。

若发送的http头中出现以下信息,则表明你的浏览器支持接受相应的gzip压缩:

accept-encoding: gzip 支持mod_gzip
accept-encoding: deflate 支持mod_deflate
accept-encoding: gzip,deflate 同时支持mod_gzip 和mod_deflate

如果服务器开启了对gzip组件的支持,那么我们就可以在http.conf或.htaccess里面进行定制,下面是一个.htaccess配置的简单实例:

# mod_gzip:
<ifmodule mod_gzip.c>
mod_gzip_on yes
mod_gzip_dechunk yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude rspheader ^content-encoding:.*gzip.*
</ifmodule>

# mod_deflate:
<ifmodule mod_deflate.c>
deflatecompressionlevel 6 #压缩率, 6是建议值.
addoutputfilterbytype deflate text/plain
addoutputfilterbytype deflate text/html
addoutputfilterbytype deflate text/xml
addoutputfilterbytype deflate text/css
addoutputfilterbytype deflate text/javascript
addoutputfilterbytype deflate application/xhtml+xml
addoutputfilterbytype deflate application/xml
addoutputfilterbytype deflate application/rss+xml
addoutputfilterbytype deflate application/atom_xml
addoutputfilterbytype deflate application/x-javascript
addoutputfilterbytype deflate application/x-httpd-php
addoutputfilterbytype deflate image/svg+xml
</ifmodule>

里面的文件mime类型可以根据自己情况添加,至于pdf 、图片、音乐文档之类的这些本身都已经高度压缩格式,重复压缩的作用不大,反而可能会因为增加cpu的处理时间及浏览器的渲染问题而降低性能。所以就没必要再通过gzip压缩。

通过以上设置后再查看返回的http头,出现以下信息则表明返回的数据已经过压缩。即网站程序所配置的gzip压缩已生效。也可以通过 http://tool.chinaz.com/gzips/ 这里查询gzip是否压缩。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网