As I explained in title I want to restrict access unless the header is satisfied. In the given link, it is explained how to restrict a specific path access, however I couldn't find anything about how to add conditions to this restriction from my researches. Any idea about this problem?
Asked
Active
Viewed 637 times
2 Answers
0
Instead of deny
/allow
directives you can check any HTTP header value via $http_<name>
variable and use return 403
to forbid access. For example, lets call our header X-Secret-Token
:
location /some/path {
if ($http_x_secret_token != 'my-super-secret-password') {
return 403; # HTTP 403 Forbidden, the same code as generated by 'deny' directive
}
...
}
If you need some complex checks, you can use several chained map
blocks (see the example).

Ivan Shatsky
- 13,267
- 2
- 21
- 37
-
I have tried this but didnt work. When I check the logs I saw response 200. I am working on configmap file. Do you have any idea about what I might miss? – Kazim Okan Akgül Oct 14 '21 at 14:37
-
Any chances some other location is overtaken request processing from this one? – Ivan Shatsky Oct 16 '21 at 09:01
0
From the research I've made it seems like the token approach presented here before seems to be the only suitable solution, a similar question has been asked here.

Jakub Siemaszko
- 668
- 3
- 8