Host React with Nginx
Access performance gains by serving pre-built React apps statically.
1. Build the App locally
bash
npm run build
# Creates a "dist" or "build" folderUpload this folder to `/var/www/react-app` on your server.
2. Nginx Configuration
The tricky part is handling client-side routing (e.g., /dashboard) so it doesn't 404.
nginx
server {
listen 80;
server_name my-react-app.com;
root /var/www/react-app;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}The `try_files` directive ensures that any unknown route falls back to `index.html`, allowing React Router to handle the URL.
Page changelog
Last updated
- 2024-04-10—Initial or baseline update for this page.
Related articles
Deployment
Integrations & Plugins — Connect Your Stack
Patterns for integrating monitoring, auth, storage, CI/CD, and webhooks across your services.
Deployment
Deploying Next.js App Router on Cloud VPS
A comprehensive guide to hosting Next.js applications using Node.js, PM2, and Nginx reverse proxy architecture.
Deployment
Deploying Django with Gunicorn & Nginx
Production-ready Python deployment using Gunicorn as the WSGI server and Nginx as the reverse proxy.
Deployment
Self-Hosted GitLab CE Deployment
Take control of your DevOps pipeline by hosting your own GitLab instance on a cloud VPS.
Deployment
Deploying Strapi Headless CMS
Setting up Strapi v4 with a PostgreSQL database for a robust content API.
Deployment
Self-Hosting a PaaS with Coolify
An open-source, self-hosted alternative to Heroku/Vercel for deploying your apps easily.
Was this page helpful?