How to open a port for http traffic on ec2 from node app? - node.js

So I have an ec2 instance running a node app on port 3000, very typical setup. However I now need to run additional apps on this server, which currently are running on their own servers, also on port 3000. So I need to migrate them all to one server, and presumably run them on different ports.
So if I want to run node apps and have them on 3000, 3010, 3020, etc, how do I do this the right way?

You need to authorize inbound traffic to your ec2 instance via AWS Console, or API. Here is a good description how to do that :
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html
Since authorizing is normally a one off, probably better to do it through the AWS Console, however, if one of your requirements is to spin up node apps in different ports in an automated fashion, then you'll probably want to look at this:
http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#authorizeSecurityGroupIngress-property

Related

Node.js multiple domain web hosting

I have a VPS server (ubuntu)
wanted multiple node.js sites to be running on it, thus multiple domains
Was trying out
kubernetes with ha and docker images(containers) per website /But memory consumption would increase and the deployment is complex.
What i Need
I don't care if the database instance is shared
each website can have a own database in the database instance.
Node.js must run in the background, has got some env variables.
Simplest routing based on domain names to node.js port like 3000, 4000, 5000 and so on ..
I would advise using NGINX as described here, Setting up an Nginx Reverse Proxy

Run two applications in the same AWS Cloud9 instance (front-end and API)

I'm trying to run json-server on port 8082 to serve some mock data to the front-end I'm developing using create-react-app (via yarn start to get the dev server on port 8080). Although both servers run correctly in their respective terminals, I can only access the first one I run from the AWS-provided URL, thus making it impossible to perform any kind of HTTP request from the React app to the json-server.
How should I go about this? Probably running two EC2 instances would work, but that seems awfully inefficient...

Does a Node js web server need a domain name to communicate with clients on other devices?

I am working on a swift project for osx with Firebase. I have a node web server to communicate between the clients and the Firebase-server, but it's a localhost-server. Do I need a real domain name to make the server accessible to end-users on another device? (I don't want a web app, just the backend for myself)
you doesn't need a domain .. but you need a serve to deploy having ip address .. suggestion you can use cloud server
You have two ways:
make request on port that the nodejs uses, example http://101.01.01.01:8000
use nginx like proxy, in this setup make your requests on 80 port (it's default), example http://101.01.01.01.
If you wont make something like dev environment on local machine use first case (don't forgot open port for other devices), for production - second.

Do I need a different server to run node.js

sorry if this is a wrong question on this forum but I am simply just stuck and need some advice. I have a shared hosting service and a cloud based hosting server with node.js installed. I want to host my website as normal but I also want to add real time chat and location tracking using node.js I am confused with what I am reading in several places because node.js is itself a server but not designed to host websites? So I have to run 2 different servers? One for the website and one to run node.js? When I setup the cloud one with a node.js script running I can no longer access the webpages.
Whats the best way for me achieve this as I am just going round in circles. Also is there a way I can set up a server on my PC and run and test both of these together before hand so I see what is needed and get it working as it will stop me ordering servers I dont need.
Many thanks for any help or advice.
Node can serve webpages using a framework like Express, but can cause conflicts if run on the same port as another webserver program (Apache, etc). One solution could be to serve your webpages through your webserver on port 80 (or 443 for HTTPS) and run your node server on a different port in order to send information back and forth.
There are a number of ways you can achieve this but here is one popular approach.
You can use NGINX as your front facing web server and proxy the requests to your backend Node service.
In NGINX, for example, you will configure your upstream service as follows:
upstream lucyservice {
server 127.0.0.1:8000;
keepalive 64;
}
The 8000 you see above is just an example, you may be running your Node service on a different port.
Further in your config (in the server config section) you will proxy the requests to your service as follows:
location / {
proxy_pass http://lucyservice;
}
You're Node service can be running in a process manager like forever / pm2 etc. You can have multiple Node services running in a cluster depending on how many processors your machine has etc.
So to recap - your front facing web server will be handling all traffic on port 80 (HTTP) and or 443 (HTTPS) and this will proxy the requests to your Node service running on whatever port(s) you define. All of this can happen on one single server or multiple if you need / desire.

amazon beanstalk tcp app not responding

i am running a nodejs tcp app at my aws linux ec2 instance . the basic code is given below
var net = require('net');
net.createServer(function(socket){
socket.write('hello\n');
socket.on('data', function(data){
socket.write(data.toString().toUpperCase())
});
}).listen(8080);
and its run like charm, but i wanted to run this same app at aws beanstalk (just to get the benefit of auto scaling). ya ya i am not aws ninja. by the way to get the public ip at beanstalk i use aws VPC.
beanstalk app connect to VPC = checked.
VPC 8080 port open = checked .
change hard coded port 8080 to process.env.PORT = checked.
but if i ping anything at port 8080 it does not return 'hello' from the application. what i am missing ?
Your application is not implementing HTTP. ElasticBeanstalk by default is going to configure the Elastic Load Balancer (ELB) to act as an HTTP load balancer. This means your instance is not healthy and is not being put into service by the ELB and the ELB itself would also be rejecting the non-HTTP request.
Important note: While it would be possible to modify ElasticBeanstalk to work for your use case, you are going to be using it in a non-standard way so there will be some risks. If you are regularly creating and deleting environments using CloudFormation or the API then you will likely run into a lot of headaches.
If you are going to just create an environment and leave it running then I suggest you take the following steps.
First off, ElasticBeanstalk's nodejs configuration is going to configure an Nginx server on the EC2 instance, since you are using TCP you will want to bypass this entirely. This can be done by re-configuring the ELB and security groups. It would be easiest to just leave Nginx running, it just will not be used, just make sure it is not on the same port as nodejs.
By default the ELB configuration will look like this:
The step you missed was updating the ELB to use TCP load balancing on the appropriate ports. You can go into the EC2 web console under Load Balancers and update the load balancer configuration for the already created Beanstalk to look like this:
You will also want to modify the health check of the load balancer to be on the correct port:
Last, double check to make sure the security groups for both the load balancer and EC2 instances allow the appropriate ports to be accessed. The last thing to check, but you already mentioned you looked, is that your VPC's NACLs also allow the appropriate ports to be accessed.

Resources