How to implement different reverse proxy via geoip

I would like to establish a website myself. The reverse proxy for this website in China is In other countries, the reverse proxy for the website is
How to configure to achieve this operation, I hope to give a useful example.Thank you.

Hi @lilei,

Initially I was going to recommend using rewrite and http.geoip together to make this transparent to the client, but I note that rewrite operates before geoip in the middleware chain so we can’t rely on the geolocation data being available to the rewrite.

Instead, you’ll have to use subdomains and redirects (or perhaps subfolders, depending on your requirements). This redirection will be visible to the client. {
  geoip /path/to/database.mmdb

  redir { # Direct CN users to other site
    if {geoip_country_code} is CN

  # Non-CN users proxy to
  proxy /
} {
  # CN users should arrive here to be proxied to
  proxy /

1 Like

Not this, what I want is to visit’s website in different regions. Do not open another second-level domain name and do not redirect it.

The above example does neither; non-CN clients will receive content proxied from when they browse to, and CN clients will be redirected to (a subdomain of the same second-level registered domain name) and receive content proxied from

Nobody browsing to is redirected away from

Then I’ll invite anyone else with any ideas to chime in on this post; since proxy upstreams cannot be dynamic, rewrite or redir are the only methods to discriminate based on things like geoip information, and rewrite is ineligible (geoip is not calculated until after rewrite is already finished).

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