Why Can’t I Access My Backend on AWS EC2?

0
1
Asked By TechieGum48 On

Hey everyone! I'm diving into AWS by deploying a MERN full-stack app on an EC2 Linux instance, but I'm running into a snag with my backend. Here's the rundown of what I've done so far: I've launched an EC2 instance and SSH'd into it. I installed Node.js and cloned both the frontend and backend repos. For the frontend, I ran npm install followed by npm run build, installed Nginx, enabled the service, and copied the build files to /var/www/html. I've opened inbound rules for ports 80, 443, and 7777, and everything works perfectly on the frontend using the public IP.

Now for the backend part: After installing the backend dependencies with npm install and starting it with npm start, it works just fine when accessing via curl on both localhost and the public IP from within the EC2 instance. However, I'm unable to access the backend from my local machine using the public IP. Even running it with PM2 doesn't change anything! I've run through this process three times without success.

I'm wondering if it could be related to binding the server to localhost versus 0.0.0.0, issues with security groups, or something entirely different? Thanks a lot for any help!

5 Answers

Answered By CloudCrafter11 On

Another thing to consider is any local firewall settings on your machine that might be blocking the access. Just ensure nothing on your local network is preventing the request from going through.

Answered By ServerNinja17 On

If you want to further troubleshoot, create a second EC2 instance in the same VPC and try accessing the backend using its private IP with curl. This can help determine if the issue is with external access or something else in the setup.

Answered By NetworkWhiz34 On

Just a heads-up, if 13.60.42.60 is your public IP, you should run `netstat -anp | grep 7777` to see if the server is actually listening on that port. It might provide insight into what's going wrong!

TechieGum48 -

I ran the command and it shows something like tcp 0 0 0.0.0.0:7777 LISTEN. I’m not sure how to share a screenshot for further help.

Answered By CodeSavant83 On

Make sure you've opened the port in your security groups. Sometimes, the rules might not allow inbound connections on the specified port, which could be causing the issue. Double-check that 7777 is properly configured for incoming traffic!

HelpfulHannah21 -

What kind of error do you get when trying to access it from the browser? Is it timing out or showing some other error message?

Answered By DevGuru22 On

Your Node.js server might be set to bind only to localhost. You need to change it to bind to 0.0.0.0. Update your app.listen section in your server code like this: `app.listen(7777, "0.0.0.0", () => { console.log("Server running on port 7777"); });`. This should help make it accessible externally since you've already done the security group settings right!

CodeExpert77 -

I've already tried that, and it still doesn't work.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.