0

first of all I am very new to the subject and the headline maybe wrong but here is what I would like to achieve:

Currently I have web server as origin which all clients connect to but as you can guess this is a very basic setup with no redundancy and also exposes my origin with all the data to the public.

What I want to do is, let's say I have web server in country A which is my origin and has all the contents. I have 3 nginx (free edition) servers in countries A,B and C which cache the contents of my origin plus they apply some simple rules to the requests.

Origin server IP : 1.1.1.1 Nginx A IP : 1.1.1.2 Nginx B IP : 1.1.1.3 Nginx C IP : 1.1.1.4

Load Balancer IP : 1.1.1.10

What I want to achieve is if a client wants to access the content from country A he should be forwarded to Nginx in country A, so on and so forth for other countries.

Also I would like to have a health check in place so if Nginx in country C failed traffic gets split into Nginx A and B.

What I understand is you can have a Nginx set up as load balancer (1.1.1.10) which has the other 3 Nginx(s) as upstreams and will get the content based on the rules you set (GEOIP or whatever) but my issue is then I would need a high BW server to do this load balancing because the actual packets are sent through this IP (1.1.1.10), am I correct here?

But what I actually want is if a client from country B accesses this url: http://1.1.1.10/app/image.jpg he should be forwarded to http://1.1.1.3/app/image.jpg

This example is in http but of course https is more desired. For example : https://www.example.com points to 1.1.1.10 https://srvB.example.com points to 1.1.1.3 so https://www.example.com/app/image.jpg from country B would be redirected to https://srvB.example.com/app/image.jpg

Is there any free solution to this ?

I know there are cloud based load balancers like cloudflare which do exactly this but I am trying to keep the cost as low as possible and most of them get pretty expensive when you have a large daily/monthly BW.

While I was reading about my problem I also stumbled upon forward and reverse proxy but I couldn't figure out how those could help me, if this is the solution to my problem can someone explain a bit about this ?

1 Answers1

0

In order to implement system like this, you need to have possibility to do Anycast routing, where same IP address is routed to different targets based on where the source of traffic is.

Wikipedia article describes the concept in more detail.

To implement anycast routing, you need to operate your own network infrastrucure, so that you can configure BGP properly. The only reasonable solutions available for end-users are CDN providers like Cloudflare.

One possibility is to set up a redirect server that sends visitors to country-specific servers via HTTP redirects. However, this adds performance penalty and application complexity, and might not work in reality. Content duplication is also an issue for Google.

The principle is that you have a webserver at www.example.com, and that would return 301 redirect to us.example.com for visitors that come from US.

Then the us.example.com would run in a webserver in USA.

Similarly, de.example.com redirect would be returned for visitors that come from Germany, and that domain's server would be in Germany.

Duplicate content issue arises if the content on both us.example.com and de.example.com is the same. Google will give penalty for either or both sites because of the duplicate content.

Further problems with this setup:

  • What would happen when a visitor from Germany visits us.example.com?
  • How would you set up the URL structure on the sites? Would everything point to www.example.com and then every request would be redirected?

Reverse proxy isn't useful here. In reverse proxy setup, all visitors connect to the reverse proxy server, which then relays the requests to the origin server. This means that for a visitor in US, reverse proxy in Germany, the traffic goes two times over the Atlantic:

  1. From visitor to reverse proxy in Germany.
  2. From Germany to upstream server in the US.
Tero Kilkanen
  • 36,796
  • 3
  • 41
  • 63
  • Hi mate, thanks for the explanation. Duplicate content is a must anyway so google penalty is accepted. As for clients visiting other zone server, that's not a big deal either as long as the numbers stay low. But how can I setup nginx to give out the 301 redirects ? maybe this would be my answer after all and can I add something like weight to the redirects like I can with the upstreams ? lastly would there be high load on this nginx (I assume not because it just answers redirects and then it's done) – Sirwan Shams Aug 01 '22 at 12:15
  • The set up of the redirect server depends on many things, so there is not a simple answer for it. Some questions: Are the URLs exactly same on `de` and `us`? You should open another question with all the details on URL structure and what redirects there should be, then it can be answered. – Tero Kilkanen Aug 01 '22 at 18:21