How to Deploy React App to Production on AWS: Complete Guide
By Braincuber Team
Published on April 13, 2026
Deploying a React application to production on AWS is a crucial skill for full-stack developers. This complete tutorial walks you through setting up a production-level AWS deployment from scratch using Express, PostgreSQL, PM2, and nginx. You will learn about VPC networking, EC2 instances, RDS databases, and how to configure a reverse proxy for optimal performance.
What You'll Learn:
- Understanding AWS VPC and subnetting concepts
- Step by step guide to setting up VPC and subnets
- Complete tutorial on launching EC2 instances
- Beginner guide to AWS RDS PostgreSQL setup
- How to configure nginx as a reverse proxy
- Complete guide to PM2 process management
- Deploying React production build to AWS
Why Learn AWS Deployment?
AWS is currently the biggest cloud computing platform. While WordPress powers many smaller websites, AWS is used by the vast majority of commercial high-traffic websites. This means people with AWS skills are in huge demand in the job market.
This tutorial assumes very little prior knowledge about AWS and is designed as a beginner guide. We will stay in the free tier so following along will not cost you anything. By the end, you will have a complete production-ready deployment.
Understanding AWS Networking
Cloud computing has drastically simplified deploying a web app. Services like Digital Ocean and Heroku make it easy by hiding complexity, but for robust, highly secure, and performant setups, we need to do it from scratch on AWS.
The AWS setup will mainly involve networking, which is why most of this tutorial focuses on networking concepts and setups. Everything else such as provisioning databases and EC2 instances is easy on AWS - networking will be the biggest challenge.
How Networking Works in Cloud Computing
Networking in cloud computing works basically the same way as hardware networking, except everything that is hardware (routers, switches, internet gateways) is virtualized. Networking determines how virtual resources communicate with each other and the wider internet.
VPC
Virtual Private Cloud - a virtual location to deploy AWS resources like web servers, databases, and messaging services.
Subnets
Sub-networks that divide your VPC for performance and security. Public subnets are internet-accessible; private subnets are not.
Public vs Private IP Addresses
A public IP address is the location of your computer on the wider internet. The same way you can have an IP address on the internet, you can also have an IP address in another network that is not the internet. Private IP addresses identify computers on your own network, while public IP addresses identify computers on the internet network.
IPv4 Addresses and CIDR Notation
IPv4 is the format in which IP addresses are written. Example: 10.12.15.22. IPv4 has 4 octets (bytes), each containing 8 bits. Since each bit can be 0 or 1, there are 2^8 = 256 combinations per octet (0-255), giving us 256^4 = 4.3 billion different IP addresses.
CIDR Notation Example
10.11.12.0/24 means the first 24 bits are the network prefix, leaving 8 bits for host addresses (256 total IPs).
Simple EBS Deployment First
Before doing our complex deployment, we can do a simple Elastic Beanstalk deployment to get acquainted with AWS. AWS Elastic Beanstalk is a way to launch an app to the cloud without manually setting up underlying resources like VPC, web server, and database.
Create AWS Account
Go to AWS home page and create a new account if you don't already have one.
Navigate to Elastic Beanstalk
Go to Services then Elastic Beanstalk under Compute section.
Create New Application
Click Create New Application, give it a name and description.
Select Platform
Select Node.js as the platform and use the Sample Application.
Launch Environment
Click Create Environment. Your app will be deployed and you'll get a URL.
Important: Clean Up
Always terminate your Elastic Beanstalk environment when done to avoid charges. Click Actions then Terminate Environment.
Production VPC Setup
Now let's set up the production VPC from scratch. This will give you a better understanding of how VPCs work.
Creating the VPC
Go to the VPC dashboard under Network & Content Delivery section. Click on VPCs tab and Create VPC button.
| Setting | Value |
|---|---|
| Name Tag | VPC-Production |
| IPv4 CIDR Block | 10.11.0.0/16 |
| Tenancy | Default |
Creating Subnets
We need both public and private subnets. The public subnet will contain our web server (accessible over internet), and the private subnet will contain our database (not accessible over internet).
| Subnet Name | Availability Zone | IPv4 CIDR Block |
|---|---|---|
| Public Subnet 1 | us-east-1a | 10.11.1.0/24 |
| Public Subnet 2 | us-east-1b | 10.11.2.0/24 |
| Private Subnet 1 | us-east-1a | 10.11.3.0/24 |
| Private Subnet 2 | us-east-1b | 10.11.4.0/24 |
Internet Gateway and Route Tables
Create an Internet Gateway and attach it to your VPC. Then create a route table for the public subnet with a route to 0.0.0.0/0 pointing to the Internet Gateway.
Destination: 10.11.0.0/16 -> Target: local
Destination: 0.0.0.0/0 -> Target: igw-xxxxxxxx (Internet Gateway)
Security Groups
Security groups are firewalls that filter incoming and outgoing traffic. Create security groups for your web server and database.
| Port | Protocol | Source |
|---|---|---|
| 22 (SSH) | TCP | Your IP |
| 80 (HTTP) | TCP | 0.0.0.0/0 |
| 443 (HTTPS) | TCP | 0.0.0.0/0 |
| 5432 (PostgreSQL) | TCP | Web Server Security Group |
Launching EC2 Instance
EC2 is the computing in cloud computing - essentially a virtual computer with CPU, RAM, and Hard Drive. We will use Amazon Linux AMI 2 as the operating system.
Select Amazon Linux AMI
Choose Amazon Linux 2 as the operating system.
Choose Instance Type
Select t2.micro to stay in the free tier.
Configure Instance
Select your VPC and public subnet. Enable Auto-assign Public IP.
Create Key Pair
Create a new key pair, download the .pem file, and keep it safe.
Launch Instance
Review and launch. SSH into instance using your key pair.
ssh -i "your-keypair.pem" ec2-user@public-ip-address
Setting Up RDS PostgreSQL
Go to RDS under Database section. First, create a DB Subnet Group that spans 2 availability zones, then create your PostgreSQL database.
DB Subnet Group
Protect against server failure by spanning 2 availability zones.
Private Access
Set publicly accessible to NO for security. Connect via SSH tunnel.
Database Connection
SSH into your EC2 instance first, then connect to RDS: psql -d dbname -h hostname -p 5432 -U username
Preparing React Production Build
Before deploying, prepare your React app for production. Run the build command to generate optimized files.
npm run build
Configure your Express server to serve the React build files. Update your server.js:
app.use(express.static(path.join(__dirname, 'build')));
if (process.env.NODE_ENV === 'production') {
app.get('/*', function (req, res) {
res.sendFile(path.join(__dirname, 'build', 'index.html'));
});
}
Deploying to EC2 and Configuring nginx
SSH into your EC2 instance, clone your project, install dependencies, and configure nginx as a reverse proxy.
Install Git and Clone
sudo yum install git then sudo git clone your-repo-url
Install Node.js
Install nvm first, then use nvm to install Node.js and npm.
Install nginx
sudo amazon-linux-extras install nginx1.12
Configure nginx
Edit /etc/nginx/nginx.conf to serve React build and proxy API requests.
Restart nginx
sudo systemctl restart nginx
location / {
root /your-project/build;
index index.html;
try_files $uri /index.html;
}
location /api/ {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
PM2 Process Management
PM2 is a cluster manager that runs your app automatically and restarts it if it crashes. Install it globally to manage your Express server.
npm install pm2 -g
pm2 start server.js -i max
pm2 list
pm2 restart server
pm2 stop server
pm2 delete server
Auto-Restart
PM2 automatically restarts your app if it crashes, ensuring high availability.
Load Balancing
The -i max flag uses all CPU cores for maximum performance.
Frequently Asked Questions
What is the free tier limit for AWS EC2?
AWS offers 750 hours of t2.micro or t3.micro instance usage free per month for the first 12 months.
Can I use PostgreSQL instead of MySQL?
Yes, this tutorial uses PostgreSQL with AWS RDS. The setup process is similar for MySQL.
Why use nginx as a reverse proxy?
nginx acts as a load balancer, improves security, prevents DoS attacks, and helps Node.js with performance and reliability.
How do I connect to a private RDS database?
SSH into your EC2 instance first, then connect to the database from that instance using the psql command.
What is PM2 used for?
PM2 is a process manager that keeps your Node.js application running, automatically restarts it on crashes, and enables load balancing across CPU cores.
Need Help with AWS Deployment?
Our experts can help you deploy and manage your full-stack applications on AWS. Get free consultation for your cloud infrastructure today.
