Provides middleware for resolving a users IP address against multiple Maxmind Geo IP databases with self update support
xcaddy \
--with github.com/relvacode/caddy-geoip2{
order geoip2 first
# accountId, licenseKey and updateUrl and updateFrequency are only required for automatic updates
geoip2 {
account_id "{env.GEO_ACCOUNT_ID}"
license_key "{env.GEO_API_KEY}"
database_directory "/tmp/"
edition_id GeoLite2-City
edition_id GeoLite2-ASN
update_url "https://updates.maxmind.com"
update_frequency 604800 # in seconds
}
}
localhost {
geoip2
# Add country and state code to the header
header geoip-country "{geoip2.country_code}"
@geofilter expression `{geoip2.country_code} in ["CN", "IR", "RU"]`
error @geofilter "Blocked by geographic location" 403
}
Supported with the GeoLite2-City and GeoLite2-Country editions
geoip2.country_codegeoip2.country_namegeoip2.country_eugeoip2.continent_codegeoip2.continent_name
Supported with the GeoLite2-City edition
geoip2.city_namegeoip2.postal_codegeoip2.location_latitudegeoip2.location_longitudegeoip2.location_timezonegeoip2.location_accuracy_radius
Supported with the GeoLite2-ASN edition
geoip2.asn_networkgeoip2.asn_organisationgeoip2.asn_system_number