Hosting web application on Amazon AWS EC2 - node.js

I am developing a web application locally. However, I would like to host the final product on an Amazon EC2 instance. I have moved my web application to the EC2 instance and am able to run the application; it's now listening on port 8081.
What I don't understand is how to allow users on the internet to access the web application running on port 8081 of the EC2 instance. I have tried redirecting the domain name to the IP address of the EC2 instance on the NameCheap DNS (where we bought the domain) to no avail. I suspect one of the things I need to do is set the permissions of the EC2 permission group but what should I set it to?
Help is greatly appreciated!
Thanks!

You can setup a nginx server to proxy all request to the port 8081.
Read more information here: https://doesnotscale.com/deploying-node-js-with-pm2-and-nginx/

Generally speaking, for a public web application you will want to run on a standard port (e.g. 80 or 443). You could do that by just running your node app as a privileged user (required by most OS's to expose 80 or 443), but generally it's better to have a web server in front pass the traffic, treating your node app as an upstream server (even if it's on localhost). NGinX is a good choice for this.
Regardless of what port you want to run it on, you'll need to update your EC2 security policy for that instance to allow traffic on that port (80, 443, 8081, whatever). You'll also need to make sure it's exposing a public IP address. It's not a bad idea to assign it an Elastic IP, since you'll wnat it to have the same address across instance reboots.
Finally, depending on what AMI you're running from, there may be a host firewall configured that you'll need to check on and configure to allow the traffic.

Related

Webserver not accessible on port 8080 after configuring Proxy

Let me start by saying I'm very new to this:
We have a linux server behind secure environment (No internet access). I was running apache webserver on that machine in port 8080 and it was accessible within the company network. Recently we asked networking team to configure us Proxy address so that the server can access Internet to perform yum, wget and few other maintenance related task.
The networking team configured http and https proxy on port 8080 and gave us a proxy address to use (http://someproxyaddress.com:8080). Now the port 8080 is connected to proxy server and apache service has been kicked out from that port. hence, it's unreachable. what kind of configuration changes do I have to make so I can access the apache web server from another machine within the company?

How do I set up my application/EC2 instance so that I don't have to put the port number at the end of the IP?

I'm trying to point my domain to my EC2 instance but it isn't working because my EC2 needs the port (:3000) at the end of the IP in order to be resolved. I'm having a really difficult time finding information on this, any help would be appreciated!
You can set up an internet facing load balancer to redirect the port 80 from public access to your ec2 instance with any port.
internet users -> hit your new created load balancer with port 80 or 443 -> set redirection rules to backend (ec2:port)
There are several types of aws loadbalancer, you can start with Elastic load balancer
if you want to save the cost, you can install nginx or haproxy on your ec2 instances to expose the port 80 directly.

Cannot access EC2 on specific port, even though I added security group

I created a web application and mounted it on an EC2 Windows instance.
Since it is created with Node.js Express and I didn't touch anything about localhost or port stuffs,
it is being listened on the port 3000 on npm start.
After I did npm start on the EC2 instance, then I can access it by "localhost:3000" within the EC2.
But when I try to access it from outside the EC2 with its public IP, like ip_address:3000, it keeps returning connection timed out error.
As I wrote in the title, I added a custom TCP security group that makes the instance opened for any IP addresses and with port 3000 but it still doesn't work.
What can I do? What am I possibly missing?
Thanks in advance.
Couple of things could be going wrong here.
Firstly - confirm your web application is actually running from within the instance.To do this on any recent windows in powershell: Invoke-WebRequest http://localhost:3000.
Secondly - confirm the security group on the instance allows incoming traffic for your designated port - HTTP(80) or HTTPS(443).
Thirdly - since you mentioned your instance has a Public IPv4 address, it must be located within a VPC and a Subnet. Navigate to the VPC service within the AWS Console and have a look at the Network ACL for that subnet. It's possibly denying all incoming traffic - rendering your security group settings unused.
If you're unsure on whether the subnet is blocking incoming traffic or not, have a look at these docs.

how to make nodejs server available online from aws win

I have aws windows server 64bit
installed nodejs on it
uploaded nodejs project
run node server.js
on aws i can access my node application on url localhost:8080
i want to make it available online
in windows firewall every thing is green
I have created new inbound rule for port 8080 and allowed that is also green
You need to modify the instance's security group to permit inbound connections on port 8080. A security group acts as a virtual firewall for the instances associated with it. By default no inbound connections are permitted.

AWS EC2 custom domain - subdomains and ports

I've started to get into AWS today and created a simple EC2 Instance with a Node.js app listening on port 3001.
I can access it through my public DNS at ec2-12-34-123-123.eu-central.amazonaws.com:3001 and get a Hello World output.
Not I'm trying to set up a custom domain to this instance.
I've done the following steps:
Created a domain with Route 53
Created an Elastic IP and assigned it to my EC2 Instance
Created a Hosted Zone and an A record for the Elastic IP
But still I can't access my server via mydomain.com:3001
Did I do anything wrong?
And how can I setup multiple subdomains forwarding to a specific port?
For example:
api.mydomain.com
mydomain.com
jenkins.mydomain.com
and so on, when everything is listening on another port?
Creating a record for my IP:port I get wrong value, because the ip:port syntax is not valid.
Edit:
Just did everything again.
created EC2 instance, launched node app on port 80
created elastic ip
created hosted zone for domain
registered ns on registrar for my domain
created A record for www.mydomain.xyz + alias mydomain.xyz
When I try to go to www.mydomain.xyz I only get the Gandi page with my data.
Does anyone know what I did wrong?
How long has it been since you registered the domain and created the CNAME or A record to point to your server? It can take about 24 hours for this to propagate and start resolving to your server.
Subdomains are DNS entries that point to a server. You can't forward them to a specific port, they basically point to all ports on the server. If you don't want to include a port number in the URL then you need to have something listening on the default port (port 80 for HTTP, or port 443 for HTTPS). If you need multiple web servers running on different ports on a single server, then you would need to add a reverse proxy like Nginx to that server to map the different domain names to the different ports.

Resources