title: Ignoring cookies list efficiently in NGINX reverse proxy setup
body: <p>I am currently working/testing microcache feature in NGINX reverse proxy setup for dynamic content. </p>
  
  <p>One big issue that occurs is sessions/cookies that need to be ignored otherwise people will logon with random accounts on the site(s).</p>
  
  <p>Currently I am ignoring popular CMS cookies like this:</p>
  
  <pre><code>if ($http_cookie ~* "(joomla_[a-zA-Z0-9_]+|userID|wordpress_(?!test_)[a-zA-Z0-9_]+|wp-postpass|wordpress_logged_in_[a-zA-Z0-9]+|comment_author_[a-zA-Z0-9_]+|woocommerce_cart_hash|woocommerce_items_in_cart|wp_woocommerce_session_[a-zA-Z0-9]+|sid_customer_|sid_admin_|PrestaShop-[a-zA-Z0-9]+") 
      {
  
  # set ignore variable to 1
  # later used in:
  # proxy_no_cache                 $IGNORE_VARIABLE;
  # proxy_cache_bypass             $IGNORE_VARIABLE;
  # makes sense ?
  
      }
  </code></pre>
  
  <p>However this becomes a problem if I want to add more cookies to the ignore list. Not to mention that using too many "if" statements in NGINX is not recommended as per the docs.</p>
  
  <p>My questions is, if this could be done using a map method ? I saw that regex in map is different( or maybe I am wrong ).</p>
  
  <p>Or is there another way to efficiently ignore/bypass cookies ?</p>
  
  <p>I have search a lot on stackoverflow, and whilst there are so many different examples; I could not find something specific for my needs.</p>
  
  <p>Thank you</p>
  
  <p><strong>Update:</strong></p>
  
  <p>A lot of reading and "digging" on the internet ( we might as well just say Google ), and I found quite some interesting examples. </p>
  
  <p>However <strong>I am very confused</strong> with these, as I do not fully understand the <strong>regex usage</strong> and I am afraid to implement such without understanding it.</p>
  
  <p><strong>Example 1:</strong></p>
  
  <pre><code>map $http_cookie $cache_uid {
    default nil;
    ~SESS[[:alnum:]]+=(?&lt;session_id&gt;[[:alnum:]]+) $session_id;
  }
  </code></pre>
  
  <ol>
  <li><p>In this example I can notice that the regex is very different from
  the ones used in "if" blocks.   I don't understand why the pattern
  starts without any "" and directly with just a <em>~</em> sign.    </p></li>
  <li><p>I don't understand what does <em>[[:alnum:]]+</em> mean ? I search for this
      but I was unable to find documentation. ( or maybe I missed it )</p></li>
  <li><p>I can see that the author was setting "nil" as default, this will
      not apply for my case.</p></li>
  </ol>
  
  <p><strong>Example 2:</strong></p>
  
  <pre><code>map $http_cookie $cache_uid {
    default  '';
    ~SESS[[:alnum:]]+=(?&lt;session_id&gt;[[:graph:]]+)  $session_id;
  }
  </code></pre>
  
  <ol>
  <li>Same points as in Example 1, but this time I can see <em>[[:graph:]]+</em>.
  What is that ?</li>
  </ol>
  
  <p><strong>My Example (not tested):</strong></p>
  
  <pre><code>map $http_cookie $bypass_cache {
  
      "~*wordpress_(?!test_)[a-zA-Z0-9_]+"  1;
      "~*wp-postpass|wordpress_logged_in_[a-zA-Z0-9]+"  1;
      "~*comment_author_[a-zA-Z0-9_]+"  1;
      "~*[a-zA-Z0-9]+_session)"  1;
  
      default      0;
  }
  </code></pre>
  
  <p>In my pseudo example, the regex must be wrong since I did not find any map cookie examples with such regex.</p>
  
  <p>So once again my goal is to have a map style list of cookies that I can bypass the cache for, with proper regex.</p>
  
  <p>Any advice/examples much appreciated.</p>