I’m an AWS beginner and have tried deploying a MERN app to an AWS EC2 instance. I have successfully deployed this on Heroku before and am moving to AWS.
I followed the steps to point my DNS and set up Nginx, SSL, and pm2 successfully. When I got to my domain, a 500 error is returned.
The error message is:
Error: Can't find / on this server!
at /home/ubuntu/cloud_v2/app.js:49:9
Which is my error message in Node when a route isn’t found. However, the "route" is just the / which is the homepage, and is certainly on the server.
Nginx is running and these are the logs:
2021/04/21 11:18:06 [notice] 28925#28925: signal process started
2021/04/21 11:30:53 [error] 28929#28929: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 54.221.27.173, server: arriveanywhere.xyz, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080/", host: "arriveanywhere.xyz"
2021/04/21 11:54:07 [notice] 29971#29971: signal process started
2021/04/21 16:41:15 [notice] 31724#31724: signal process started
2021/04/21 16:41:19 [notice] 31726#31726: signal process started
2021/04/21 16:41:22 [notice] 31728#31728: signal process started
2021/04/21 16:42:03 [notice] 31730#31730: signal process started
2021/04/21 16:42:49 [notice] 31735#31735: signal process started
2021/04/21 16:45:49 [notice] 31756#31756: signal process started
It failed once this morning but has shown "signal process started" since then.
My ports are:
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN -
tcp 0 0 172.31.11.76:54132 3.232.124.90:27017 ESTABLISHED 29944/server.js
tcp 0 0 172.31.11.76:54128 3.232.124.90:27017 ESTABLISHED 29944/server.js
tcp 0 0 172.31.11.76:40442 3.224.254.52:27017 ESTABLISHED 29944/server.js
tcp 0 604 172.31.11.76:22 69.249.187.35:50408 ESTABLISHED -
tcp 0 0 172.31.11.76:54124 3.232.124.90:27017 ESTABLISHED 29944/server.js
tcp 0 0 172.31.11.76:58498 34.197.51.246:27017 ESTABLISHED 29944/server.js
tcp 0 0 172.31.11.76:40428 3.224.254.52:27017 ESTABLISHED 29944/server.js
tcp 0 0 172.31.11.76:54138 3.232.124.90:27017 ESTABLISHED 29944/server.js
tcp 0 0 172.31.11.76:54126 3.232.124.90:27017 ESTABLISHED 29944/server.js
tcp 0 0 172.31.11.76:58484 34.197.51.246:27017 ESTABLISHED 29944/server.js
tcp 0 0 172.31.11.76:54130 3.232.124.90:27017 ESTABLISHED 29944/server.js
tcp6 0 0 :::8080 :::* LISTEN 29944/server.js
tcp6 0 0 :::22 :::* LISTEN -
8080 is what node is listening to, and is what Nginx is configured to listen to.
If I call http://127.0.0.1:8080/ from Postman, it works.
I’m serving my pages from the build file in my React folder
if(process.env.NODE_ENV === "production") {
app.use(express.static(path.join(__dirname, 'react/build')));
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname+'/react/build/index.html'));
});
}
I would be really grateful if anyone could help me resolve this! Also happy to provide more info. Thanks.
2
Answers
I was not directing my static files properly to Node. I had:
and this was not being read. I changed it to
(process.env.NODE_ENV !== "development")
.I guess your problem is not about AWS, is about your server and finding the files to show. I guess if you was in a new server but not AWS you could have the same error. error 500 is common web-server error. at first you need to be sure if the problem is about your server or it has something to do with AWS. with a simple html file or something like that. — one of the most common causes is redirecting between your server files path to your wished path or access to files. if there is so you should concentrate on .htaccess files in your OS and web server to find the redirect problem. the easiest solution is to renaming .htaccess file of your website and see if the error is resolved. I had the same error but with Apache2, I do not have enough information about Nginx.
here are some more explanation about what I mean:
A:Internal server error
B:Internal server error