Skip to content

Commit c4ea259

Browse files
authored
Add Lab11 for GeoIP (#77)
* lab11 initial * lab11 initial * add geoip test * add geoip test * add media * add icons * update dc configs * add downloads config * add downloads config * add downloads config * lab11 updates * lab11 updates * lab11 updates * update outline * update outline * lab11 update * remove extra file * add icons * add icons * fix Nginx > NGINX
1 parent ad3e89b commit c4ea259

24 files changed

+993
-7
lines changed

labs/lab10/readme.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,4 @@ az grafana delete --name $MY_GRAFANA --resource-group $MY_RESOURCEGROUP --yes
171171

172172
-------------
173173

174-
Navigate to ([Lab Guide](../readme.md))
175-
176-
174+
Navigate to ([Lab11](../lab11/readme.md) | [LabGuide](../readme.md))

labs/lab11/GeoIP.conf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# GeoIP.conf file for `geoipupdate` program, for versions >= 3.1.1.
2+
# Used to update GeoIP databases from https://www.maxmind.com.
3+
# For more information about this config file, visit the docs at
4+
# https://dev.maxmind.com/geoip/updating-databases.
5+
6+
# `AccountID` is from your MaxMind account.
7+
AccountID xxxxxxx
8+
9+
# `LicenseKey` is from your MaxMind account.
10+
LicenseKey xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
11+
12+
# `EditionIDs` is from your MaxMind account.
13+
EditionIDs GeoLite2-ASN GeoLite2-City GeoLite2-Country

labs/lab11/as.geo.example.com.conf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Nginx 4 Azure - as.geo.example.com.conf
2+
# Chris Akker, Shouvik Dutta, Adam Currier - Jan 2025
3+
#
4+
# Nginx Server Block for GeoIP Continent Routing
5+
#
6+
# Asia Data Center
7+
#
8+
server {
9+
listen 80;
10+
server_name as.geo.example.com;
11+
12+
location / {
13+
14+
return 200 "Welcome to N4A Workshop, website $host\n";
15+
add_header X-DCTEST-FQDN $host;
16+
17+
}
18+
19+
}

labs/lab11/downloads.example.com.conf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Nginx 4 Azure - downloads.example.com.conf
2+
# Chris Akker, Shouvik Dutta, Adam Currier - Jan 2025
3+
#
4+
# Nginx Map Block for Country Download Export Control
5+
#
6+
map $geoip2_data_continent_code $is_allowed {
7+
CA 1; # Canada
8+
FR 1; # France
9+
DE 1; # Germany
10+
IT 1; # Italy
11+
JP 1; # Japan
12+
UK 1; # United Kingdom
13+
US 1; # United States
14+
default 0;
15+
}
16+
# Download Server
17+
#
18+
server {
19+
listen 80;
20+
server_name downloads.example.com;
21+
22+
access_log /var/log/nginx/downloads.example.com.log geoip2; # Add new GeoIP2 logging
23+
24+
location /downloads {
25+
26+
if ($is_allowed = 0) {
27+
return 403 "Access not allowed from\nCountry: $geoip2_data_country_iso_code\n";
28+
}
29+
30+
return 200 "Welcome to the /downloads URI\nYour IP Address is: $remote_addr\nFrom CountryISO: $geoip2_data_country_iso_code\n";
31+
}
32+
#
33+
# Test Source IPs using XFF Header
34+
#
35+
location /testip {
36+
37+
return 200 "Welcome to /downloads test, GeoIP2 tested IP: $http_x_forwarded_for from\nContinent: $test_geoip2_data_continent_code\nCountryISO: $test_geoip2_data_country_iso_code\n";
38+
39+
}
40+
41+
}

labs/lab11/eu.geo.example.com.conf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Nginx 4 Azure - eu.geo.example.com.conf
2+
# Chris Akker, Shouvik Dutta, Adam Currier - Jan 2025
3+
#
4+
# Nginx Server Block for GeoIP Continent Routing
5+
#
6+
# European Data Center
7+
#
8+
server {
9+
listen 80;
10+
server_name eu.geo.example.com;
11+
12+
location / {
13+
14+
return 200 "Welcome to N4A Workshop, website $host\n";
15+
add_header X-DCTEST-FQDN $host;
16+
17+
}
18+
}

labs/lab11/geo.example.com.conf

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Nginx 4 Azure - geo.example.com.conf
2+
# Chris Akker, Shouvik Dutta, Adam Currier - Jan 2025
3+
#
4+
# Nginx Map Block for GeoIP Continent Routing
5+
#
6+
map $geoip2_data_continent_code $nearest_data_center {
7+
EU eu; # Routes to eu.geo.example.com
8+
NA na; # Routes to na.geo.example.com
9+
AS as; # Routes to as.geo.example.com
10+
default na; # Routes to na.geo.example.com
11+
12+
}
13+
# Main website
14+
server {
15+
listen 80;
16+
server_name geo.example.com;
17+
18+
location / {
19+
20+
return 200 "Welcome to N4A Workshop, GeoIP tracked your IP: $remote_addr from\nContinent: $geoip2_data_continent_code\nCountryISO: $geoip2_data_country_iso_code\nCity: $geoip2_data_city_name\nPostal: $geoip2_data_postal_code\nLat-Long: $geoip2_data_latitude $geoip2_data_longitude\nState: $geoip2_data_state_name\nStateISO: $geoip2_data_state_code\n";
21+
22+
}
23+
#
24+
# Data Center Redirect based on Continent
25+
#
26+
location /dctest {
27+
return 301 http://$nearest_data_center.geo.example.com; # Use HTTP Redirect to closest Data Center
28+
add_header X-GeoIP-Continent $nearest_data_center; # Add an HTTP Header for tracking
29+
}
30+
#
31+
# Test Source IPs using XFF Header
32+
#
33+
location /testip {
34+
35+
return 200 "Welcome to N4A Workshop, GeoIP2 tested IP: $http_x_forwarded_for from\nContinent: $test_geoip2_data_continent_code\nCountryISO: $test_geoip2_data_country_iso_code\nCity: $test_geoip2_data_city_name\nPostal: $test_geoip2_data_postal_code\nLat-Long: $test_geoip2_data_latitude $test_geoip2_data_longitude\nState: $test_geoip2_data_state_name\nStateISO: $test_geoip2_data_state_code\n";
36+
37+
}
38+
39+
40+
}

labs/lab11/geoip2_variables.conf

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Nginx 4 Azure - geoip2_variables.conf
2+
# Chris Akker, Shouvik Dutta, Adam Currier - Jan 2025
3+
#
4+
# Using "GeoLite2-Country" as one of the EditionIDs in /etc/nginx/GeoIP.conf
5+
# Using "GeoLite2-City" as one of the EditionIDs in /etc/nginx/GeoIP.conf
6+
#
7+
# Set geoip2_ variables from City Database
8+
geoip2 /usr/local/share/GeoIP/GeoLite2-City.mmdb {
9+
$geoip2_data_city_name city names en;
10+
$geoip2_data_postal_code postal code;
11+
$geoip2_data_latitude location latitude;
12+
$geoip2_data_longitude location longitude;
13+
$geoip2_data_state_name subdivisions 0 names en;
14+
$geoip2_data_state_code subdivisions 0 iso_code;
15+
16+
# Test IP Address from XFF Header
17+
$test_geoip2_data_city_name source=$http_x_forwarded_for city names en;
18+
$test_geoip2_data_postal_code source=$http_x_forwarded_for postal code;
19+
$test_geoip2_data_latitude source=$http_x_forwarded_for location latitude;
20+
$test_geoip2_data_longitude source=$http_x_forwarded_for location longitude;
21+
$test_geoip2_data_state_name source=$http_x_forwarded_for subdivisions 0 names en;
22+
$test_geoip2_data_state_code source=$http_x_forwarded_for subdivisions 0 iso_code;
23+
}
24+
25+
# Set geoip2_ variables from Country Database
26+
geoip2 /usr/local/share/GeoIP/GeoLite2-Country.mmdb {
27+
$geoip2_data_continent_code continent code;
28+
$geoip2_data_country_iso_code country iso_code;
29+
30+
# Test IP Address from XFF Header
31+
$test_geoip2_data_continent_code source=$http_x_forwarded_for continent code;
32+
$test_geoip2_data_country_iso_code source=$http_x_forwarded_for country iso_code;
33+
}
34+
35+
36+

labs/lab11/media/geoip-icon.jpeg

5.89 KB
Loading
218 KB
Loading
244 KB
Loading

0 commit comments

Comments
 (0)