Private fargate container cannot access api hosted on public EC2.

0

I have a public EC2 instance that hosts an application and uses nginx for reverse-proxy. It has an api that can be accessed using http. I'm trying to access the api using EC2-public ip from a private fargate container but get "Connection timeout" error. If the container accesses the api using EC2-private ip, it gets the response 404 not found. The security group of the EC2 allows inbound traffic on port 80 from security group of container. There is a NAT gateway involved for private instances to access public sites. If I allow all traffic (0.0.0.0/0) to access port 80 on ec2, then the container can call the api successfully. Both EC2 and container use the same VPC. What am I missing?

1 Answer
1
Accepted Answer

Fixed this by adding an entry for the private ip of ec2 instance in nginx conf.

answered 2 months ago
profile picture
EXPERT
reviewed 2 months ago
profile picture
EXPERT
reviewed 2 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions