Zum Inhalt

auto_reload

The auto_reload directive in the geoip2 module enables automatic reloading of the GeoIP2 database at a specified interval if it has changed. This is useful for ensuring that your NGINX server always uses the most up-to-date geographical data without requiring manual intervention.

Syntax

auto_reload <interval>;

Default

disabled

Example

http {
    geoip2 /etc/maxmind-country.mmdb {
        auto_reload 5m;
        $geoip2_data_country_code default=US source=$remote_addr country iso_code;
    }

    server {
        listen 80;
        location / {
            proxy_pass http://backend;
            proxy_set_header X-Country-Code $geoip2_data_country_code;
        }
    }
}

In this example, the GeoIP2 database is checked every 5 minutes for changes. If the database has been updated, it will be reloaded automatically. The X-Country-Code header is set with the country code determined from the client's IP address.