apache开启对gzip的支持丨技术开发分享录

apache开启对gzip的支持

{{ detail.nickname }}

转载 翻译 {{ formatTime(detail.create_time) }} 字数 {{ detail.content && detail.content.length }} 阅读 {{ detail.read_num }} {{ formatTag(v) }}

"修改 httpd.conf 配置\n\n去掉 #LoadModule headers_module modules/mod_headers.so 前面的注释#\n去掉 #LoadModule deflate_module modules/mod_deflate.so 前面的注释#\n去掉 #LoadModule filter_module modules/mod_filter.so 前面的注释#\n\n然后在底部追加如下配置即可\n\n```\n<ifmodule mod_deflate.c>\n      DeflateCompressionLevel 6\n      AddOutputFilterByType DEFLATE text/plain\n      AddOutputFilterByType DEFLATE text/html\n      AddOutputFilterByType DEFLATE text/php\n      AddOutputFilterByType DEFLATE text/xml\n      AddOutputFilterByType DEFLATE text/css\n      AddOutputFilterByType DEFLATE text/javascript\n      AddOutputFilterByType DEFLATE application/xhtml+xml\n      AddOutputFilterByType DEFLATE application/xml\n      AddOutputFilterByType DEFLATE application/rss+xml\n      AddOutputFilterByType DEFLATE application/atom_xml\n      AddOutputFilterByType DEFLATE application/javascript\n      AddOutputFilterByType DEFLATE application/x-javascript\n      AddOutputFilterByType DEFLATE application/x-httpd-php\n      AddOutputFilterByType DEFLATE application/x-font-ttf\n      AddOutputFilterByType DEFLATE image/svg+xml\n      AddOutputFilterByType DEFLATE image/gif image/png  image/jpe image/swf image/jpeg image/bmp\n      # Don’t compress images and other  #排除不需要压缩的文件\n      BrowserMatch ^Mozilla/4 gzip-only-text/html\n      BrowserMatch ^Mozilla/4\\.0[678] no-gzip\n      BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html\n      SetEnvIfNoCase Request_URI .(?:html|htm)$ no-gzip dont-varySetEnvIfNoCase \n      #SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary\n      SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary\n      SetEnvIfNoCase Request_URI .(?:pdf|doc)$ no-gzip dont-vary\n</ifmodule>\n```\n\n在\\.htaccess中的配置\n\n```\n<ifmodule mod_deflate.c>\n\t# 启用对特定MIME类型内容的压缩\n\tSetOutputFilter DEFLATE\n\t# 设置不压缩的文件\n\tSetEnvIfNoCase Request_URI .(?:gif|jpe?g|png|exe|t?gz|zip|bz2|sit|rar|pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary\n\t# 设置压缩的文件\n\tAddOutputFilterByType DEFLATE text/javascript\n\tAddOutputFilterByType DEFLATE text/html\n\tAddOutputFilterByType DEFLATE text/css\n\tAddOutputFilterByType DEFLATE text/plain\n\tAddOutputFilterByType DEFLATE text/xml\n\tAddOutputFilterByType DEFLATE application/json\n\tAddOutputFilterByType DEFLATE application/x-httpd-php\n\tAddOutputFilterByType DEFLATE application/javascript\n\tAddOutputFilterByType DEFLATE application/x-javascript\n</ifmodule>\n```\n\n配置后会优先使用同名的压缩文件返回到浏览器端,浏览器进行解压,由于文件体积减小了,从而大大提高了对文件的加载速度。"
PS:写作不易,如要转裁,请标明转载出处。

如果此篇对您有帮助,可小额赞助,以兹鼓励!

猜你想看