Custom Amazon Elastic Load Balancing: with email forwarding and redirects

image

The release of my project of the day was approaching. Mobile apps have been downloaded in the app stores and we waited for an answer from Apple, because the check in Google Play is relatively quick and painless. The entire code of the server application was written, had nothing to do, and free time was about a week. I thought it would be nice to advance and get a load balancer-om that in the future not to spend a lot of time customizing it, and also configure after the release probably would have led to the fact that the server for some time ceased to serve users. For hosting the servers we used Amazon EC2, and therefore load balancer chose nasonovskiy — Amazon Elastic Load Balancer (ELB).

How


Domain was registered at Internet.bs on the ec2 server was set to a static ip address using elastic ip. Accordingly the Registrar was a record (A record), which pointed to this ip. Also good Registrar will provide a way to configure email forwarding, which I gladly took to get to your mail box, sent to feeback@имярек.com. Even the Registrar was able to do a redirect from one subdomain to another, what I used to redirect all users with www.имярек.com imerica. When you move want to keep it, without additional servers and applications, and certainly had no desire to write additional code.

Relocation: ELB, Route53 and NS Records


The first thing I did was set up the ELB. It's all quite simple: in the EC2 tab, Load Balancers, click Create to create a Load Balancer using a convenient dialog box, select the ports on which the server will match the ports ELB, custom Health Check (periodically checking the availability of a certain URL on the server, the ELB will determine which server is "alive," and what is not to submit requests because they don't answer), and select the server on which distributed load. All these parameters can then be exchanged and working ELB. By the way, if your web application uses HTTPS, I recommend to configure your ELB and application server to use http, it's great to unload your servers. In our case, it was able to handle several times more requests per second.

Then it's time to link the domain name to the ELB, because ELB and although it has not been configured, the application server is still used directly. Since ELB uses a dynamic ip address, bind it simply by using A record will not work. It will have to use another service with Amazon Route 53. You need to create a Hosted Zone with our domain name. This creates 2 records — NS and SOA. To link the domain name to the Hosted Zone you want to create or replace the NS record at the Registrar of the domain values of the NS records Hosted Zone. Next you need to specify which will fit our domain, for this you need to create a Hosted Zone a record (A record) of the selected alias and from the drop down list Alias Target to choose our ELB.

image

After that our server has again become available at the old address. But he began to respond only to requests for the address without www and with www address not answered actually.

Custom 301 Redirect domain without www to domain with www


You can configure and Vice versa, the setting is completely analogous. Why not 301 Redirect another A record pointing to the same ELB? From the point of view of search systems in this case we will have two site with identical content but search engines such to put it mildly not in favor.
To set up a redirect was not as easy as it was possible to make our Registrar. As a solution on the forums and on Stack Overflow to set up a redirect in Apache or nginx, but that decision does not suit us because our application server — Apache Tomcat. To give him another server, not like — hate increased response time. It was also suggested to write code with the appropriate logic, but do not want to.

image

Then in Route 53 Hosted Zone in our domain create A record on the domain name with www(or without) option and specify the alias as the alias target our S3 bucket created.

image

Great, now our domain with www and without www, and even correctly redirects the user to the selected option.

Email Forwarding


Unfortunately, to configure Email Forwarding services Amazon will not work, because such a service just yet. But I found great service ImprovMX, which made it possible to configure email forwarding in just a minute. Instructions for setting up (if you can call it that, because it requires only one action) is also on the site. All you need to do in the Hosted Zone create an MX record with the following content:

the
10 mx1.improvmx.com 
20 mx2.improvmx.com

It remains only to enter the name of the domain and a mailbox that will receive the redirected mail.

Opinion


What we got in the end: the distribution of the load between our application servers, while retaining the desired functionality — redirect domain without www domain c www and email forwarding. Bonus received a performance increase, and the ability to quickly increase performance by simply adding more servers. Thank you for your attention.
Article based on information from habrahabr.ru

Комментарии

Популярные сообщения из этого блога

ODBC Firebird, Postgresql, executing queries in Powershell

Installation LivestreetCMS on MODX Revolution package 10 clicks

The Ministry of communications wants to ban phones without GLONASS