0

I have the following dilemma. I have an Amazon EC2 instance running Ubuntu with only the 3001 port open to incoming requests. I have a Nextjs app running in that port and don't have any problem with accessing it through a browser, and an Express Webserver runing in the 3000 port.

As you would notice, the server is not open to the public because the port in which it works is not allowed for incoming connections. Now, as you would know, Next js is full stack, so I supposed that you could interact with the Webserver via NextJs's backend (or api), because it would not be a connection from the outside, but I'm not getting it to work. Whenever I open the 3000 port, I have the response I want, but when I block it, the request is left hanging.

  • 1
    Are both running on a single EC2 instance? What are your instance's security group settings? Does it allow inbound traffic from itself (the security group)? – jarmod Jun 23 '23 at 18:42
  • Yes. They're running in a single EC2 instance. My instance security group settings are the following: accept all TCP traffic through port 3001, and accept incoming TCP traffic from the same security group (referenced by id) through port 3000. Outbound rules allow everything. – Matías Leandro Jun 23 '23 at 19:09
  • Make sure your VPC is using AmazonProvidedDNS and the requests to the app on port 3000 are using the DNS hostname or private IP of the instance, not its public IP. – jarmod Jun 23 '23 at 20:24

1 Answers1

0

I finally figured it out. If I do the requests from the Next API hitting 'localhost' instead of the public IP of my Amazon EC2 Instance i don't have any problems. Even when the 3000 port is completely closed.