【问题标题】:Apache: can't find htaccess file to enable gzip compressionApache:找不到启用 gzip 压缩的 htaccess 文件
【发布时间】:2018-02-12 07:51:26
【问题描述】:

我尝试在 Apache 服务器上运行我的 react-app 的生产版本,但我意识到它没有使用 gzip 压缩。我不知道该怎么做。我尝试对网络广告进行研究,发现我需要为其更新 .htaccess 文件,但即使启用了隐藏文件,我也无法找到它。同一个 JS 文件在 React 的服务器上的大小约为 100KB,但它显示为400KB 在 Apache 的服务器上。

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    您应该在文档根目录中自己创建它,而不是在其中添加指令。例如:

    SetOutputFilter DEFLATE
    AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
    SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
    

    在 Apache website 上查看更多信息。

    【讨论】:

      【解决方案2】:

      在 StackOverflow 上尝试了所有答案后, this worked for me.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-07-07
        • 1970-01-01
        • 1970-01-01
        • 2013-12-29
        • 2012-03-04
        • 1970-01-01
        • 2014-04-10
        • 2021-11-03
        相关资源
        最近更新 更多