In this tutorial, we will be hosting a separate React and Node.js app in our EC2 instance and map our custom domain. This is the first time I tried to run multiple (Node.js & React JS) apps on my EC2 instances and to my luck, I succeeded in it. I want to ensure nobody should get frustrated in setting up their multiple instances in EC2 like me. It’s quite easy to implement it actually because there are lots of answers are already flooded in StackOverflow but none were practical. This put me up in a situation to write this article and help others because I know that, Sharing is caring. It would be more awesome to run our client in the custom domain and server in the subdomain (eg: & You can get one @ or through any other domain registrar and a domain name is mandatory to complete the remaining steps. Required: https://tamilakam.in https://api.tamilakam.in. GoDaddy I hope you are already aware of Nginx configuration setup. If not, do not worry. We will set it up while working on this tutorial. Deploy your Node.js app in production and map your custom domain. I have already worked on a tutorial to deploy a node.js app in production. You can go through @ _In this tutorial, we will be creating a sample Node.js server, pushing it to BitBucket and using PM2, we will automate…_medium.com Deploy your Node.js app in production and use BitBucket to automate your deployment. In this above tutorial, I have just hosted a Node.js app in a production environment. Using the amazon EC2 default URL and the port number, we could access the server. But now, we are going to map our custom domain to point to our remote server in this tutorial. Note: We will use port 4500 in this tutorial to run our server. I assume you already have experience on Amazon EC2 instance and it’s connection process. If you aren’t, kindly go through the below link, complete the steps provided and get ready with your remote instance before proceeding. _In this part, we will be creating an Amazon account, EC2 instance and connect to that instance via SSH._medium.com Make your Amazon EC2 instance up and running. : Provide your Amazon EC2 address in your Internet Domain Registrar DNS settings. Step 1 IPv4 Public IP Get the IPv4 Public IP address from your Amazon console. It would be like 18.xxx.xxx.15 Add record with values as follows. A Type: AName: api // Sub domain so we can access it like api.tamilakam.inValue: 18.xxx.xxx.15 // TTL: 600 seconds IPv4 Public IP Refer the image below for more info. Add other A records too so that we don’t need to come again here for our client app configurations. DNS Management page — Add Records. : Let’s connect to our remote instance first using the below command from terminal. (Replace your EC2 url in required place) Step 2 $ ssh -i ~/.ssh/AWS-EC2-INSTANCE-LIVE.pem ubuntu@ec2-xx-xxx-xx-xx.us-east-2.compute.amazonaws.com : Dedicate any port to run your Node.js server in EC2. Step 3 Click under in your Amazon console. Security Groups NETWORK & SECURITY Click Security Groups. Right click on your security group for your instance and click . Edit inbound rules Click . Add the following configurations as you see in the below image and click . Add Rule Save Security group config rule. The port 4500 says we are going to run our Node.js server in this port. Add your port in which the server is running. : Install Nginx and configure Step 4 Ubuntu comes with its own package manager, . Using , we can install in one command. apt-get apt-get nginx $ sudo apt-get install nginx runs nginx automatically after install so you should now have it running on port , check by entering your public DNS URL into a browser. apt-get 80 Nginx welcome page. If this doesn’t work, you might need to start it manually. $ sudo /etc/init.d/nginx start Now let’s configure our Nginx to run our Node.js server. How are configs set up? Configs are stored in plain text files in with any name. Linking them into the folder will cause them to be read and used when starts. All of the configs are combined together by . nginx sites-available sites-enabled nginx nginx You can take a look at this config using cat. $ cat /etc/nginx/sites- /default available Let’s first remove the default config from , we will leave it in for reference. sites-enabled sites-available $ sudo rm /etc/nginx/sites- /default enabled Let’s create a config file in with the domain name. sites-available $ sudo nano /etc/nginx/sites- /api.tamilakam.in available The following is the config we are going to use. Type it in your file and save it, replacing your custom domain in the field. server_name server {listen 80;server_name api.tamilakam.in;location / {proxy_set_header X - Real - IP $remote_addr;proxy_set_header Host $http_host;proxy_pass http: //127.0.0.1:4500;}} This will forward all HTTP traffic from port to port . 80 4500 We are listening to the port 4500 where our Node.js server runs and redirecting it to api.tamilakam.in. Link the config file in (this will make it seem like the file is actually copied in ). sites-enabled sites-enabled $ sudo ln -s /etc/nginx/sites-available/api.tamilakam.in /etc/nginx/sites-enabled/api.tamilakam.in Read more about symbolic links here if they are unfamiliar. Restart for the new config to take effect. nginx $ sudo service nginx restart That’s it. Visit and our Node.js API server is ready. https://api.tamilakam.in Deploy your React app in production and map your custom domain. You can refer the below link where I have created a complete sample React application, uploaded it in BitBucket and hosted it as a production application in Amazon EC2 instance with Nginx configured. You can use the same instance to run the client by following the below tutorial. Yes. Now we are running both Server and the Client in the same instance in Amazon EC2. If you have any queries, let me know in the comments. Thank you. References: _In part 1 we started a server, responding to HTTP requests on port 3000. In this tutorial we will look at 4 more…_hackernoon.com Tutorial: Creating and managing a Node.js server on AWS, part 2 _In this tutorial, we will be creating a sample Node.js server, pushing it to BitBucket and using PM2, we will automate…_medium.com Deploy your Node.js app in production and use BitBucket to automate your deployment.