AWS ECS dynamic port mapping + nginx + app AWS ECS dynamic port mapping + nginx + app nginx nginx

AWS ECS dynamic port mapping + nginx + app


I don't think trying to reach this dynamic port makes a lot of sense...

Currently your have only one nginx server running, so you have an application load balancer, that directs incoming traffic on port 80 to an EC2 instance, at the random port corresponding to your web server container.

<ALB domain name>:80 -> <container EC2 instance IP>:<container dynamic port>

But if your service was scaling up, you would have two containers, running on two different ports, possibly on different EC2 instances.

<ALB domain name>:80 -> <container EC2 instance IP>:<dynamic port>                     -> <container2 EC2 instance IP>:<another dynamic port>

Your ALB would contact in round-robin each of these containers alternatively.

Mapping to one of these containers on its dynamic port directly would be losing the advantage of the load balancer by bypassing it.

So your proxy that adds SSL has to reach the load balancer itself, on its internal domain name (or the one you would have assigned in Route 53), on port 80.


You can useJWilder Nginx Proxy docker container. This allows you to do the dynamic mapping using environmental variables which is configurable in ECS.