-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
65 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,13 @@ | ||
# usage: include /etc/nginx/geoipme.conf; | ||
# this proxy pass to sites-enabled/geoip.conf | ||
location ~ /(geoip|geoipme)+/(?<ip>.*) { | ||
charset utf-8; | ||
add_header Cache-Control no-cache; | ||
set $realip $ip; | ||
set $realip $ip; | ||
|
||
if ($ip = '') { | ||
set $realip $realip_remote_addr; | ||
if ($realip = '') { | ||
set $realip $realip_remote_addr; | ||
} | ||
|
||
default_type application/json; | ||
set $mybody '{"ip":"$realip","country_code":"$geoip2_country_code","region_code":"$geoip2_region_code","region_name":"$geoip2_region","city":"$geoip2_city","zip_code":"$geoip2_postal_code","latitude":"$geoip2_latitude","longitude":"$geoip2_longitude","metro_code":"$geoip2_dma_code"}'; | ||
|
||
if ($arg_format = "xml") { | ||
add_header Content-Type application/xml; | ||
|
||
set $mybody '<Response><IP>$realip</IP><CountryCode>$geoip2_country_code</CountryCode><CountryName>$geoip2_country</CountryName><RegionCode>$geoip2_region_code</RegionCode><RegionName>$geoip2_region</RegionName><City>$geoip2_city</City><ZipCode>$geoip2_postal_code</ZipCode><Latitude>$geoip2_latitude</Latitude><Longitude>$geoip2_longitude</Longitude><MetroCode>$geoip2_dma_code</MetroCode></Response>'; | ||
} | ||
|
||
if ($arg_format = "csv") { | ||
add_header Content-Type text/csv; | ||
set $mybody '$realip,$geoip2_country_code,$geoip2_region_code,$geoip2_region,$geoip2_city,$geoip2_postal_code,$geoip2_latitude,$geoip2_longitude,$geoip2_dma_code'; | ||
} | ||
|
||
if ($arg_callback) { | ||
add_header Content-Type application/javascript; | ||
return 200 '$arg_callback($mybody);'; | ||
} | ||
|
||
return 200 $mybody; | ||
} | ||
proxy_set_header X-Forwarded-For $realip; | ||
proxy_set_header Host "127.0.0.1"; | ||
proxy_pass "http://127.0.0.1:9081"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,35 @@ | ||
map $http_x_forwarded_for $realip { | ||
default $http_x_forwarded_for; | ||
'' $realip; | ||
} | ||
|
||
geoip2 /etc/nginx/GeoLite2-Country.mmdb { | ||
auto_reload 60m; | ||
|
||
$geoip2_metadata_country_build metadata build_epoch; | ||
$geoip2_data_country source=$realip_remote_addr country names en; | ||
$geoip2_data_country_code source=$realip_remote_addr country iso_code; | ||
$geoip2_data_country source=$realip country names en; | ||
$geoip2_data_country_code source=$realip country iso_code; | ||
} | ||
|
||
geoip2 /etc/nginx/GeoLite2-City.mmdb { | ||
auto_reload 60m; | ||
|
||
$geoip2_continent_code source=$realip_remote_addr continent code; | ||
$geoip2_country source=$realip_remote_addr country names en; | ||
$geoip2_country_code source=$realip_remote_addr country iso_code; | ||
$geoip2_region source=$realip_remote_addr subdivisions 0 names en; | ||
$geoip2_region_code source=$realip_remote_addr subdivisions 0 iso_code; | ||
$geoip2_city source=$realip_remote_addr city names en; | ||
$geoip2_postal_code source=$realip_remote_addr postal code; | ||
$geoip2_latitude source=$realip_remote_addr location latitude; | ||
$geoip2_longitude source=$realip_remote_addr location longitude; | ||
$geoip2_time_zone source=$realip_remote_addr location time_zone; | ||
$geoip2_dma_code source=$realip_remote_addr location metro_code; | ||
$geoip2_continent_code source=$realip continent code; | ||
$geoip2_country source=$realip country names en; | ||
$geoip2_country_code source=$realip country iso_code; | ||
$geoip2_region source=$realip subdivisions 0 names en; | ||
$geoip2_region_code source=$realip subdivisions 0 iso_code; | ||
$geoip2_city source=$realip city names en; | ||
$geoip2_postal_code source=$realip postal code; | ||
$geoip2_latitude source=$realip location latitude; | ||
$geoip2_longitude source=$realip location longitude; | ||
$geoip2_time_zone source=$realip location time_zone; | ||
$geoip2_dma_code source=$realip location metro_code; | ||
} | ||
|
||
geoip2 /etc/nginx/GeoLite2-ASN.mmdb { | ||
auto_reload 60m; | ||
|
||
$geoip2_asn source=$realip_remote_addr autonomous_system_number; | ||
$geoip2_organization source=$realip_remote_addr autonomous_system_organization; | ||
$geoip2_asn source=$realip autonomous_system_number; | ||
$geoip2_organization source=$realip autonomous_system_organization; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
server { | ||
listen 127.0.0.1:9081; | ||
resolver 8.8.8.8 8.8.4.4; | ||
|
||
location / { | ||
charset utf-8; | ||
add_header Cache-Control no-cache; | ||
|
||
default_type application/json; | ||
set $mybody '{"ip":"$realip","country_code":"$geoip2_country_code","region_code":"$geoip2_region_code","region_name":"$geoip2_region","city":"$geoip2_city","zip_code":"$geoip2_postal_code","latitude":"$geoip2_latitude","longitude":"$geoip2_longitude","metro_code":"$geoip2_dma_code"}'; | ||
|
||
if ($arg_format = "xml") { | ||
add_header Content-Type application/xml; | ||
|
||
set $mybody '<Response><IP>$realip</IP><CountryCode>$geoip2_country_code</CountryCode><CountryName>$geoip2_country</CountryName><RegionCode>$geoip2_region_code</RegionCode><RegionName>$geoip2_region</RegionName><City>$geoip2_city</City><ZipCode>$geoip2_postal_code</ZipCode><Latitude>$geoip2_latitude</Latitude><Longitude>$geoip2_longitude</Longitude><MetroCode>$geoip2_dma_code</MetroCode></Response>'; | ||
} | ||
|
||
if ($arg_format = "csv") { | ||
add_header Content-Type text/csv; | ||
set $mybody '$realip,$geoip2_country_code,$geoip2_region_code,$geoip2_region,$geoip2_city,$geoip2_postal_code,$geoip2_latitude,$geoip2_longitude,$geoip2_dma_code'; | ||
} | ||
|
||
if ($arg_callback) { | ||
add_header Content-Type application/javascript; | ||
return 200 '$arg_callback($mybody);'; | ||
} | ||
|
||
return 200 $mybody; | ||
} | ||
} |