Use Nginx map to parse fields and reject requests.
# Allowed hosts
map $http_host $name {
hostnames;
default no;
example.com yes;
*.example.com yes;
example.org yes;
*.example.org yes;
.example.net yes;
wap.* yes;
}
# Allowed countries
map $geoip_country_code $allowed_country {
default no;
country_code_1 yes;
country_code_2 yes;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
# Disallow access based on hostname
if ($name = no) {
return 444;
}
# Disallow access based on GeoIP
if ($allowed_country = no) {
return 444;
}
...