How to use geoip for geo-location jumps

I want to be an international website with multiple domain names. When you want to visit K.comde, jump to A.com.B countries in country A and jump to B.com. Understand the http.geoip plug-in, but do not know how to configure. Hope that the gods give the younger brother a hint. It’s best to write a demo configuration. Thank you

1 Like

There’s a few ways to go about this.

The geoip directive does its work before redir, so the placeholders it sets should be available. I would probably also use a snippet and checks so you don’t have to do a heck of a lot of duplication.

(redir_country) {

  geoip /path/to/db/GeoLite2-City.mmdd

  redir { # USA
    if {hostonly} not_ends_with .com
    if {geoip_country_code} is US
    / https://example.com{uri}
  }
  
  redir { # Germany
    if {hostonly} not_ends_with .com.de
    if {geoip_country_code} is DE
    / https://example.com.de{uri}
  }

  # etc for redirs...

}

example.com {
  root /path/to/US/website
  import redir_country
}

example.com.de {
  root /path/to/DE/website
  import redir_country
}

# etc for domains...

Personally, I’m a fan of doing this transparently (so whatever domain the user goes to doesn’t matter, they get the right webpage). You could do this by keeping the different versions of your website under different folders of your webroot.

example.com, example.com.de, example.com.au {
  root /path/to/websites
  geoip /path/to/db/GeoLite2-City.mmdd
  rewrite {
    to /{geoip_country_code}{path} {path}
  }
}

Keep the default version of your website in /path/to/websites, and then just add subfolders named after the country code which contain the localised versions of the site. Then, if a localised version of a site exists, it will get served, else it will fall back to the default.

2 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.