How do I deny illegal host headers besides all subdomains (wildcard solution) and the main domain with nginx? When using this code below all of the subdomains stop working.
if ($host !~* ^(domain.com|*.domain.com)$ ) {
return 444;
}
My server name is:
server_name domain.com *.domain.com;
How can this be accomplished?
^means "start of string".^domain.comwill NOT matchfoo.domain.com, becausedomain.comisn't at the start of the string.|*.will also not work.*is "zero or more of the previous", but you have no previous|is not a matching character, it's the regex equivalent of "or".