How to Deploy a Vite "Hello World" App on AWS EC2 Step-by-Step

Chris TiquisChris Tiquis
2 min read

Vite is a modern front-end build tool that offers lightning-fast performance for development and production. In this blog, you'll learn how to deploy a basic Vite app to an Amazon EC2 instance using Nginx.


Prerequisites

  • AWS Account

  • EC2 instance (Ubuntu preferred)

  • Domain (optional but useful)

  • SSH key for EC2

  • Basic knowledge of terminal, Vite, and EC2


Step 1: Create a Vite Project Locally

npm create vite@latest hello-vite -- --template vanilla
cd hello-vite
npm install
npm run build

This will generate a dist/ folder with the production build.


Step 2: Launch and Set Up an EC2 Instance

  1. Launch an EC2 Instance:

    • Use Ubuntu 22.04 or 20.04.

    • Assign a public IP and open ports 22 (SSH) and 80 (HTTP).

  2. SSH into the EC2 Instance:

ssh -i /path/to/key.pem ubuntu@your-ec2-public-ip

Step 3: Install Nginx on the EC2 Instance

sudo apt update
sudo apt install nginx -y

Start and enable Nginx:

sudo systemctl start nginx
sudo systemctl enable nginx

Step 4: Upload the Vite Build to EC2

From your local machine, use scp to copy the dist folder:

scp -i /path/to/key.pem -r dist ubuntu@your-ec2-public-ip:/home/ubuntu/

Step 5: Configure Nginx to Serve the App

  1. SSH into EC2 again (if not already).

  2. Move the build to the Nginx web root:

sudo cp -r /home/ubuntu/dist/* /var/www/html/
  1. (Optional) Update the Nginx default config if needed:
sudo nano /etc/nginx/sites-available/default

Make sure the root is set to /var/www/html and index.html is included.

  1. Restart Nginx:
sudo systemctl restart nginx

🌐 Step 6: Access the App

Open a browser and go to:

http://your-ec2-public-ip

You should see your Vite Hello World page!


Bonus: Add a Domain and HTTPS (Optional)

Use services like Route 53 and Let’s Encrypt to attach a domain and install SSL.


Final Notes

  • This guide focuses on static deployment. For SSR, consider using Node.js with PM2 and reverse proxying.

  • Always configure firewall and security rules carefully.

0
Subscribe to my newsletter

Read articles from Chris Tiquis directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Chris Tiquis
Chris Tiquis