I have two containers on AWS EC2 instance and I run them with docker-compose. These two different containers consisted of the backend and frontend images of my project. When I run it with the DNS address + :3000 port on AWS, I can see the front-end page, but when I try to login in my project (sign-up endpoint gets the same error), I get an ERR_CONNECTION_REFUSED error.
So I thought there might be a problem with the ports.
- When I send a request from postman on AWS’s DNS address + :8080, the
backend responds to me without any problems. - The cURL requests (localhost:8080) made in the instance’s terminal to the
backend work without any problems. - However, the frontend cannot send requests to the backend listening
on localhost:8080 in the same instance.
What am I missing?
Extras:
DOCKER-COMPOSE FILE
version: '3'
services:
book-portal-back-end:
image: "ugurcanerdogan/book-portal-be:v1"
container_name: ugurcanerdogan-bookPortal-be
ports:
- "8080:8080"
environment:
- SPRING.PROFILES.ACTIVE=default
book-portal-front-end:
image: "ugurcanerdogan/book-portal-fe:v1"
container_name: ugurcanerdogan-bookPortal-fe
ports:
- "3000:3000"
links:
- book-portal-back-end
Inbound rules of instance:
2
Answers
The real problem here was my "login" endpoint. There was no really a /login endpoint (I was catching login requests with filters, I didn't have any login endpoints under a @Controller) so every request was being denied. I changed my JWT and login-register implementation now it works well!
You need to look at the Security Groups associated with your FE & BE instances Make sure your FE instance allows outgoing connections to the BE instance, furthermore you need to ensure that the BE instance will allow incoming connections from your FE instance on port 8080
Something like this:
FE Instance Security Group (Outgoing) you will need the following:
Type: Custom TCP
Protocol: TCP
Port Range: 3000
Source: External IP of BE instance or Security Group
BE Instance Security Group (Incoming):
Type: Custom TCP
Protocol: TCP
Port Range: 8080
Source: External IP of FE instance or Security Group