Request nginx rejection if no header

I need nginx to reject requests if the StaticCookie header StaticCookie missing. I am not interested in its value, I just need it to exist.

I came up with this, but it will not work. Nginx allows headerless requests.

  if ($http_StaticCookie = false) { return 403; } root /usr/share/asuno/www; location ~* /css/ { expires max; } location ~* /js/ { expires max; } 

I saw this post - Nginx: reject a request if the header is missing or incorrect - but it deals with certain header values. I need to check the simple existence of the header.

I tried to put location directives inside an if clause, but then nginx throws errors trying to read the configuration.

How can I do that?

+7
nginx
source share
1 answer

Alexey’s comment. Ten rights, thanks.

 if ($http_StaticCookie = "") { return 403; } 
+5
source share

All Articles