title: How to remove certain cookies from nginx response
body: <p>I have nginx set up as a reverse proxy server and I want to remove certain cookies set on the backed server (apache)</p>
  
  <p>My website uses a lot of cookies which I can not control (Expression Engine CMS, don't ask me why). I want to delete some of those cookies (lets say cookies A B and C) and keep some other (cookies D and E).</p>
  
  <p>After that I will set up nginx to respond with cached content only if the request has no cookies.</p>
  
  <p>Do you have any idea how to do this? Thanks</p>
  
  <p>So far I have in my config:</p>
  
  <pre><code>proxy_cache_path /opt/nginx/cache levels=1:2 keys_zone=mycache:20m max_size=1G;
  proxy_temp_path /opt/nginx/tmp_cache/;
  proxy_ignore_headers Expires Cache-Control Set-Cookie;
  proxy_cache_use_stale error timeout invalid_header http_502;
  proxy_cache_bypass $cookie_nocache;
  proxy_no_cache $cookie_nocache;
  </code></pre>
  
  <p>...</p>
  
  <pre><code>location / {
      proxy_set_header X-Real-IP  $remote_addr;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_cache mycache;
      proxy_cache_valid  200 302  6h;
      proxy_cache_valid  404      1m;
      proxy_pass http://x.x.x.x:8080;
  }
  </code></pre>