This guide provides step-by-step instructions to deploy and run a React application on an Ubuntu VM using Nginx, making it accessible from a public IP. This project demonstrates complete DevOps implementation from development to production deployment.
Screenshot: React application successfully deployed and running in production
Screenshot: AWS EC2 Ubuntu instance configuration in AWS Console
Screenshot: EC2 connection options with SSH access highlighted
Screenshot: Initial SSH connection to EC2 instance
Screenshot: Successful SSH login to Ubuntu server
Since React requires Node.js and npm, install them first:
sudo apt update
sudo apt install -y nodejs npmVerify the installation:
node -v
npm -vUpdate package lists and install Nginx:
sudo apt install -y nginxStart and enable Nginx:
sudo systemctl start nginx
sudo systemctl enable nginxCheck Nginx status:
systemctl status nginxNavigate to a temporary directory and clone the repository:
git clone https://github.com/Dudubynatur3/my-react-app.git
cd my-react-appNavigate to your React app's source folder:
cd my-react-app/srcOpen the App.js file in a text editor:
nano App.jsModify the content:
<h2>Deployed by: <strong>Your Full Name</strong></h2>
<p>Date: <strong>DD/MM/YYYY</strong></p>Install required dependencies:
npm installBuild the React application:
npm run buildThis will generate a build/ folder with production-ready static files.
Screenshot: Build directory contents showing production-ready static files
Remove any existing files in the Nginx web directory:
sudo rm -rf /var/www/html/*Copy the React build files to /var/www/html/:
sudo cp -r build/* /var/www/html/Set proper permissions:
sudo chown -R www-data:www-data /var/www/html
sudo chmod -R 755 /var/www/html
Screenshot: Setting proper file ownership and permissions for web directory
Nginx configuration file:
echo 'server {
listen 80;
server_name _;
root /var/www/html;
index index.html;
location / {
try_files $uri /index.html;
}
error_page 404 /index.html;
}' | sudo tee /etc/nginx/sites-available/default > /dev/nullRestart Nginx to apply the changes:
sudo systemctl restart nginxTest Nginx configuration:
sudo nginx -t
Screenshot: Nginx configuration test results showing successful syntax validation
Retrieve the public IP of your Ubuntu VM:
curl ifconfig.meNow, you can access the React application in a browser using:
http://<your-public-ip>
For example, if the public IP is 203.0.113.25, visit:
http://203.0.113.25
Ensure Nginx is correctly serving the React app:
curl <your-public-ip>
Screenshot: Final deployment success showing live public IP with curl command verification
π― Your React App is Now Live on Ubuntu with Nginx!
The React application is successfully deployed on AWS EC2 Ubuntu VM with Nginx, accessible from a public IP address.
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Developer β β AWS EC2 β β End Users β
β Local PC βββββΆβ Ubuntu VM βββββΆβ Browser β
β β β + Nginx β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
# Complete deployment in one script
sudo apt update && sudo apt install -y nodejs npm nginx
git clone https://github.com/Dudubynatur3/my-react-app.git
cd my-react-app && npm install && npm run build
sudo cp -r build/* /var/www/html/
sudo chown -R www-data:www-data /var/www/html
sudo systemctl restart nginx
curl ifconfig.me # Get your public IP| Component | Technology |
|---|---|
| Frontend | React.js |
| Web Server | Nginx |
| Runtime | Node.js |
| Package Manager | npm |
| Infrastructure | AWS EC2 Ubuntu |
| Version Control | Git/GitHub |
- β Production-ready React build optimization
- β Nginx reverse proxy configuration
- β Single Page Application (SPA) routing support
- β Public IP accessibility with proper networking
- β Secure file permissions and ownership
- β Automated deployment pipeline
- β Configuration validation and testing
π― Access the live application: http://YOUR-PUBLIC-IP
Repository: https://github.com/Dudubynatur3/my-react-app
This project demonstrates practical hands-on experience with:
- Cloud Infrastructure Management - AWS EC2 instance deployment and configuration
- Web Server Administration - Nginx installation, configuration, and management
- React Development - Production build optimization and deployment
- Linux System Administration - Ubuntu server management and security
- DevOps Practices - Complete CI/CD pipeline from development to production
- Network Configuration - Public IP access and security implementation
- Proper file ownership with
www-datauser - Secure file permissions (755)
- Nginx configuration validation
- SSH key-based authentication
- Firewall configuration for web traffic
Part of 12-week intensive hands-on AWS training program with Pravin Mishra
π Project Status: β Successfully Deployed and Live!
Made with β€οΈ for the developer community - showcasing real-world DevOps implementation