禁止基于主机或国家/地区代码的请求

使用 Nginx 映射来解析字段并拒绝请求。

# 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;
    }
...