Amazon Route 53 is used for registering domains and storing DNS records. Basically, it cannot handle HTTP requests redirection which is commonly handled by web or proxy servers. So, we need to implement a kind of web server in front of our service to make redirection. There are two methods that we can try to achieve our need for redirection. First, we can utilize Nginx (or other tools) as a proxy to our service with an additional configuration block for redirection. Second, if our service is hosted on Amazon EC2, we can activate the load balancer service and add a listener for redirecting specific requests.
Nginx as Proxy Server
The configuration for redirection is generally as follows.
server {
listen 80;
server_name old_domain.com;
return 301 http://new_domain.com$request_uri;
}
This method utilizes the load balancer feature in Amazon EC2. In the load balancer listener setting, we need to add a rule to redirect a specific request based on the hostname in the request's header. The additional rule for the HTTP:80 listener of the load balancer is as follows.
- IF: Host is old_domain.com
- THEN: Redirect to http://new_domain.com:80/#{path}?#{query}
We also need to add the correct records in our Amazon Route 53 that host the domains. Some details of the configuration are as follows.
- The record type is A record
- Activate the alias switch on the "Route traffic to" column
- Choose "Alias to Application and Classic Load Balancer"
- Apply the records both on the old domain and the new domain
Comments
Post a Comment