clear_request_cookie
The `clear_request_cookie` directive removes a specified cookie from the request headers in NGINX.
Description
The clear_request_cookie directive is used in NGINX to effectively delete a cookie from the request headers. When this directive is invoked, it checks for the presence of a specified cookie by name. If the cookie exists in the request, it will be removed; if the cookie does not exist, nothing will occur. This operation aids in managing how cookies are sent to backend applications, especially in scenarios where certain cookies should not be passed forward based on specific logic of the application or user requirements.
This directive can be utilized in http, server, or location contexts, and can accept an optional parameter for conditionally executing the clear operation. This means you can specify an if condition that must be true for the cookie to be cleared, allowing for fine-tuned control over the request processing. The directive can handle up to two parameters: the first being the name of the cookie to clear, and the optional second being the condition.
Config Example
location / {
clear_request_cookie session_id;
clear_request_cookie auth_token if=$http_a;
}Using conditions incorrectly may lead to unexpected behavior where a cookie is not cleared when intended.
Ensure that the cookie name is spelled correctly and is case-sensitive, as cookie names are treated in a case-sensitive manner.