How do websites redirect to your location-based version?

How do websites redirect to your location-based version?

Vishnu S's photo
Vishnu S
·Aug 21, 2022·

3 min read

Subscribe to our newsletter and never miss any upcoming articles

Table of contents

  • 1. Create public VPCs and instances.
  • 2. Install a web server.
  • 3. Set up Load balancers (Optional).
  • 4. Set up AWS Global Accelerator

If you search for apple.com from your browser, you'd notice that the site asks you to confirm your location and redirects you to the region-specific website.

When you are hosting an application that serves users globally, the users trying to access your application who are far away from the region(s) in which you published your application may experience higher latency or loading time.

So in order to reduce the latency, some websites directly redirect you to your region-based version of the site and give content (country's currency, special offers, etc.) as per your location.

This process is called Geo IP-based redirection. It detects the visitor's location from their IP address by matching it against a database of IPs and locations. It is one of the ways to reduce latency.

Let's learn how to enable regional-based routing for a website hosted on AWS so that your global users can experience low latency.

We will be using AWS Global accelerator for this purpose. Route 53 can also be used for the same.

image_2022-08-07_015033052.png

1. Create public VPCs and instances.

Start by creating two VPCs - one in the US and one in the EU so that we can create EC2 instances in these regions and host our sample website in them.

  • EU instance image_2022-08-06_210229462.png

  • US instance US instance

2. Install a web server.

Follow the tutorial here and set up web servers in both instances. You can even automate it using tools like Ansible to save time.

Once you set up a web server, change some files of the web server in both of your instances so that you can understand which region it belongs to, for differentiating when we try to reach it later.

  • US version

image_2022-08-06_215845407.png

  • EU version

image_2022-08-06_215821688.png

3. Set up Load balancers (Optional).

Load balancers help us to redirect traffic to our instances. It will help prevent server overload and improve the availability of your website. This step is not necessary for our purpose here as there is not a lot of traffic coming into our websites.

4. Set up AWS Global Accelerator

AWS Global Accelerator helps you to improve the performance of your applications for local and global users.

It provides you with static IP addresses which serve as single fixed entry points for your clients. This means that it allocates IP addresses and associates them to the regional endpoints which you specify (Here, the public IP address of EC2 instances).

Let's move ahead and set up Global accelerator.

  • First, you configure the listeners to identify which ports you want to listen to.

image_2022-08-06_221410314.png

  • Now set up endpoint groups and specify the amount of traffic you want to redirect.

image_2022-08-06_221453479.png

  • Next, we define the endpoints (Public IP addresses of EC2 instances) that we want to reach within each endpoint group. image_2022-08-06_224040821.png

Great! That creates our Global accelerator.

Now, when you try to access the endpoint of the accelerator, you will be redirected to the nearest region in which your website is hosted according to your location.

image_2022-08-06_232617624.png

image_2022-08-06_232640062.png

This is one of the ways of setting up geo-based routing using accelerator.

Route 53 is another service using which we can accomplish the same. But unlike Global accelerator, with Route 53 you can use Geolocation Routing Policy to even direct traffic only to regions of your desire (eg: Indian IP addresses reaching US endpoints instead of EU even though EU is nearer).

Follow to keep posted on my updates.
Cheers.
Vishnu S.

Did you find this article valuable?

Support Community Classroom by becoming a sponsor. Any amount is appreciated!

See recent sponsors Learn more about Hashnode Sponsors
 
Share this