禁止基於主機或國家/地區程式碼的請求

使用 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;
    }
...