Apache服务启用Gzip压缩传输网页,所说可以提高传输效率,但会增强服务器负担。 系统CentOS,Apache该加载的模块都已经默认加载了,但默认并未开启Gzip压缩。

编辑/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>

然后重启下httpd服务,如果服务没报错,应该是成功启用了Gzip功能了,可以登录http://tool.chinaz.com/Gzips网站检测下。确实成功了,显示如下: apache_gzip

Related content