There are countless tutorials on checking if a cookie exists and contains my content, in this case foobar
.
How do I do the following assuming mycookie is the cookie that I want set.
if ($cookie_mycookie does not equal "foobar") {
return 401;
}
I have tried the following to no avail.
if (!$http_mycookie ~* "foorbar" ) {
return 401;
}
Thank you!
In Nginx, each cookie is available in embedded variable
$cookie_CookieName
. In case you want to check cookie with namemycookie
, you can do it using this configuration snippet:From nginx manual for the
if
command: