簡體   English   中英

Nginx Cache和Yii

[英]Nginx Cache and Yii

我為Nginx + php-fpm進行了配置,並在http部分進行了nginx緩存

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";
    }

大多數情況下都可以,但是我無法注銷,我仍然注銷並且仍然像登錄用戶一樣,該如何解決?

不幸的是,在大多數情況下,您無法真正通過服務器HTTP緩存在身份驗證下緩存任何頁面。 例如,用戶在嘗試訪問自己的個人資料時,只會看到別人的頁面(除非您的URL確實與眾不同,這通常也不是最佳實踐)。

解決方案是使用片段緩存,有關Yii的專用教程,請參見此處

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM