I would like to establish a website A.com myself. The reverse proxy for this website in China is B.com. In other countries, the reverse proxy for the website is C.com.
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.
example.com {
geoip /path/to/database.mmdb
redir { # Direct CN users to other site
if {geoip_country_code} is CN
/ https://b.example.com{uri}
}
# Non-CN users proxy to C.com
proxy / C.com
}
b.example.com {
# CN users should arrive here to be proxied to B.com
proxy / B.com
}
https://caddyserver.com/docs/http.geoip
https://caddyserver.com/docs/redir
Not this, what I want is to visit A.com’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 C.com
when they browse to example.com
, and CN clients will be redirected to b.example.com
(a subdomain of the same second-level registered domain name) and receive content proxied from B.com
.
Nobody browsing to example.com
is redirected away from example.com
.
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.