首先编辑php.ini,修改zlib.output_compression 为On

然后编辑httpd.conf,取消注释以下两个模块

LoadModule deflate_module modules/mod_deflate.so

LoadModule filter_module modules/mod_filter.so

接下来在httpd.conf文件最下面加入:

<Directory />
Header set Access-Control-Allow-Origin *
Header set Access-Control-Allow-Methods *
Header set Access-Control-Allow-Headers *
</Directory>
<IfModule mod_deflate.c>
DeflateCompressionLevel 9
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
AddOutputFilter DEFLATE css js
</IfModule>
SetOutputFilter DEFLATE
 
# Set the path to the directory where you wish to apply the gzip compression
# Usually you would like to apply that to the entire htdocs folder, but you can change it
<Directory "C:/xampp/htdocs"> 
    <IfModule mod_deflate.c>
        # Add any file type you want
        AddOutputFilterByType DEFLATE text/html
    </IfModule>
</Directory>

C:/xampp/htdocs为你要开启gzip压缩的web目录,改为你自己的目录即可

最后修改:2023 年 03 月 06 日
如果觉得我的文章对你有用,请随意赞赏