Nginx Manage the Cookie in Response

NginxManagetheCookieinResponse

MyrequirementistodeletetheResponseCookieinmyNGINX.

Atfirst,Iwastrying

proxy_hide_headerSet-Cookie

ItcanremovetheresponseheaderSet-Cookie.SotheHTTPresponsewillnothavethisintheheader.

Butactually,myrequirementistodeleteoneCookie.SoIchangetodolikethis.

add_header'Set-Cookie''VC=;Path=/api;Domain=.sillycat.com;Max-Age=0;Expires=0';

add_header'Set-Cookie''VC=;Path=/DWH/accounts;Domain=.sillycat.com;Max-Age=0;Expires=0';

Theselinesmeans,itwillremovetheVCcookieinthatpath.

ThefullinformationinNGINXissimilarto

location/DWH{

indexindex.html;

proxy_passhttps://{{proxy_server}}.{{target_domain}};

proxy_set_headerX-Real-IP$remote_addr;

proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;

proxy_set_headerHost$http_host;

add_header'Access-Control-Allow-Origin'$http_origin;

add_header'Access-Control-Allow-Methods''GET,POST,OPTIONS';

add_header'Access-Control-Allow-Credentials''true';

#proxy_hide_headerSet-Cookie;

add_header'Set-Cookie''VC=;Path=/api;Domain=.{{target_domain}};Max-Age=0;Expires=0';

add_header'Set-Cookie''VC=;Path=/DWH/accounts;Domain=.{{target_domain}};Max-Age=0;Expires=0';

}

IamusingaPythontemplate,soIhave{{}}there.Buttheideaisthesame.

Inthebrowser,wecangotodevelopertool—>Application—>Cookiestoseethechanges.

References:

https://blog.confirm.ch/adding-and-removing-nginx-response-headers/

https://github.com/openresty/headers-more-nginx-module

https://stackoverflow.com/questions/35493418/how-to-remove-a-response-header-in-nginx-after-having-stored-its-value-in-case-o

http://www.ebrueggeman.com/blog/setting-cookies-in-nginx

http://mailman.nginx.org/pipermail/nginx/2016-September/051736.html

相关推荐