Apache Web服务器上启用GZIP,怎么弄?

2022-05-2910:44:45服务器及运维Comments1,519 views字数 1842阅读模式

如何在Apache Web服务器上启用GZIP?

据统计,Apache提供支持的网站数量超过当今使用的任何其他Web服务器。它也是WordPress推荐的两个Web服务器之一。要在Apache服务器上启用GZIP压缩,您需要使用其mod_filter和mod_deflate模块,并使用正确的指令正确配置它们。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/24010.html

Apache Web服务器上启用GZIP,怎么弄?

有两个方法来配置Apache的服务器

如果可以访问主服务器配置文件(httpd.conf),则建议使用它来配置Apache,因为.htaccess文件会降低Apache的速度,严格来说是sysadmins,因为共享主机很少允许您编辑主服务器配置文件。这种方法比较复杂适合熟悉Apache的专业人士。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/24010.html

如果您无法访问主服务器配置文件(大多数WordPress共享主机通常是这种情况),那么您需要使用.htaccess文件配置Apache 。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/24010.html

首先,请使用SFTP或主机的在线文件管理器在WordPress网站的根目录中找到.htaccess文件。然后将以下代码片段添加到其中。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/24010.html

<IfModule mod_deflate.c>
 # Compress HTML, CSS, JavaScript, Text, XML and fonts
 AddOutputFilterByType DEFLATE application/javascript
 AddOutputFilterByType DEFLATE application/rss+xml
 AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
 AddOutputFilterByType DEFLATE application/x-font
 AddOutputFilterByType DEFLATE application/x-font-opentype
 AddOutputFilterByType DEFLATE application/x-font-otf
 AddOutputFilterByType DEFLATE application/x-font-truetype
 AddOutputFilterByType DEFLATE application/x-font-ttf
 AddOutputFilterByType DEFLATE application/x-javascript
 AddOutputFilterByType DEFLATE application/xhtml+xml
 AddOutputFilterByType DEFLATE application/xml
 AddOutputFilterByType DEFLATE font/opentype
 AddOutputFilterByType DEFLATE font/otf
 AddOutputFilterByType DEFLATE font/ttf
 AddOutputFilterByType DEFLATE image/svg+xml
 AddOutputFilterByType DEFLATE image/x-icon
 AddOutputFilterByType DEFLATE text/css
 AddOutputFilterByType DEFLATE text/html
 AddOutputFilterByType DEFLATE text/javascript
 AddOutputFilterByType DEFLATE text/plain
 AddOutputFilterByType DEFLATE text/xml

 # Remove browser bugs (only needed for really old browsers)
 BrowserMatch ^Mozilla/4 gzip-only-text/html
 BrowserMatch ^Mozilla/4\.0[678] no-gzip
 BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 Header append Vary User-Agent
</IfModule>

要点:确保mod_filter模块在服务器上处于活动状态。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/24010.html

测试Apache服务器是否开启gzip

更改上传保存文件后,就需要来测试服务器是否开启了Gzip服务,这里,需要使用测试的网站giftofspeed来,输入你的网站,点击Check检查即可,稍等片刻,即可看到结果。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/24010.html

Apache Web服务器上启用GZIP,怎么弄?

总结

以上是如何在Apache Web服务器上启用GZIP压缩的方法,如果有任何问题,可以检查服务器的错误日志。文章源自菜鸟学院-https://www.cainiaoxueyuan.com/yunwei/24010.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/yunwei/24010.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定