You can also use regular expressions for a bit more flexibility. This
way you can explicitly accept only the request methods you allow and
return the error code of your choosing.
Only allow GET and HEAD request methods
if ($request_method !~ ^(GET|HEAD)$ ) { return 444; }
Hello - I am using the latest nginx 6. When I try to do as you say
above I am getting the error in the nginx error file: unknown directive
“if” in xyz.log
I am using your exact block as above and from your web page, like this:
if ($request_method !~ ^(GET|HEAD)$ ) {
return 444;
}
I have tried this within the main server directive as well as from
within location directives, but always get this error. Obviously I am
missing something? Thanks.