Nginx Module Reference manual: Geo Module (GEO)

Source: Internet
Author: User
Keywords Nginx geo geo Module
Tags address client compiled configure default default value example ip

These modules are all compiled into Nginx by default unless a module is manually specified to be excluded in configure.

This module creates variables whose values depend on the IP address of the client:
The following example:

Geo $geo {default 0; 127.0.0.1/32 2; 192.168.1.0/24 1; 10.1.0.0/16 1;}

Instructions

Geo

Syntax: Geo [$IP _variable] $variable {...}
Default value: None
Working with Fields: HTTP
This directive specifies the country to which the client IP belongs, and by default it looks for the $remote_addr variable, but it can be specified manually after version 0.7.27.

Geo $arg _remote_addr $geo {...;}

Using CIDR address format, in addition, there are 4 special parameters:

Delete-Deletes the specified network (0.7.23) Default-replaces some undefined addresses with 0.0.0.0/0. Include-a text file with address information that can contain multiple. Proxy-Specifies the proxy server address (0.8.7). Ranges-Specifies that the address (0.7.23) be defined using the form of an address pool, which must be placed first. Geo $country {default no; include conf/geo.conf; 127.0.0.0/24 us; 127.0.0.1/32 ru; 10.1.0.0/16 ru; 192.168.1.0/24 UK;}

conf/geo.conf File Contents:

10.2.0.0/16 Ru; 192.168.2.0/24 Ru;

The value will use the largest parameter, for example, 127.0.0.1 will be "ru" instead of "us".
An example of using ranges:

Geo $country {ranges; default no; 127.0.0.0-127.0.0.0 us; 127.0.0.1-127.0.0.1 Ru; 127.0.0.1-127.0.0.255 us; 10.1.0.0-10.1.255.255 Ru; 192.168.1.0-192.168.1.255 UK; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.