Skip to content

Instantly share code, notes, and snippets.

@phamquocbuu
Created January 11, 2018 04:32
Show Gist options
  • Save phamquocbuu/93056297f81084906c88b4070111bf59 to your computer and use it in GitHub Desktop.
Save phamquocbuu/93056297f81084906c88b4070111bf59 to your computer and use it in GitHub Desktop.
NGINX Proxy with Geo module
# https://serverfault.com/questions/545441/nginx-geo-location-module-configuration-using-geo-database
# http://nginx.org/en/docs/http/ngx_http_geo_module.html#directives
# https://www.howtoforge.com/nginx-how-to-block-visitors-by-country-with-the-geoip-module-debian-ubuntu
# https://dev.maxmind.com/geoip/legacy/geolite/
geoip_country /usr/share/GeoIP/GeoIP.dat;
map $geoip_country_code $backend {
default US;
US US;
CN DE;
DE DE;
FR DE;
EU DE;
}
upstream DE {
server IP_DE; #Server A
}
upstream US {
server IP_US; #Server B
}
##
# Virtual Host Configs
##
server {
listen 80;
location / {
proxy_pass http://$backend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment