Nginx+fastcgi_cache 配置magento缓存

废话不多说,直接上配置文件

server {
    listen       81;
    server_name  localhost;
    root  /opt/dev/workspace/magento17; ## App folder
    index  index.php;
    
    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires  max;
        access_log  off;
        log_not_found  off;
    }
 
    location / {
        #try_files  $uri @fcgi_cache;
        if ( -f $request_filename){
                 expires 30d;
                 break;
         }
         
        if ( !-e $request_filename ){
                rewrite ^(.*) /index.php last;//这个是配置所有的非静态文件请求都重定向到index.php
        }

	#if ($cookie_frontend) { return 413; }
        #if ($cookie_CUSTOMER_AUTH) { return 413; }
        #if ($request_method = POST ) { return 413; }
        #error_page 413 = @fcgi_nocache;
    }
    
    # Deny access to hidden files
    location ~ (/(app/|includes/|/pkginfo/|var/|report/config.xml)|/\.svn/|/.hta.+) {
        deny  all;
    }
    
    # Forward paths like /js/index.php/x.js to relevant handler
    location ~ .php/ {
        rewrite ^(.*.php)/ $1 last;
    }

    location ~ \.php {
        set $nocache yes;
	
        if ( $request_uri ~ "^/product"){
                set $nocache "";
        }
	if ( $request_uri ~ "^/storyselect"){
		set $nocache "";
	}
	if ( $request_uri ~ "^/topic"){
                set $nocache "";
        }
	if ( $request_uri ~ "^/p\d+\.html"){
                set $nocache "";
        }
	if ( $request_uri ~ "^/hotnav"){
                set $nocache "";
        }
	if ( $request_uri ~ "^/filter"){
                set $nocache "";
        }
	if ( $request_uri ~ "^/mainfilter"){
                set $nocache "";
        }
	if ( $request_uri ~ "^/tagpl"){
                set $nocache "";
        }
        if ( $request_uri ~ "^/?$"){
                set $nocache "";
        }   
        if ( $request_uri ~ "^/index\.php/?\s*"){
                set $nocache "";
        }

        fastcgi_pass   127.0.0.1:3344;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        fastcgi_param SCRIPT_NAME  /index.php;
        include        fastcgi_params;

        fastcgi_cache  F;
        #fastcgi_cache_key  "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri"; ## Original
        fastcgi_cache_key  "$scheme$request_method$host$request_uri$http_if_modified_since$http_if_none_match";
        #fastcgi_cache_lock  on 5s; # NGINX 1.1.12
	
        fastcgi_cache_valid  200 301 302 304 1d;
	fastcgi_cache_valid all 3h;
	
        fastcgi_cache_min_uses  1;
        fastcgi_cache_valid  30m;
        fastcgi_cache_use_stale  updating error timeout invalid_header http_500;
        fastcgi_cache_bypass  $nocache;
        fastcgi_no_cache  $nocache;
	fastcgi_ignore_headers Cache-Control Expires Set-Cookie;
    }

    
    # Manually purge pages
    #location ~ /purge(/.*) {
    #    fastcgi_cache_purge MAGE "$scheme$request_method$host$1";
    #}  
}

正常情况下magento返回的页面,header中有cookie 而且 Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 ,所以nginx是不会缓存这些页面的,为了让nginx能缓存页面必须添加这么一句:fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

发布了120 篇原创文章 · 获赞 63 · 访问量 205万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览