DevTinder works on localhost. Season 3 puts it on the internet. In this chapter you'll rent a server from AWS, connect to it over SSH, install Node.js and Nginx, and serve the React frontend to anyone with the server's address.
In this chapter you'll learn
- what cloud computing and EC2 are, and the key terms: instance, AMI, instance type, key pair, security group
- how to launch an Ubuntu server and connect to it with SSH
- how to install Node.js the right way on a server
- what Nginx is, and how to serve a React build with it
- why refreshing a React page gives 404 on a server, and the
try_filesfix - security groups (firewall rules) and Elastic IPs
Before you start: you need the finished frontend from Chapter S2 19: DevTinder UI - Part 5 in a GitHub repository, and an AWS account (it asks for a card; the free tier covers this, but set a billing alarm).
Cloud computing and EC2
Running your own physical server means buying hardware, keeping it powered, cooled and connected. Cloud computing lets you rent computing resources by the hour instead.
AWS (Amazon Web Services) is the largest cloud provider. Its EC2 (Elastic Compute Cloud) service rents virtual machines: full computers running inside Amazon's data centres, which you control remotely. This is the "hardware + operating system" layer from Chapter 11: Creating the Server.
Key terms:
| Term | Meaning |
|---|---|
| Instance | one virtual machine |
| AMI (Amazon Machine Image) | the operating system template the instance starts from, e.g. Ubuntu Server |
| Instance type | how much CPU and RAM: t2.micro / t3.micro (1–2 vCPU, 1 GB RAM) are free-tier eligible |
| Region | the data centre location, e.g. Mumbai (ap-south-1). Pick one near your users |
| Key pair | an SSH key used to log in. AWS keeps the public key; you download the private key (.pem) once |
| Security group | a firewall: rules for which ports accept traffic from where |
| Public IP | the address the internet uses to reach your instance |
Step 1: Launch an instance
- In the AWS Console, open EC2 → Launch instance.
- Name:
devTinder. - AMI: Ubuntu Server (the latest LTS).
- Instance type:
t2.microort3.micro(free tier). - Key pair: create a new one (
devTinder-secret), type RSA, format.pem, and download it. You can't download it again; if you lose it, you lose SSH access to the instance. - Network settings: allow SSH (port 22) from My IP only.
- Launch. Wait until the instance state is Running and 2/2 status checks have passed.
Cloud resources cost money once you're past the free tier, and a stopped-but-forgotten instance or an unattached Elastic IP can still bill you. In Billing → Budgets, create a budget alert (for example at $5) on day one.
Step 2: Connect with SSH
SSH (Secure Shell) gives you an encrypted terminal on a remote machine. You prove who you are with the private key instead of a password.
chmod 400 devTinder-secret.pem # macOS/Linux: SSH refuses keys that others can read
ssh -i "devTinder-secret.pem" ubuntu@<your-instance-public-ip>chmod 400 devTinder-secret.pem # macOS/Linux: SSH refuses keys that others can read
ssh -i "devTinder-secret.pem" ubuntu@<your-instance-public-ip>-ipoints to your private key.ubuntuis the default username on Ubuntu AMIs.- Your prompt changes to something like
ubuntu@ip-172-31-5-10:~$: every command now runs on the server.
If SSH hangs, check the security group allows port 22 from your current IP (home IPs change).
Never commit the .pem file to Git or share it. Anyone with it can log into your server.
Step 3: Install Node.js
Install the same major version you use locally, so the app behaves the same. Using nvm (Chapter 03: Let's Write the code) makes this easy, and lets you switch versions later:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
source ~/.bashrc
nvm install 22 # use the same major version as your laptop (node -v)
node -v
npm -vcurl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
source ~/.bashrc
nvm install 22 # use the same major version as your laptop (node -v)
node -v
npm -vOld guides (and the original course notes) install Node.js 20 with setup_20.x. Node.js 20 reached end-of-life in April 2026 and no longer gets security fixes. Use a currently supported LTS version from nodejs.org.
Step 4: Get the code and build it
git clone https://github.com/<you>/devTinder-web.git
cd devTinder-web
npm ci # exact versions from package-lock.json (S2 03)
npm run build # creates the dist/ foldergit clone https://github.com/<you>/devTinder-web.git
cd devTinder-web
npm ci # exact versions from package-lock.json (S2 03)
npm run build # creates the dist/ foldernpm run build turns your React source into a production build: plain, minified HTML, CSS and JavaScript files in dist/. Browsers can't run JSX directly, and the dev server (npm run dev) is for development only. The dist/ folder is all you need to serve.
Step 5: Install Nginx
Nginx (pronounced "engine-x") is a very fast, event-driven web server (Chapter 01: Introduction to NodeJs mentioned its event-driven design). You'll use it for two jobs:
- serving static files (the React build), in this chapter
- acting as a reverse proxy in front of the Node.js backend, in Chapter S3 02: Nginx and Backend Node App Development
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx # start automatically after a rebootsudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx # start automatically after a rebootsystemctl manages background services on Linux: start, stop, restart, reload, status.
Step 6: Deploy the build
Nginx serves files from /var/www/html by default. Replace its welcome page with your build:
sudo rm -rf /var/www/html/*
sudo cp -r dist/* /var/www/html/sudo rm -rf /var/www/html/*
sudo cp -r dist/* /var/www/html/(The original course notes use scp here. scp copies files between machines, for example from your laptop to the server; on the same machine, use cp.)
Fix: refreshing a page gives 404
Open http://<public-ip>/profile directly, or refresh while on it, and Nginx answers 404. Why?
- Your React app is a Single-Page Application (Chapter S2 15: DevTinder UI - Part 1): there's only one real file,
index.html. Routes like/profileexist only inside React Router. - Clicking a
<Link>works, because the browser never asks the server. - But a refresh asks Nginx for a file called
/profile. It doesn't exist, so: 404.
The fix: tell Nginx "if the file doesn't exist, serve index.html", and let React Router handle the URL. Edit the site config:
sudo nano /etc/nginx/sites-available/defaultsudo nano /etc/nginx/sites-available/defaultserver {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html;
server_name _;
location / {
try_files $uri $uri/ /index.html; # file → folder → fall back to the SPA
}
}server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.html;
server_name _;
location / {
try_files $uri $uri/ /index.html; # file → folder → fall back to the SPA
}
}Check the syntax, then reload:
sudo nginx -t # always test before reloading
sudo systemctl reload nginx # apply without dropping connectionssudo nginx -t # always test before reloading
sudo systemctl reload nginx # apply without dropping connectionsStep 7: Open port 80 in the security group
The security group blocks everything you haven't allowed. To let browsers in:
- EC2 → Security Groups → your instance's group → Edit inbound rules.
- Add a rule: Type HTTP, Port 80, Source
0.0.0.0/0(anywhere: it's a public website). - Save. The change applies immediately; there's no need to restart anything.
Now open http://<your-instance-public-ip> in a browser: DevTinder's frontend is live. (It can't log in yet; the backend comes in Chapter S3 02: Nginx and Backend Node App Development.)
Keep the address: Elastic IP
An instance's public IP changes every time it's stopped and started. Anything pointing at the old IP (your domain's DNS, the MongoDB Atlas allow-list) then breaks. An Elastic IP is a fixed public IP you allocate and attach to the instance: EC2 → Elastic IPs → Allocate → Associate. Release it when you delete the instance, since unused Elastic IPs are billed.
Common mistakes
- Losing the
.pemkey, or committing it to GitHub. - SSH key permissions too open:
UNPROTECTED PRIVATE KEY FILE!. Fix withchmod 400. - Serving the dev server (
npm run dev) in production instead of thedist/build. - No
try_filesfallback: every page except/gives 404 on refresh. - Editing the Nginx config without
nginx -t: a typo stops Nginx from reloading. - Forgetting the security group rule for port 80: the site just doesn't load.
- No billing alarm.
Key takeaways
- EC2 rents virtual machines: pick an AMI (Ubuntu), an instance type, a key pair and a security group.
- Connect with
ssh -i key.pem ubuntu@<ip>; keep the key private (chmod 400). - Install a supported LTS Node.js (nvm makes it easy),
npm ci, thennpm run build→dist/. - Nginx serves the build from
/var/www/html;try_files $uri $uri/ /index.htmlmakes SPA routes work on refresh. - Test with
nginx -t, apply withsystemctl reload nginx. - Open port 80 in the security group; use an Elastic IP so the address never changes.
Interview questions
Q1. What is AWS EC2?
Elastic Compute Cloud is AWS's service for renting virtual servers (instances). You choose the OS image (AMI), the hardware size (instance type) and the network/firewall settings (VPC, security groups), and pay for the time it runs. You can resize, stop, start or replicate instances as needed.
Q2. What is a security group?
A virtual firewall attached to EC2 instances that controls inbound and outbound traffic by protocol, port and source/destination. Everything inbound is denied unless a rule allows it. Rules apply immediately. Security groups are stateful: replies to allowed traffic are automatically allowed back.
Q3. What is Nginx, and why use it with a Node.js app?
Nginx is a high-performance, event-driven web server and reverse proxy. In front of Node.js it serves static files efficiently, terminates HTTPS, forwards API requests to the Node process (reverse proxy), and can add compression, caching, rate limiting and load balancing, so Node.js only handles application logic.
Q4. Why does refreshing a React route give a 404 on Nginx, and how do you fix it?
In a SPA, routes like /profile exist only in client-side JavaScript; there's no /profile file on disk. A refresh asks the server for that path, which doesn't exist. Fix it with a fallback that serves index.html for unknown paths: try_files $uri $uri/ /index.html; in Nginx. React Router then renders the right page.
Q5. What is an Elastic IP, and why use one?
A static public IPv4 address that you allocate to your AWS account and attach to an instance. A normal public IP changes whenever the instance is stopped and started; an Elastic IP stays the same, so DNS records and allow-lists keep working. Unattached Elastic IPs are billed.
Q6. What's the difference between npm run dev and npm run build?
npm run dev starts Vite's development server: unminified code, hot reloading, error overlays. It's not meant for real traffic. npm run build produces an optimized production bundle (minified, hashed file names for caching) in dist/, which any static web server such as Nginx can serve.
What's next
The frontend is live, but it can't talk to anything. In Chapter S3 02: Nginx and Backend Node App Development you'll deploy the backend on the same server, keep it running with PM2, and connect the two through Nginx as a reverse proxy.