php 如何在 XAMPP 服务器中启用 GZip 压缩

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6993320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 01:46:04  来源:igfitidea点击:

How to enable GZip compression in XAMPP server

phpwindowsapachexamppgzip

提问by linuxeasy

I am using xampp sever latest version to improve my web page performance.

我正在使用 xampp 服务器最新版本来提高我的网页性能。

I have to enable Gzip in XAMPP. How can it be done?

我必须在 XAMPP 中启用 Gzip。怎么做到呢?

回答by linuxeasy

You do compression by setting appropriate directive in apache.

您可以通过在 apache 中设置适当的指令来进行压缩。

It goes uncommenting the following lines in your apache conf file: C:\xampp\apache\conf\httpd.conf

它会取消对 apache conf 文件中的以下几行的注释:C:\xampp\apache\conf\httpd.conf

if your xampp installation folder is C:\xampp.

如果您的 xampp 安装文件夹是 C:\xampp。

and these are the lines to be uncommented first:

这些是首先要取消注释的行:

LoadModule headers_module modules/mod_deflate.so
LoadModule filter_module modules/mod_filter.so

that is to say, if they have # before them, you should remove them!

也就是说,如果它们前面有#,你应该删除它们!

Then put this at the end of your httpd.conf file:

然后把它放在你的 httpd.conf 文件的末尾:

SetOutputFilter DEFLATE 

<Directory "C:/your-server-root/manual">  #any path to which you wish to apply gzip compression to!
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/html  # or any file type you wish
    </IfModule>
</Directory> 

回答by luciole135

Everything what is said above does not work on my XAMPP version 1.8.1 (php 5.4.7).

上面所说的所有内容都不适用于我的 XAMPP 版本 1.8.1 (php 5.4.7)。

The only thing that works is to put on "On" instead of "Off" these line of the php.ini file:

唯一有效的是将 php.ini 文件的这些行置于“On”而不是“Off”:

zlib.output_compression = On

回答by TarranJones

Find apache\conf\httpd.conf

找到 apache\conf\httpd.conf

uncomment the following line(remove #)

取消注释以下行(删除#)

LoadModule headers_module modules/mod_deflate.so

some versions may require you to comment out the following lines instead.

某些版本可能需要您注释掉以下几行。

LoadModule headers_module modules/mod_headers.so
LoadModule deflate_module modules/mod_deflate.so

finally add this line to your .htaccess file.

最后将此行添加到您的 .htaccess 文件中。

SetOutputFilter DEFLATE

回答by Johan Bové

Not sure why you have this code:

不知道为什么你有这个代码:

LoadModule headers_module modules/mod_deflate.so

But that didn't work for me, it returned an APACHE error on Apache/2.4.3 (Win32):

但这对我不起作用,它在 Apache/2.4.3 (Win32) 上返回了 APACHE 错误:

12:57:10  [Apache]  Error: Apache shutdown unexpectedly.
12:57:10  [Apache]  This may be due to a blocked port, missing dependencies, 
12:57:10  [Apache]  improper privileges, a crash, or a shutdown by another method.

I Had to use:

我不得不使用:

LoadModule deflate_module modules/mod_deflate.so