Search code examples
amazon-web-servicesamazon-ec2connectionfirewall

Can't reach server running in blocked port through backend in Amazon EC2


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.


Solution

  • 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.