apache开启gzip压缩

来源:互联网 发布:htc一键解锁软件 编辑:程序博客网 时间:2024/06/12 01:42

1. yum install httpd -y 

2. vim /etc/httpd/conf/httpd.conf , 在配置的最后添加如下参数

<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
    SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary


    AddOutputFilterByType DEFLATE text/*
    AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript application/javascript application/x-javascript
    AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp


    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

3. 测试,如果你的apache使用的是 80 端口,本机运行 telnet  127.0.0.1  80


telnet 127.0.0.1 80
Trying 127.0.0.1...
Connected to proxy2 (127.0.0.1).
Escape character is '^]'.


输入:  

GET    /webroot/index.html    HTTP/1.1
HOST: hostname
Accept-Encoding: gzip,deflate,sdch

双击Enter键

有如下代码则表示开启成功

Content-Encoding: gzip



原创粉丝点击