Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove certain cookies from nginx response [closed]

I have nginx set up as a reverse proxy server and I want to remove certain cookies set on the backed server (apache)

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).

After that I will set up nginx to respond with cached content only if the request has no cookies.

Do you have any idea how to do this? Thanks

So far I have in my config:

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;

...

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;
}
like image 497
Martin Taleski Avatar asked Dec 29 '12 21:12

Martin Taleski


People also ask

Where is nginx cache?

/var/cache/nginx – the path to the local disk directory for the cache. levels – defines the hierarchy levels of a cache, it sets up a two-level directory hierarchy under /var/cache/nginx.

What is Proxy_connect_timeout?

proxy_connect_timeout 60s; Context: http , server , location. Defines a timeout for establishing a connection with a proxied server. It should be noted that this timeout cannot usually exceed 75 seconds.


1 Answers

Although you already mentioned that you switched to Varnish to accomplish what you asked for, the correct answer would have been to use the headers-more-nginx-module which basically allows you the same as the Varnish function does (and much more).

like image 123
Fleshgrinder Avatar answered Nov 18 '22 14:11

Fleshgrinder