Can't access my nodeJS web app hosted on AWS EC2 through browser - node.js

I have hosted a nodeJS application on AWS ec2 instance which I can access through ssh but not through my browser i.e, http.
There is no error logged on the console it only shows the following message in the browser:
"unable to connect"
I am aware about security groups and checked them twice I've included http as well as https properly. Please help

Did you configure a web server to direct the requests from the AWS URL to the nodejs application you are running?
Try checking out nginx (https://www.nginx.com/), its really easy and fast to cofigure.
Here is a minimal configuration template:
server {
listen 80;
server_name <aws-url>;
location / {
proxy_pass 127.0.0.1:<node-port>;
}
}

Related

Can't connect to node.js API, EC2 AWS

I am trying to deploy my nodeJS API at Ubuntu Amazon Web Services. The app.js is runing at port 3002
As you can see my app.js is running at port3002 and firewall is allowing the connection with this port
Next test is send a request to my API using curl
curl -d '{"email":"adriel#admin.com","password":"Zxycok159!"}' -H 'Content-Type: application/json' http://localhost:3002/user/login
I got the expected response with curl.
res:
token: f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b
To finish the process I will check my security groups, to allow 3002 port, and my private ip at AWS console.
public IPv4
18.221.231.202
private IPv4
172.31.17.178
It seems to be all right, but when I try to enter in a regular browser http://172.31.17.178:3002
I got a timeout response, can't connect properly and have an API response.
Res:
Unable to access this site 172.31.17.178 took too long to respond.
Try:
Check the connection
Check proxy and firewall
Run Windows Network Diagnostics
ERR_CONNECTION_TIMED_OUT
I tried the most common solutions (AWS EC2 security groups, Ubuntu Firewall, Curl tests) to this issue, but can't connect to API in the browser, any suggestions?
I don't know how can I have the properly response like when I do the same process at my local machine, at my local browser receive the expect response
You're trying to use the private IP of the instance. Use the public Ip of the instance. Private IP is only accessible within your AWS VPC (This depends). Public IP is what clients use to access your application.
The right away to configure nginx for both (front end and backend)
server {
listen 80 default_server;
server_name _;
# react app & front-end files
location / {
root /opt/front-end/dist;
try_files $uri /index.html;
}
# node api reverse proxy
location /api/ {
proxy_pass http://localhost:3002/;
}
}
This is the correct away to configure a website at 80

http to https url in AWS Beanstalk single instance environment

I deployed my NodeJS/Express app on AWS Beanstalk. The current config is :
Environment type: single instance
EC2 instance type: t2.micro
Node.js version: 10.15.0
No load balancer
Proxy server : Nginx
When deployed it gives me a URL http://<app-name>.<server-location>.elasticbeanstalk.com/
I tested (using Postman) my authenticate API with the URL - http://<app-name>.<server-location>.elasticbeanstalk.com/users/authenticate and it gives me the status code of 200 OK and is working fine.
When I use HTTPS instead of HTTP it doesn't work as expected. In postman I get below error:
There was an error connecting to https://<app-name>.<server-location>.elasticbeanstalk.com/users/authenticate
I have my frontend deployed on netlify and when I trigger the same request from my Web application it gives me below error :
The page at 'https://<app-name>.netlify.com/login' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://<app-name>.<server-location>.elasticbeanstalk.com/users/authenticate'. This request has been blocked; the content must be served over HTTPS.
I understand that since my request is coming from https I need to have my backend configured to have https listener. I am not sure as to how I can accomplish this in AWS Beanstalk where I don't have a Load balancer and my env type is a single instance.
I am new to AWS. Appreciate your help. Thanks!
You'll need to add an .ebextension config file to:
Allow 443 traffic in your Security Group
Install the ssl package
copy the certificates from the application package to the ssl dir. (certificates can be created in the certificate manager) or paste them in the config file
edit nginx config
Here is an example
https://edwardsamuel.wordpress.com/2015/07/17/enable-https-and-http-redirect-on-aws-elastic-beanstalk/

Deploy nodejs app on ecs

I'm try launch Nodejs app on alibabacloud ecs with using nginx.
my app is in /var/www/html/ar_exp folder
When I runnode app then app listen localhost:8080
my nginx default config:
`
server {
listen 80;
server_name mydomain.com;
location / {
proxy_pass http://localhost:8080;
}
}
`
When I check from my ecs server via curl mydomain.com or via wget mydomain.com response is correct from nodejs app. But when i check it in browser then: ERR_connection_timed_out.
For all files in nodejs app folder () i set the following settings:
chown -R www-data:www-data /var/www/
and 755 for all files
what else would I check?
Website inaccessibility from the ECS can be due to following reasons.
OS firewall: Make sure that the application OS firewall(ufw) settings are properly configured to allow communication to the application port.
VPC Security Group: Make sure that the security group setting is applied and required communication port is configured.Details to configure security group

Azure App Service getting Error 404 when redirected via NGINX

I created a VM, port 80 is open and installed NGINX on it.
I created 2 App Services which can be accessed via x1.azurewebsites.net and x2.azurewebsites.net
I configured the VM to act as an load balancer but when redirecting the traffic I get the following: https://i.gyazo.com/b94bed9c90d3b0f0c400c83f762f0544.png
I am not using my own domain. Does someone know what the issue could be?
I got the following configurations:
upstream backend {
server xx.azurewebsites.net;
server xxx.azurewebsites.net;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
server_name_;
location / {
proxy_pass http://backend;
}
}
Azure App Service uses cookies for ARR (Application Request Routing). You have to make sure that your NGinx reverse proxy configuration pass the correct cookie / header to your web app.
The other possibility (to make sure the behavior comes from ARR) is to disable it: https://azure.microsoft.com/en-us/blog/disabling-arrs-instance-affinity-in-windows-azure-web-sites/

node.js application running on a port should have no port visible in the URL bar

I have 5 domains pointing to the same machine, let's say these domains are:
example1.com
example2.com
example3.com
example4.com
example5.com
My server has a virtual host file managed by apache, which controls these 5 domains.
I have a node.js app running on port 3000.
If I connect to any of the 5 domains, and type :3000 at the end, I can see the node.js app splash screen.
For example, if I connect to example1.com:3000 it serves me the same page (the node.js app) that can be reached by connecting to example2.com:3000 and example3.com:3000, etc. I understand why this is happening.
However, I am trying to edit my configuration such that the following criteria are met:
Users can only connect to the node app when they type in example5.com, and not any of the other domains.
Users do not have to type in the port number, example5.com:3000, when trying to reach the node app.
I have searched and found some information which leads me to believe this is normally achieved by setting up a reverse proxy, but most examples I find are using nginx or node. It would be nice to figure out a reverse proxy solution with apache so I don't have to re-write all my virtual host logic with node or nginx.
You need to set up a reverse proxy. An easy way to do this is to use nginx. Install and start nginx and in your config file put the following:
server {
listen 80;
server_name example1.com;
location / {
proxy_pass http://localhost:3000;
}
}
And then run your node server on port 3000.

Resources