Firewall
Country blocking
Blocks visitors from the countries you choose, or allows only the countries you choose, using a country database stored on your own server.
What it does
Blocklist mode turns away visitors from the countries you list. Allowlist mode turns away everyone except the countries you list.
You choose what blocked visitors get: a 403 "forbidden" page with your message, a 404 "not found" page, or a redirect to another address. You also choose what happens when a country cannot be worked out.
Why it matters
If your business only serves a few countries, most attacks from elsewhere can simply be refused. A local shop rarely needs visitors from the other side of the world.
Set it up
- Add your own address to the IP allow list first, in case you travel.
- Go to the Firewall tab, section Geo blocking, and switch on Geo IP Blocking.
- Check the detection read-out says a country source is available. Stack Guard downloads a free country database for you; behind Cloudflare it can also use Cloudflare's country.
- Choose Blocking Mode, pick the countries, and set Unknown Location. Allow is safer to start.
- Choose the Response Code and message, then click Save Changes.
Good to know
Country data is never perfect, and VPNs let people appear to be anywhere. Treat country blocking as a filter that cuts noise, not a wall.
Allowlist mode is strict: anyone travelling abroad, including you, is blocked unless their address is on the allow list.
Administrators are not blocked inside the admin area, but country blocking does apply to them on the front of the site.
Visitor addresses are never sent to an outside service: the lookup happens on your server.
Which plan includes it
Country blocking and the country lookup tool are part of Pro.
How it works, for developers
- Checked on
initat priority 2; skipped for AJAX, scheduled tasks and allow-listed addresses. - Country lookup order: the
CF-IPCountryheader (only trusted when the request really comes from Cloudflare), then a MaxMind database at the path you give, then the DB-IP Lite database inuploads/stack-guard/geo/. - The DB-IP database is checked daily by the
smg_geo_db_updatetask and downloaded again when older than 32 days. Lookups are cached for an hour insmg_geo_*transients; daily block counts for 30 days insmg_geo_stats. - Settings:
smg_geo_blocking_enabled,smg_geo_mode,smg_geo_countries,smg_geo_unknown_action,smg_geo_response_code,smg_geo_block_message,smg_geo_redirect_url,smg_geo_maxmind_db_path. Skipped whileSMG_SAFE_MODEis defined.
Quick answers about country blocking
What does Country blocking do in Stack Guard?
Blocklist mode turns away visitors from the countries you list. Allowlist mode turns away everyone except the countries you list. You choose what blocked visitors get: a 403 "forbidden" page with your message, a 404 "not found" page, or a redirect to another address. You also choose what happens when a country cannot be worked out.
Why use country blocking on a WordPress site?
If your business only serves a few countries, most attacks from elsewhere can simply be refused. A local shop rarely needs visitors from the other side of the world.
How do I set up country blocking?
1. Add your own address to the IP allow list first, in case you travel. 2. Go to the Firewall tab, section Geo blocking, and switch on Geo IP Blocking. 3. Check the detection read-out says a country source is available. Stack Guard downloads a free country database for you; behind Cloudflare it can also use Cloudflare's country. 4. Choose Blocking Mode, pick the countries, and set Unknown Location. Allow is safer to start. 5. Choose the Response Code and message, then click Save Changes.
Which Stack Guard plan includes country blocking?
Country blocking and the country lookup tool are part of Pro.
More in Firewall
- BansBlocks a specific internet address, a whole range of addresses, or a kind of software from your entire site, for a set time or for good.
- IP allow listA list of trusted internet addresses, such as your office, that Stack Guard's blocking features never stop.
- Real visitor IP (trusted proxy)Tells Stack Guard how to find a visitor's real internet address when your site sits behind Cloudflare, a load balancer or another proxy.
- Custom firewall rulesYour own if-this-then-that rules for incoming requests: block, allow or just log requests that match a page address, a browser name, a visitor address and more.
Not running Stack Guard yet? It is free.
Download Free