Technical · Cloud

AWS ALB Health Check for multiples app or services on NGINX

February 9, 2022

AWS ALB Health Check for multiples apps or services on NGINX — 23blocks

Diagram of a load balancer distributing traffic across three servers

There are many reasons to deploy multiple apps or services on an NGINX AWS EC2 instance, from cost savings to redundancy. In our case, we have an Application Load Balancer handling all requests to a Target Group (or Server Farm). However, in those cases is not just straightforward to set up the targets health check.

This post presents a solution to that scenario.

Case

Our EC2 Instance has a default website on port 80 and 2 or more apps on port 80 but with different host headers (ie: aka.mydomain.com, afa.mydomain.com, etc), so when it is time to set up the Target Group Health Check we need a solution to how to monitor each service (or app) instead of the default NGINX site.

Solution

We ended up changing our default NGIX website (etc/nginx/sites-available/default) by including the following segment:

location /aka { 
proxy_set_header Host aka.mydomain.com;
proxy_pass http://127.0.0.1/health;
}
location /afa { 
proxy_set_header Host afa.mydomain.com;
proxy_pass http://127.0.0.1/health;
}

Therefore, on each Target Group, we can use on the path of the Health Check “/aka” and in the other Target Group “/afa”. We are doing an NGINX redirect and adding the host header, the health route is a health check page on all our applications that returns 200 and some details of the status of our apps and services.

Now, Our EC2 instance running multiple NGINX apps or services can be a target on both Target Groups and the health check will do its job if one of the services is down sending requests to any other available targets.

Do you have an idea and want to make a prototype to see if it is functional or sustainable over time? Then, 23blocks is the best solution that you will find to carry out this development with less effort and investment.

Each of our blocks is a combination of Software, Infrastructure, and Services, which are available as API Microservices. According to industry standards, these are hosted in a highly available cloud, ready for production and use.

Deciding to start a software project can be complicated and intimidating. So, contact us at info@23blocks.com to receive free assistance from our software experts and get started on your idea.

There is a better way to build apps and platforms -the #23blocksway.

Originally published at https://23blocks.com on February 9, 2022.

Originally published on Medium in 23blocks.

Related reading

More in the Digest — a weekly roundup of AI and agents news — or start with AI Strategy.