Can I serve my static website content and run a node server on the same ec2 Instance . My ec2 instance is a t2.micro ubuntu 14.04 Image. Tasks done : Nodejs,npm installed. Nginx installed configured. Set up the ../../www/ directory to serve content through nginx.
I have a domain xyz.com pointed its @ value to the elastic IP associated with the instance.
uploaded website files to directory . So now if I access xyz.com I get my website content through the nginx . Cool.
But the node app is not accessible. My node app is running on the port 3000.
tried adding
server {
root /var/www;
index: example.js
server_name _;
location / {
proxy_pass http://127.0.0.1:3000;
expires 30d; # not required
access_log off;
}
}
/etc/nginx/sites-available to point to the node server .
Cool . now xyz.com runs my node app . But no website content is accessible now : ( And if I try hitting any API whose routes are defined in my Express routes there are no logs on the server side . only an nginx 404 error eg:
xyz.com/myroute -404 nginx error, works on localhost:3000/myroute
xyz.com/ - returns the default route set for /xyz.com:3000 - doesnot hit the node server. no logs.
Many online resources suggest rerouting the port 80 in the security zone to serve content over the port on which node is running. I could run the node app this way but again the whole website would have to be served through node.
I want to run them separately .
xyz.com - serves me the website
xyz.com:3000 - allows me to hit my node server Should I separate the app and website on to two different instances ? How can they be routed??