参考链接: Apache如何开启Gzip压缩

编辑httpd.conf,先确保模块加载正常

1
2
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so

然后在最后添加

1
2
3
4
5
6
7
8
<IfModule deflate_module>
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|doc|avi|mov|mp3|rm)$ no-gzip dont-vary
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>

重启 Apache

1
sudo service httpd restart