17

I need nginx to reject requests if header StaticCookie is not present. I don't care about its value, I just need for it to exist.

What I came up with is this, but this doesn't work. Nginx allows requests with no headers at all.

    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 request if header is not present or wrong - but it deals with defined header values. What I need is to check mere existence of the header.

I tried putting location directives inside the if clause but then nginx throws errors trying to read the config.

How can this be done?

Community
  • 1
  • 1
kurtgn
  • 8,140
  • 13
  • 55
  • 91

1 Answers1

22

the comment by Alexey Ten is correct, thanks.

if ($http_StaticCookie = "") { return 403; }
Montaro
  • 9,240
  • 6
  • 29
  • 30
kurtgn
  • 8,140
  • 13
  • 55
  • 91