S
S
skul2013-04-14 00:11:10
Nginx
skul, 2013-04-14 00:11:10

nginx block if no cookie

Good afternoon, you need to block a specific location if there is no $cookie_NAME cookie with a numeric value.
Tried like this

set $var $cookie_NAME;
    location ^~ /path {
        if ($var) { proxy_pass http://127.0.0.1:8080; }
        return 403;
    }

Checked with curl
curl -b "NAME=999" example.com/path/index.php

In response I receive
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>nginx</center>
</body>
</html>

Please tell me how can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Burov, 2013-04-14
@skul

if ($cookie_NAME = "") {
    return 403;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question