title: enabling Nginx FASTCGI cache for logged user and when the product is added to the cart
body: <p>My site is an ecommerce site using woocommerce. Read recommedation to disable Nginx FASTCGI cache for logged user and when the product is added to the cart. My site has all the static content including product page and there is no content change for logged user excluding my account page. Thus I am thinking maybe I could enable cache on all of my content even for logged user and when product is added to the cart excluding my-account, cart, checkout, order-tracking, submit-ticket, wp-admin, POST and query. Also have to update the cache when stock is out of stock for product page. Do you think it's OK or it's a wrong idea? Any comment would be appreciated.</p>
  <p>Here is nginx.conf file.</p>
  <pre><code>fastcgi_cache_path /var/run/nginx-cache levels=1:2       
                 keys_zone=EXE:300m inactive=10d;
  fastcgi_cache_key &quot;$scheme$request_method$host$request_uri&quot;;
  fastcgi_cache_use_stale error timeout invalid_header http_500;
  
  
  
  server {
  listen   80;
          server_name example.com ;
  
      set_real_ip_from 10.0.0.0/8;
  real_ip_header X-Real-IP;
      real_ip_recursive on;
  
  access_log /var/www/example/logs/http-access.log;
  error_log /var/www/example/logs/http-error.log;
  
         root /var/www/example/public_html/;
         index index.php ;
  
  location /nginx_status {
          stub_status on;
          access_log   off;
          allow 10.0.0.0/24;
  
          deny all;
      }
  
      location = /signup-log.dat {
          allow 10.0.0.0/24;
  
          deny all;
          return 404;
      }
  
  gzip_static on;
  brotli_static on;
  
  set $skip_reason &quot;&quot;;
  set $skip_cache 0;
  
  
  # POST requests and urls with a query string should always go to PHP
  if ($request_method = POST) {
      set $skip_cache 1;
      set $skip_reason &quot;POST&quot;;
  }   
  
  if ($query_string != &quot;&quot;) {
      set $skip_cache 1;
      set $skip_reason &quot;QueryString&quot;;
  }   
  
  if ( $cookie_woocommerce_items_in_cart = &quot;1&quot; ){
       set $skip_cache 1;
      set $skip_reason &quot;Cart&quot;;
  }
  
  # Don't cache uris containing the following segments
  if ($request_uri ~* &quot;(/signup.php)&quot;) {
      set $skip_cache 1;
      set $skip_reason &quot;SPAM TRAP&quot;;
  }   
  
  # Don't cache uris containing the following segments
  if ($request_uri ~* &quot;(/cart.*|/my-account.*|/checkout.*|/order-tracking.*|/submit-ticket.*|/addons.*|/wp-admin/|/xmlrpc.php|sitemap(_index)?.xml|wp-.*.php|/index.php)&quot;) {
      set $skip_cache 1;
      set $skip_reason &quot;URI&quot;;
  }   
  
  # Don't use the cache for logged in users or recent commenters
  if ($http_cookie ~* &quot;comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_no_cache|wordpress_logged_in&quot;) {
      set $skip_cache 1;
      set $skip_reason &quot;Logged&quot;;
  }
  
  location / {
          # no php is touched for static content
      try_files $uri $uri/ /index.php?$args;
  }   
  
  ### STATIC CACHES ###
  
  location = /robots.txt { allow all; access_log off; log_not_found off; }
  location = /favicon.ico { access_log off; log_not_found off; }
  location ~* \.(jpg|jpeg|gif|css|png|js|ico|html|woff|svg|woff2|avif)$ { access_log off;    add_header Static-Files &quot;Cached&quot;; expires 1y; }
  
  
  
  location ~ \.php$ {
      set $rt_session &quot;&quot;;
      
      if ($http_cookie ~* &quot;wp_woocommerce_session_[^=]*=([^%]+)%7C&quot;) {
                  set $rt_session wp_woocommerce_session_$1;
          }   
  
      if ($skip_cache = 0 ) {
           more_clear_headers &quot;Set-Cookie*&quot;;
          set $rt_session &quot;&quot;;
      }
      
  
          fastcgi_cache_key &quot;$scheme$request_method$host$request_uri$rt_session&quot;;
     
      proxy_hide_header       Pragma;
      try_files $uri =404;
      include fastcgi_params;
      fastcgi_pass unix:/run/php-fpm/www.sock;
      fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
  
      add_header FAST-CGI-Cache-Skip $skip_reason;
      add_header FAST-CGI-Cache $upstream_cache_status;
          # Don't cache when $skip_cache is true
      fastcgi_cache_bypass $skip_cache;
          fastcgi_no_cache $skip_cache;
  
          # Use the cache zone
      fastcgi_cache EXE;
  
          # Cache everything for 1d
      fastcgi_cache_valid  1d;
  }
  
  
  
  }
  </code></pre>