Skip to content

Instantly share code, notes, and snippets.

@williamzujkowski
Created November 3, 2025 22:49
Show Gist options
  • Select an option

  • Save williamzujkowski/8749d27f31c0c222e79033fc978069bd to your computer and use it in GitHub Desktop.

Select an option

Save williamzujkowski/8749d27f31c0c222e79033fc978069bd to your computer and use it in GitHub Desktop.
DoH Advanced Routing - nginx load balancing and geo-based provider selection
#!/usr/bin/env python3
# DoH Provider Selection Based on Geographic Location
def select_doh_provider(client_ip):
"""Select optimal DoH provider based on location"""
# Simplified geo-detection
if client_ip.startswith('192.168.'):
return "https://local-doh.home.arpa/dns-query"
elif is_asian_ip(client_ip):
return "https://dns.google/dns-query" # Better in Asia
else:
return "https://cloudflare-dns.com/dns-query" # Global default
# nginx DoH Load Balancing Configuration
upstream doh_providers {
server 1.1.1.1:443 weight=3;
server dns.google:443 weight=2;
server dns.quad9.net:443 weight=1;
keepalive 32;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment