If you’ve built a website using React, the next step is putting it online. That means “deploying” your app so people can visit it. In this guide, I’ll walk you through how to deploy a React app on a Linux VPS (Virtual Private Server). It’s a cheap and flexible way to host your site.
I’ve done this a few times myself. The first time felt tricky, but it got easier once I understood what was going on. I’ll try to keep things simple so you don’t get stuck.
What Is a React App?
React is a JavaScript library for building websites. It’s made by Facebook and used by lots of developers to create fast and modern apps. When you build something in React, you’re usually writing small “components” that work together to make the whole site.
You don’t need to know everything about React to deploy it, though. As long as your app runs fine on your computer, we can move it to a server.
What Is a VPS?
A VPS is short for Virtual Private Server. It’s like renting your own small computer on the internet. You can use it to host websites, run apps, or store files.
I use VPS hosting for most of my projects because:
- It’s affordable
- You get full control
- It runs 24/7
If you’re using a Linux VPS with Ubuntu or CentOS, this guide will work for you. I’ll use Ubuntu as an example.
Before You Start
Here’s what you’ll need:
- A working React app (you can build one using
npm run build
) - A Linux VPS (Ubuntu 20.04 or similar)
- A domain name (optional but nice)
- A little patience
Let’s get started.
Step 1: Build Your React App
Your React app needs to be turned into static files. These are HTML, CSS, and JavaScript files that browsers can understand.
On your local computer, open a terminal in your React project folder and run:
npm run build
This creates a new folder called build
. It contains everything needed to run your app in a browser.
Step 2: Connect to Your VPS
Next, we connect to the Linux VPS. You’ll use SSH, which is a way to securely log in.
On your computer, run:
ssh username@your-server-ip
Replace username
with your VPS user (often root
) and your-server-ip
with the IP address of your server.
Now you’re in.
Step 3: Install a Web Server (Nginx)
We need something to serve your React files. I use Nginx. It’s lightweight and fast.
First, update your server’s package list:
sudo apt update
Then install Nginx:
sudo apt install nginx -y
After it’s installed, check if it’s running:
sudo systemctl status nginx
If you see “active (running),” you’re good.
Step 4: Copy Your Files to the Server
Now we need to move the build
folder from your computer to the server.
One easy way is using scp
, a secure copy tool.
From your local machine, run:
scp -r build/ username@your-server-ip:/home/username/react-app
This puts the files in /home/username/react-app
on your VPS. You can choose a different folder if you want.
Step 5: Configure Nginx to Serve Your App
Let’s tell Nginx where to find your React files.
Open the Nginx config file:
sudo nano /etc/nginx/sites-available/react
Paste this:
server {
listen 80;
server_name yourdomain.com;
root /home/username/react-app;
index index.html;
location / {
try_files $uri /index.html;
}
}
Replace yourdomain.com
with your real domain name or your server’s IP address.
Then, link this file to the sites-enabled
folder:
sudo ln -s /etc/nginx/sites-available/react /etc/nginx/sites-enabled/
Test the config:
sudo nginx -t
If you see no errors, reload Nginx:
sudo systemctl reload nginx
Now open a browser and visit your server IP or domain. You should see your React app.
Step 6: Secure Your App (Optional but Recommended)
If you have a domain name, you can add HTTPS using Let’s Encrypt. That gives your site a green lock and better security.
First, install Certbot:
sudo apt install certbot python3-certbot-nginx -y
Then run:
sudo certbot --nginx -d yourdomain.com
It will ask a few questions. After that, you’ll have HTTPS set up.
Bonus: What Happens Behind the Scenes?
When someone visits your site, here’s what happens:
- Their browser sends a request to your server
- Nginx gets the request
- Nginx finds your static React files
- It sends them back to the browser
- The browser runs the React app
It’s pretty fast because everything is static. No database or backend is needed for basic React apps.
What If You Update the App?
When you make changes and want to redeploy:
- Run
npm run build
again on your computer - Use
scp
to copy the newbuild
folder to the server - Replace the old files with the new ones
- Reload the browser
That’s it.
Three Quick Lists for You
Tools Used in This Guide
- React (for building your app)
- Nginx (web server)
- SSH and SCP (for connecting and copying files)
Common Problems I’ve Seen
- Port 80 is blocked (open it in your firewall)
- Nginx not pointing to the right folder
- You forgot to run
npm run build
Benefits of This Setup
- Fast and low cost
- Works well for static apps
- Full control over your server
My Opinion
I like hosting my React apps this way because I learn more about servers and Linux. It gives me flexibility. I’ve also used platforms like Netlify or Vercel, which are easier, but sometimes I want full control, like setting custom headers or using my own domain without limits.
Also, this setup works for Vue, Svelte, or any other static app—not just React.
Final Thoughts
Deploying a React app on a Linux VPS isn’t too hard once you break it down. You build the app, upload it, point Nginx to it, and you’re done.
If this is your first time, don’t worry if something doesn’t work right away. Try checking the logs or going step by step again.
Got stuck somewhere? Want help making your setup more advanced, like adding a Node.js backend or CI/CD? Just let me know.