Geo-blocking in nginx via ngx_http_geoip2_module + MaxMind GeoLite2 database. IP lookup → country code → allow/deny via map or if. Useful for compliance (GDPR, sanctions), reducing bot traffic. Cons: VPNs bypass easily, legitimate travellers get blocked, MaxMind requires signup (free tier fine).
Below: step-by-step, working examples, common pitfalls, FAQ.
apt install libnginx-mod-http-geoip2geoip2 /path/GeoLite2-Country.mmdb { $geoip_country_code country iso_code; }map $geoip_country_code $blocked { default 0; CN 1; RU 1; }if ($blocked) { return 403; }geoipupdate daemon (monthly)curl -H "X-Forwarded-For: 1.2.3.4" https://example.com| Scenario | Config |
|---|---|
| Basic country blocking | # nginx.conf http:
geoip2 /usr/share/GeoIP/GeoLite2-Country.mmdb {
$geoip_country_code country iso_code;
}
map $geoip_country_code $blocked {
default 0;
CN 1;
KP 1;
}
# server:
if ($blocked) { return 403; } |
| Whitelist only (allow some) | map $geoip_country_code $allowed {
default 0;
US 1;
CA 1;
GB 1;
DE 1;
}
if ($allowed = 0) { return 403; } |
| Custom blocked page | location = /blocked.html {
internal;
root /var/www/static;
}
if ($blocked) { error_page 403 /blocked.html; return 403; } |
| Allow admin IP bypass | set $skip 0;
if ($remote_addr = "1.2.3.4") { set $skip 1; }
if ($blocked = 1) { set $skip "${skip}1"; }
if ($skip = 1) { return 403; } |
| geoipupdate daemon | # /etc/GeoIP.conf
AccountID XXX
LicenseKey YYY
EditionIDs GeoLite2-Country
# Cron: 0 3 1 * * /usr/bin/geoipupdate |
$http_cf_ipcountry or real_ip_headerThe tool checks HTTP security headers, SSL/TLS configuration, server info leaks, and protection against common attacks (XSS, clickjacking, MIME sniffing). A grade fromA to F shows overall security level.
Checking Content-Security-Policy, HSTS, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, and more.
TLS version, certificate expiry, chain of trust, HSTS support.
Finding exposed server versions, debug modes, open configs, and directories.
Detailed report explaining each issue with specific steps to fix it.
HTTP header audit
config verification
CSP & HSTS setup
compliance checks
Strict-Transport-Security.Server: Apache/2.4.52 helps attackers find exploits. Hide the version.DENY or SAMEORIGIN.nosniff, browsers may misinterpret file types (MIME sniffing).Content-Security-Policy-Report-Only, monitor violations, then enforce.Server, X-Powered-By, X-AspNet-Version from responses.Security check history and HTTP security header monitoring.
Sign up freeCloudflare: simple dashboard toggle, blocks before origin. nginx: more flexible, no CDN dependency. For critical security — both.
MaxMind GeoLite2 — free, good accuracy, standard. IP2Location — commercial, more details (proxy/VPN detection).
Whitelist their IP BEFORE the country check. Or a separate admin.example.com without geo-block.
Sanctions compliance: CU, IR, KP, SY. Security: countries with high bot activity. Business: where you have no support.