Configuring the geo module

Configuring the geo module

The ngx_http_geo_module module creates variables with values depending on the client IP address.

Syntax geo [$address] $variable { ... }
Default
Context HTTP
NGINX configuration sample
geo $my_geo_map {
    default        0;
    127.0.0.1      0;
    10.12.100.1/32 1;
    10.13.0.0/16    2;
    2001:0db8::/32 1;
}

Example of a Salt pillar for the geo module:

nginx:
server:
  geo:
    enabled: true
    items:
      my_geo_map:
        enabled: true
        variable: my_geo_map_variable
        body:
          default:
            value: '0'
          localhost:
            name: 127.0.0.1
            value: '0'
          client:
            name: 10.12.100.1/32
            value: '1'
          network:
            name: 10.13.0.0/16
            value:  '2'
          ipv6_client:
            name: 2001:0db8::/32
            value: '1'

All geo variables specified in the pillars, after applying the nginx.server state, will be reflected in the /etc/nginx/conf.d/geo.conf file.