- Log into the AWS Management Console
- Navigate to EC2 Dashboard
- Click "Launch Instance"
- Configure your instance:
- Name: Give your instance a descriptive name (e.g., "React-App-Server")
- AMI: Select "Ubuntu Server 22.04 LTS" (free tier eligible)
- Instance Type: Choose "t2.micro" (free tier eligible)
- Key Pair: Select existing one
- Click the dropdown and select "vockey"
- Network Settings:
- Allow SSH traffic
- Allow HTTP traffic
- Allow HTTPS traffic
- Storage: 8 GB gp3 is good
- Click "Launch Instance"
- Wait for instance state to show "Running"
- Click the checkbox next to your EC2 name
- Click the "Actions" dropdown then press "Connect"
- Press Connect on the "EC2 Instance Connect" tab
Once connected to your EC2 instance, run the following commands:
sudo apt update
sudo apt upgrade -ysudo apt-get install -y nodejs
sudo apt-get install -y npm
# Verify installation
node --version
npm --versionsudo apt install git -ysudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginxcd ~
git clone https://github.com/byui-cloudsociety/reactdeploy.git
cd reactdeploynpm installnpm run buildsudo cp -r /home/ubuntu/reactdeploy/build /var/www/react-app
sudo chown -R www-data:www-data /var/www/react-appsudo nano /etc/nginx/sites-available/react-appAdd the following configuration:
server {
listen 80;
server_name your-instance-public-ip;
root /var/www/react-app;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
expires 1y;
add_header Cache-Control "public, immutable";
}
}sudo ln -s /etc/nginx/sites-available/react-app /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/defaultsudo nginx -t
sudo systemctl reload nginx