【问题标题】:Not able to enable mod_deflate on Apache / CentOS7无法在 Apache / CentOS 7 中启用 mod_deflate
【发布时间】:2015-12-23 09:31:09
【问题描述】:

我遵循了一个来自良好来源的简单教程,但 gzip 压缩不起作用。

1) 我运行以下命令查看 mod_deflate 是否已经安装:

apachectl -t -D DUMP_MODULES | grep deflate

我得到了 deflate_module(共享),所以它就在那里。

2) 我创建了一个新文件 /etc/httpd/conf.d/mod_deflate.conf,内容如下:

<filesMatch "\.(js|html|css)$">
SetOutputFilter DEFLATE
</filesMatch>

我保存了它并运行 systemctl reload httpd.service。它不起作用,所以我运行 systemctl restart httpd.service。 Gzip 压缩仍然不起作用。

我用 apachectl -t 检查了 Apache 配置文件的语法,似乎一切正常。它仍然不起作用。

这可能是什么原因?我要检查什么?

谢谢。

【问题讨论】:

  • 如何检查压缩是否有效?您是否检查过错误日志中的任何错误消息?
  • 您如何验证它不起作用?您是否在 conf 文件中打错字,然后 apachectl -t 以验证 conf 文件是否已加载?你为什么不只使用 CentOS 的软件包来做这件事呢?
  • 我用两个在线工具CheckGzipCompression.comWhatsMyIp.org/http-compression-test 进行了检查。我还没有查看日志,那里可能有一些信息。我检查了拼写错误,一切都正确。
  • @Niels Keurentjes - 看起来为此的配置文件已加载。当我打错字并重新启动服务器时,它没有启动。我纠正了它,现在一切正常。

标签: apache gzip mod-deflate apache-modules


【解决方案1】:

我只添加了这一行,它有效:

AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript

【讨论】:

    猜你喜欢
    • 2016-11-12
    • 2018-09-02
    • 2020-07-09
    • 1970-01-01
    • 2017-06-23
    • 1970-01-01
    • 1970-01-01
    • 2018-02-12
    • 1970-01-01
    相关资源
    最近更新 更多