• apache 配置静态文件缓存和开启gzip压缩


    1,设置文件静态缓存3天:

    在httpd.conf 里添加如下代码:

    #文件静态缓存配置

      <IfModule expires_module>

        #打开缓存

        ExpiresActive on

        #文件缓存259200/3600/24=3天

        ExpiresByType text/css A259200

        ExpiresByType application/x-javascript A259200

        ExpiresByType application/javascript A259200

        ExpiresByType text/html A259200

        ExpiresByType image/jpeg A259200

        ExpiresByType image/gif A259200

        ExpiresByType image/png A259200

        ExpiresByType image/x-icon A259200

    </IfModule>

    测试在浏览器查看是否有:

    Cache-Control :max-age=259200

    有则成功

    2,开启gzip压缩

    在httpd.conf添加如下代码:

    <IfModule mod_deflate.c>
        SetOutputFilter DEFLATE    #必须的,就像一个开关一样,告诉apache对传输到浏览器的内容进行压缩
    
        SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary #设置不对后缀gif,jpg,jpeg,png的图片文件进行压缩
        SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary #同上,就是设置不对exe,tgz,gz。。。的文件进行压缩
        SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary
    
        AddOutputFilterByType DEFLATE text/* #设置对文件是文本的内容进行压缩,例如text/html  text/css  text/plain等
        AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript application/javascript application/x-javascript #这段代码你只需要了解application/javascript application/x-javascript这段就可以了,这段的意思是对javascript文件进行压缩
        AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp #这段是告诉apache对php类型的文件进行压缩
    
        BrowserMatch ^Mozilla/4 gzip-only-text/html # Netscape 4.x 有一些问题,所以只压缩文件类型是text/html的
        BrowserMatch ^Mozilla/4.0[678] no-gzip # Netscape 4.06-4.08 有更多的问题,所以不开启压缩
        BrowserMatch MSIE !no-gzip !gzip-only-text/html # IE浏览器会伪装成 Netscape ,但是事实上它没有问题
    </IfModule>

    在站长之家测试下即可看到是否成功!
  • 相关阅读:
    array and ram
    char as int
    pointer of 2d array and address
    Install SAP HANA EXPRESS on Google Cloud Platform
    Ubuntu remount hard drive
    Compile OpenSSL with Visual Studio 2019
    Install Jupyter notebook and tensorflow on Ubuntu 18.04
    Build OpenCV text(OCR) module on windows with Visual Studio 2019
    Reinstall VirtualBox 6.0 on Ubuntu 18.04
    Pitfall in std::vector<cv::Mat>
  • 原文地址:https://www.cnblogs.com/hxyphp/p/4422965.html
Copyright © 2020-2023  润新知