Fastcgi_hide_header仅在缓存处于活动状态时处于活动状态

时间:2019-02-19 22:22:44

标签: nginx reverse-proxy fastcgi nginx-location

我试图在我的网站上设置一个缓存,该缓存对于某些页面是活动的,而对于其他页面是无效的。 PHP cookie会话用于登录和论坛,因此它们必须在某些页面上处于活动状态

我所拥有的是一张地图,该地图确定了缓存应在哪些页面上激活:

map $request_uri $skip_cache {
    default 1;
    ~^/index.php 0;
    / 0;
    ~^/objects 0;
    ~^/places 0;
    ~^/articles 0;
}

然后在服务器块中,我调用地图以标识服务器在哪个页面上处于活动状态。

我还有另一个地图引用了第一个地图,以标识我们是否应该输出cookie:

map $skip_cache $cache_cookie_ignore {
    default "";
    1 "";
    0 "Set-Cookie";
}

最后,服务器块具有缓存详细信息,并且还引用了两个映射,以确定我们是否应该忽略cookie,以及是否应该缓存页面

server {
      listen 80;
      listen [::]:80;
      #set the domains these rules work on
      server_name domain.com
      staging.azurewebsites.net;
      root /home/site/wwwroot; ## <-- Your only path $
      error_log /home/logfiles/nginx/error.log;


    location / {
        try_files $uri $uri/ $uri.html @php;
    }
    location @php {         
        rewrite ^(/[^/]+)$ $1.php last;
        rewrite ^(/[^/]+)/(.*)$ $1.php?q=$2 last;
    }

    #general server settings
    location ~ \.php$  {
          try_files $uri =404;
          include fastcgi_params;
          fastcgi_pass unix:/run/php/php7.0-fpm.sock;
          fastcgi_split_path_info ^(.+?\.php)(/.*)?$;
          fastcgi_connect_timeout         300; 
          fastcgi_send_timeout           3600; 
          fastcgi_read_timeout           3600;
          fastcgi_buffer_size 128k;
          fastcgi_buffers 4 256k;
          fastcgi_busy_buffers_size 256k;
          fastcgi_temp_file_write_size 256k;
          fastcgi_intercept_errors on; 
          fastcgi_index index.php;
          fastcgi_param SCRIPT_FILENAME /home/site/wwwroot$fastcgi_script_name;

          fastcgi_cache cfcache;
          fastcgi_cache_valid 30s;
        fastcgi_cache_bypass $skip_cache;
        fastcgi_no_cache $skip_cache;
        fastcgi_param FASTCGI_SKIP_CACHE $skip_cache;                   

     #send a SERVER var so we know if the cache is enabled or not
            add_header X-FastCGI-Cache $upstream_cache_status;
            add_header X-Cookie-Skip $cache_cookie_ignore;
      }
}

不幸的是,这导致每个页面的缓存都产生了MISS,我认为这是因为skip cookie指令被忽略了。如何仅跳过特定页面上的cookie?

0 个答案:

没有答案
相关问题