apache配置页面压缩发送和cache机制

首先在配置文件保证下面module前面的#是去掉的

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

然后在配置文件的添加:

# for gzip
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI .(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI .(?:pdf|mov|avi|mp3|mp4|rm)$ no-gzip dont-vary
AddOutputFilterByType DEFLATE text
AddOutputFilterByType DEFLATE application/ms* application/vnd* application/postscript application/javascript application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php application/x-httpd-fastphp
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html

## for cache
ExpiresActive On
ExpiresDefault A604800
ExpiresByType text/css A3600
ExpiresByType text/html A3600
ExpiresByType application/x-javascript A3600
ExpiresByType image/gif “access plus 2 month”
ExpiresByType image/jpeg “access plus 2 month”
ExpiresByType image/png “access plus 2 month”
ExpiresByType image/x-icon “access plus 2 month”
ExpiresByType application/x-shockwave-flash A2592000
Header unset Pragma
FileETag None
Header unset ETag
Header unset Last-Modified
Header append Cache-Control “public”

或者将其加到 .htaccess文件中。

如果是Yii开发的web,可以使用:

'components'=>array(
        ......
        'cache'=>array(
            'class'=>'system.caching.CMemCache', )),

如果出现php抱怨memcache的扩展没有加载的问题,在centos下面使用下面的命令安装加载:

yum install php-pecl-memcache

(或者yum install php-pecl-memcached

service httpd reload

参考:

http://www.yulong89.com/apache.html

http://www.yed.info/archives/774.html

http://www.yiiframework.com/doc/guide/1.1/en/caching.overview

版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章出处,否则按侵权处理.

    分享到:

Leave a Reply

Your email address will not be published. Required fields are marked *