In your dynamic_config.yml, add the GeoBlock middleware configuration. You can add this under the middlewares section:
pangolin-geoblock:
plugin:
geoblock:
enabled: true
defaultAllow: false
databaseFilePath: "/plugins-storage/IP2LOCATION-LITE-DB1.IPV6.BIN"
allowPrivate: true
logBannedRequests: true
banIfError: true
disallowedStatusCode: 403
allowedCountries:
- US # United States
- CA # Canada
- GB # United Kingdom
- IN # India
# Add more countries as needed from the ISO 3166-1 alpha-2 codes
allowedIPBlocks:
- "192.168.0.0/16"
- "10.0.0.0/8"
bypassHeaders:
X-Internal-Request: "true"
X-Skip-Geoblock: "1"
Apply the middleware to your enterypoints in traefik_config.yml. You can add it to specific paths:
Thanks you so much for this guides, i was having a lot of troubles with other proxies but since im using Pangoling + your guides i could set up an amazing proxy!
I have a question (forgive me, i’m learning!) … i followed the instructions and installed geoblock functionality in traefik. tested the access with a vpn from one of the blocked countries (i have whitelisted only some countries - rest should be blocked) and it seemed to be working. lately i added crowdsec to my configuration and crowdsec keeps blocking chinese ips that are trying to access. so just for interess and because i’m still learning: does that mean that crowdsec checks first (like before geoblock)? otherwise the chinese ips would not make it through geoblock, right?
You should ideally have geoblock first as a middleware and then crowdsec, that way you can take advantage of both plugins and the load on crowdsec becomes less and say suppose if geoblock missies something crowdsec will catch it.
The order of the middlewares in the dynamic_conf.yml does not matter, where is a MUST is at the traefik_config.yml , in that one you need to place “pangolin-geoblock@file” the very firts one.
http:
middlewares:
geoblock:
plugin:
geoblock:
# Enable this plugin?
enabled: true
# Path to ip2location database file
databaseFilePath: /plugins-local/src/github.com/nscuro/traefik-plugin-geoblock/IP2LOCATION-LITE-DB1.IPV6.BIN
# Whitelist of countries to allow (ISO 3166-1 alpha-2)
allowedCountries: [ "AT", "CH", "DE" ]
# Blocklist of countries to block (ISO 3166-1 alpha-2)
blockedCountries: [ "RU" ]
# Default allow indicates that if an IP is in neither block list nor allow lists, it should be allowed.
defaultAllow: false
# Allow requests from private / internal networks?
allowPrivate: true
# HTTP status code to return for disallowed requests (default: 403)
disallowedStatusCode: 204
# Add CIDR to be whitelisted, even if in a non-allowed country
allowedIPBlocks: ["66.249.64.0/19"]
# Add CIDR to be blacklisted, even if in an allowed country or IP block
blockedIPBlocks: ["66.249.64.5/32"]
it has more options compared to the one which I have posted in the tutorial.
but please check the issues before deploying Issues · nscuro/traefik-plugin-geoblock
I’ll lcome back to it at a later time, I’m sure I need to have the database created first.
"plugin":"plugin-geoblock","module":"github.com/david-garcia-garcia/traefik-geoblock","runtime":"","time":"2025-05-10T00:09:40Z","level":"error","message":"2025/05/10 00:09:40 time=2025-05-10T00:09:40.579Z level=ERROR msg=\"could not find file\" plugin=geoblock@file file=IP2LOCATION-LITE-DB1.IPV6.BIN path=/plugins-storage/IP2LOCATION-LITE-DB1.IPV6.BIN\n"}
{"level":"error","entryPointName":"websecure","routerName":"ws-router@file","error":"geoblock@file: failed to open database: open /plugins-storage/IP2LOCATION-LITE-DB1.IPV6.BIN: no such file or directory","time":"2025-05-10T00:09:40Z"}