2014-01-10 57 views
1

我有一個配置我的Nginx + PHP-FPM 我在服務器部分由nginx的緩存 在HTTP部分Nginx的緩存和Yii的

fastcgi_cache_path /var/cache/nginx/ levels=1:2 keys_zone=nginx_webpy_cache:1m inactive=1d; 
fastcgi_temp_path /var/cache/nginx/temp; 

set $no_cache 0; 
    if ($request_method = POST) 
    { 
     set $no_cache 1; 
    } 
    #Don't cache if the URL contains a query string 
    if ($query_string != "") 
    { 
     set $no_cache 1; 
    } 
    #Don't cache the following URLs 
    if ($request_uri ~* "/(api/|login|logout|corporate/login|corporate/logout)") 
    { 
     set $no_cache 1; 
    } 
    #Don't cache if there is a cookie called PHPSESSID 
    if ($http_cookie = "PHPSESSID") 
    { 
     set $no_cache 1; 
    } 
location ~ \.php$ { 
     fastcgi_cache_bypass $no_cache; 
     fastcgi_no_cache $no_cache; 
     fastcgi_pass php-fpm; 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME /srv/www/site/index.php; 
     include fastcgi_params; 
     try_files $fastcgi_script_name =404; 
     fastcgi_cache nginx_webpy_cache; 
     fastcgi_cache_valid 200 301 302 304 2m; 
     fastcgi_cache_key "$request_method|$http_if_modified_since|$http_if_none_match|$host|$request_uri|$cookie_login_id"; 
     fastcgi_ignore_headers Cache-Control Expires Set-Cookie; 
     fastcgi_hide_header "Set-Cookie"; 
    } 

location ~* \.(ico|js|txt|jpg|jpeg|png|css|pdf)$ { 
     root /srv/www/site; 
     access_log off; 
     expires 1h; 
     add_header Pragma public; 
     add_header Cache-Control "public"; 
    } 

天色工作不錯,但我無法註銷,我註銷,仍然喜歡登錄用戶,如何解決它?

回答

0

不幸的是,在大多數情況下,您無法真正緩存使用服務器HTTP緩存進行身份驗證的任何頁面。例如,用戶在嘗試訪問他們自己的配置文件時(例如,除非您的網址真的具有獨特性,這通常不是最佳實踐),他們只會看到其他人的網頁。

解決方案將使用片段緩存,請參閱here以瞭解Yii特定的教程。