apache 开启Gzip网页压缩

下面就是就是要讲解如何开启gzip压缩;
实例环境:
服务器:centos6.5
apche:2.2.15
gzip压缩需要 deflate_module和headers_module的支持;
系统默认就是开启的;
需要做的是在httpd.conf配置项添加规则;

[root@iZ28qa8jt4uZ conf]# vim /etc/httpd/conf/httpd.conf  #修改配置项
#在最后边添加如下内容
<Location />
     AddOutputFilterByType DEFLATE text/plain
     AddOutputFilterByType DEFLATE text/css
     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 text/html
</Location>
[root@iZ28qa8jt4uZ conf]# service httpd restart    #重启apache

ok就这么简单即可;

通过站长工具来查看:http://tool.chinaz.com/Gzips

输入:http://byte.lovecoder.cn/结果为:

在这里插入图片描述
什么?你说你用的是虚拟空间;不能修改httpd.conf ?好吧,使用.htaccess总可以吧,好人做到底;在项目根目录下建一个.htaccess文件
里面添加如下内容:

<IfModule mod_deflate.c>
# Insert filters
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE image/svg+xml
# Drop problematic browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSI[E] !no-gzip !gzip-only-text/html
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary
</IfModule>

如果是自己的服务器还想使用.htaccess;那需要在httpd.conf 里面开启.htaccess;
修改httpd.conf的302行左右 AllowOverride None 改为 AllowOverride All:

<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>

还有大约340左右的AllowOverride None 改为 AllowOverride All:

AllowOverride All:

但是如果是自己的服务器;
尽量修改http.conf;
而不是使用.htaccess;
因为开启.htaccess后apache每次都要检测.htaccess文件会稍微降低httpd服务器的性能。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

泡在网上的蜘蛛

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值