I have multiple services running on multiple ports on a single AWS EC2
instances. I've been using two ALBs
to run these services, but I'd like to combine them into a single ALB that forwards to the correct service based on the host name. One service is a node app running port 80 and the other is a flask app running on port 5001.
As of now, I have a target group setup as mywebsite
for the node app on port 80, and api-service
for my flask app on port 5001.
I added those target groups to an ALB, my-alb
, and set up forwarding rules so that port 80 and 5001 will forward to port 443. On port 443 I set up forwarding rules so that if the host matches api.*
it will forward to the target group api-service
otherwise it will default to my-website
.
I have also set up my alb as the alias for api.mywebsite.com
and www.mywebsite.com
on route 53 as well as setting up the certificate. All the health checks are passing for both my target groups.
Here's the issue:
www.mywebsite.com
works properly. I get forwarded to the https
version of the site and everything looks fine. When I try to use api.mywebsite.com
it doesn't load and I get a 504 Bad Gateway error.
To summarize, here are the steps I've completed:
- Setup two target groups for my services on
port 80 and 5001
- Added those two target groups to
ALB
and set routing rules to redirect toport 443
- Set forwarding rules for route 443 to forward to the service on
port 5001
if the host matchesapi.*
else route to the service on port 80. - Set the ALB as the alias for
api.mywebsite.com
andwww.mywebsite.com
inroute 53
.
Any help would be appreciated, thanks!
EDIT: Got it working.
I had configured my security group incorrectly. That is the step I was missing :D. Once I added port 5001 to the security group assigned to my ALB and EC2 it began to work properly.
Thanks!