nginx , apache 缓存 和压缩


nginx

  
  http内 
       
  gzip    on;
  gzip_min_length   1k;
  gzip_buffers   4 8k;
  gzip_http_version  1.1;
  gzip_types   text/plain application/x-javascript text/css  application/xml;
  gzip_disable "MSIE [1-6]\.";
  
  
  server 内
  
   location ~ .*\.(gif|jpg|png|htm|html|css|js|flv|ico|swf)(.*) {
              proxy_pass http://appserver;
              proxy_redirect off;
              proxy_set_header Host $host;
              proxy_cache cache_one;
              proxy_cache_valid 200 302 1h;
              proxy_cache_valid 301 1d;
              proxy_cache_valid any 1m;
              expires 30d;
        }


apache

        <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
        </IfModule>
        <IfModule mod_expires.c>
        # ----------------------------------------------------------------------
        # Expires headers (for better cache control)
        # ----------------------------------------------------------------------
         
        # Enable expirations
        ExpiresActive On
        ExpiresByType image/jpg "access 1 year"
        ExpiresByType image/jpeg "access 1 year"
        ExpiresByType image/gif "access 1 year"
        ExpiresByType image/png "access 1 year"
        ExpiresByType text/css "access 1 month"
        ExpiresByType text/html "access 1 month"
        ExpiresByType application/pdf "access 1 month"
        ExpiresByType text/x-javascript "access 1 month"
        ExpiresByType text/css "access plus 1 year"
        ExpiresByType application/x-shockwave-flash "access 1 month"
        ExpiresByType image/x-icon "access 1 year"
        ExpiresDefault "access 1 month"
        </IfModule>
         
         
        <IfModule mod_headers.c>
          <FilesMatch "\.(js|css|xml|gz)$">
            Header append Vary: Accept-Encoding
          </FilesMatch>
        </IfModule>
         
        <IfModule mod_gzip.c>
        mod_gzip_on Yes
        mod_gzip_dechunk Yes
        mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
        mod_gzip_item_include handler ^cgi-script$
        mod_gzip_item_include mime ^text/.*
        mod_gzip_item_include mime ^application/x-javascript.*
        mod_gzip_item_exclude mime ^image/.*
        mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
        </IfModule>
         
        <IfModule mod_deflate.c>
        SetOutputFilter DEFLATE
        AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml text/x-js text/js 
        </IfModule>



暂无留言,赶快评论吧

欢迎留言