How to check Cookie header line and custom cache on Nginx
- by user124249
I am trying cache for my website use Nginx Proxy module and has following requirements:
If request has cookie (in request header)
The response will use cache of Nginx
Hide Set-Cookie header line
If request has no cookie (in request header)
Foward request to backend
Don't hide h Set-Cookie header line
I use If (of rewrite module) and any directive:
if (!-e $http_cookie)
{
set $not_cache_rq 0;
set $not_cache_rp 0;
}
if ($http_cookie) {
set $not_cache_rq 1;
set $not_cache_rp 1;
}
proxy_cache_bypass $not_cache_rq;
proxy_no_cache $not_cache_rp;
proxy_hide_header Set-Cookie;
I do not know how to call cookie proxy_hide_header option when has cookie and no cookie on header line.
Please help me. Many thanks.