如何启用mod_deflate模块的PHP文件?模块、文件、mod_deflate、PHP

2023-09-02 20:36:27 作者:小丸子の专属脸蛋

我有一个液体的Web VPS帐户,mod_deflate模块已安装并运行,我确信/主动。

我用gzip压缩我通过PHP的CSS和JS文件,以及我的PHP文件本身。不过,我现在尝试通过mod_deflate模块要做到这一点,似乎很好地工作的所有文件,除了PHP文件。 (TXT文件做工精细,CSS,JS,静态HTML文件,它通过一个PHP文件生成根本不值一提。)我怎么解决这个问题?

(我用的网站优化中的cPanel,这在主目录下创建一个.htaccess文件(没有的public_html,高于一级)了的COM preSS的所有内容选项完全相同的文字作为COM preSS以外的所有图像的例子的http://的httpd .apache.org /文档/ 2.0 / MOD / mod_deflate.html )

.htaccess文件:

 < IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    < IfModule mod_setenvif.c>
        #Netscape 4.x版本有一些问题...
        BrowserMatch ^的Mozilla / 4 GZIP只-text / html的

        #网景4.06-4.08有一些更多的问题
        BrowserMatch ^的Mozilla / 4  .0 [678]无GZIP

        #MSIE伪装成Netscape的,但它是精细
        #BrowserMatch  bMSIE!没有GZIP!GZIP只-text / html的

        #注:由于在mod_setenvif错误最多的Apache 2.0.48
        #上述正则表达式将无法正常工作。您可以使用以下
        #解决方法,以获得预期的效果:
        BrowserMatch  BMSI [E]!没有GZIP!GZIP只-text / html的

        #不要COM preSS图片
        SetEnvIfNoCase REQUEST_URI。(?: GIF |?JPE G | PNG)$无gzip的不要,各不相同
    < / IfModule>

    < IfModule mod_headers.c>
        #请确保代理不提供错误的内容
        头追加因人而异用户代理包膜=!不,变化
    < / IfModule>
< / IfModule>
 

解决方案

这已经有一段时间,因为我张贴了这个问题 - 我最终通过的php.ini使zlib的COM pression所以zlib的COM presses PHP输出而mod_deflate模块COM presses一切。

我想这是不工作的原因(mod_deflate模块不COM pressing PHP输出),是因为有PHP运行的CGI,而不是Apache的DSO ...

I have a Liquid Web VPS account, I've made sure that mod_deflate is installed and running/active.

怎样把index.htm转化成index.php 然后怎样在转换后的php文件里边加一段PHP代码

I used to gzip my css and js files via PHP, as well as my PHP files themselves... However, I'm now trying to do this via mod_deflate, and it seems to work fine for all files except for PHP files. (Txt files work fine, css, js, static HTML files, just nothing that is generated via a PHP file.) How do I fix this?

(I used the "Compress all content" option under "Optimize Website" in cPanel, which creates an .htaccess file in the home directory (not public_html, one level higher than that) with exactly the same text as the "compress everything except images" example on http://httpd.apache.org/docs/2.0/mod/mod_deflate.html)

.htaccess file:

<IfModule mod_deflate.c>
    SetOutputFilter DEFLATE
    <IfModule mod_setenvif.c>
        # Netscape 4.x has some problems...
        BrowserMatch ^Mozilla/4 gzip-only-text/html

        # Netscape 4.06-4.08 have some more problems
        BrowserMatch ^Mozilla/4.0[678] no-gzip

        # MSIE masquerades as Netscape, but it is fine
        # BrowserMatch bMSIE !no-gzip !gzip-only-text/html

        # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
        # the above regex won't work. You can use the following
        # workaround to get the desired effect:
        BrowserMatch bMSI[E] !no-gzip !gzip-only-text/html

        # Don't compress images
        SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
    </IfModule>

    <IfModule mod_headers.c>
        # Make sure proxies don't deliver the wrong content
        Header append Vary User-Agent env=!dont-vary
    </IfModule>
</IfModule>

解决方案

It's been a while since I posted this question - I ended up enabling zlib compression via PHP.ini so zlib compresses PHP output while mod_deflate compresses everything else.

I'm thinking the reason it wasn't working (mod_deflate wasn't compressing PHP output) has to do with PHP running as CGI and not an Apache DSO...