Link Domain to EC2 server Nodejs

if you don’t know how to get start with EC2 following the article first

This article I will introduce to you how to link you domain to Web app on EC2

  • go to services find or search Service name Router 53

create hosted zone

you should to create hosted zone enter your domain you bought

addition some record

  • type A value is public ip of EC2 server


go to domain manage -> name Server manager edit nameServer to point to host on aws seem like

or contact to the company you bought domain

you should waiting about 24 hour to update nameServer

in this time we will go back to EC2 to config some thing

the “things” you need is Nginx, pm2

let’s set up:

$ sudo apt-get update && sudo apt-get upgrade -y
$ sudo apt-get install nginx -y

Setup Nginx

Check status of Nginx and start it using the following commands

$ sudo systemctl status nginx    # To check the status of nginx
$ sudo systemctl start nginx # To start nginx

Make sure that Nginx runing on system startup

$ sudo systemctl enable nginx

Nginx should be up and running,

Setting up Nginx as a reverse proxy for Nodejs application

$ wget -q -O — ‘'$ sudo rm /etc/nginx/sites-available/default
$ sudo vi /etc/nginx/sites-available/default

paste config, and change

server {
listen 80; server_name; location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;

Test the configuration of Nginx using the command below

$ sudo nginx -t

Then reload Nginx if OK is displayed.

$ sudo /etc/init.d/nginx reload


Install PM2 Advanced, production process manager for Nodejs and start Nodejs app with PM2

npm i -g pm2pm2 install ts-nodepm2 start index.ts 

we going to. http://your_public_ip:3000 to check process is open

http://your_public_ip to check successfully to redirect from port 3000 to port 80

and then waiting NameServer is update and try: http://yourdomain

good luck, and thank you

Reference :