GeoBlock
This is a community guide and is not officially supported. If you have any issues, please reach out to the author.
Legacy guide. Pangolin now supports native geo-blocking. If you previously installed this plugin, follow Remove GeoBlock Plugin before enabling native geo-blocking.
GeoBlock is a Traefik middleware that uses IP-based geolocation to allow or block traffic from specific countries. It helps enhance security and access control by restricting unwanted or potentially harmful connections based on geographic regions.
Installation
To integrate GeoBlock into your Traefik setup, follow the steps below:
- Add the following configuration to your
/config/traefik/traefik_config.ymlfile:
entryPoints:
websecure:
http:
middlewares:
- geoblock@file
experimental:
plugins:
geoblock:
moduleName: github.com/PascalMinder/geoblock
version: v0.3.2- Add the following configuration to your
/config/traefik/dynamic_config.ymlfile. SettingblackListMode: falseenables GeoBlock in whitelist mode, allowing only the specified countries. Remember to add the appropriate countries when traveling. A list of country codes can be found in the documentation.
http:
middlewares:
geoblock:
plugin:
geoblock:
silentStartUp: false
allowLocalRequests: true
logLocalRequests: false # change to true to see logs and verify if it is working
logAllowedRequests: false # change to true to see logs and verify if it is working
logApiRequests: false # change to true to see logs and verify if it is working
api: "https://get.geojs.io/v1/ip/country/{ip}"
apiTimeoutMs: 500
cacheSize: 25
forceMonthlyUpdate: true
allowUnknownCountries: false
unknownCountryApiResponse: "nil"
blackListMode: false
countries:
- DE # add/replace with your country code- Restart Traefik to apply the changes:
docker restart traefikTesting
To monitor GeoBlock activities in the Traefik logs, enable logging by setting the following options to true:
logLocalRequests: true
logAllowedRequests: true
logApiRequests: true
