Deploying a static Website to AWS EC2 with NGINX

Deploying a static Website to AWS EC2 with NGINX

ยท

2 min read

If you have a static HTML/CSS website and want to share it with the world, deploying it on an Ubuntu 22.04 AWS EC2 instance with NGINX is a seamless process. In this step-by-step guide, we'll walk through the deployment process to ensure your static content is live and accessible.

Prerequisites:

  1. AWS Account:

    • Ensure you have an AWS account. If not, sign up for one.
  2. EC2 Instance:

    • Launch an EC2 instance with Ubuntu 22.04. Make a note of the instance's public IP or DNS.
  3. Security Group:

    • Configure the security group to allow traffic on ports 80 (HTTP) and 22 (SSH).
  4. SSH Key Pair:

    • Create or use an existing SSH key pair to connect to the EC2 instance.

Do you need help creating your EC2 instance? Click to view step-by-step guides.

Steps:

1. Connect to your Ubuntu EC2 instance:

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

Need help on connecting to your instance on a windows device? Click to view

2. Update the system:

sudo apt update && sudo apt upgrade -y

3. Install NGINX:

sudo apt install nginx -y

4. Start NGINX:

sudo systemctl start nginx

5. Clone your GitHub repository:

#First navigate to /var/www/html
cd /var/www/html

# Then initialize git
git init

#Clone git repo
git clone https://github.com/your-username/your-repo.git

6. Configure permissions:

sudo chown -R www-data:www-data /var/www/html

7. Verify NGINX configuration:

sudo nginx -t

8. Reload NGINX:

sudo systemctl reload nginx

9. Set up a domain (optional):

If you have a domain, configure your DNS settings to point to the EC2 instance's public IP.

10. Access your website:

Open a web browser and navigate to your EC2 instance's public IP. Your simple HTML/CSS website is now live and accessible.

Additional Tips:

  • Automate Deployment:

    • Use Git Actions or other CI/CD tools for automated deployments when you push changes.
  • Customize NGINX Configuration:

    • Change NGINX configuration files in /etc/nginx/sites-available/ if you have specific requirements.
  • SSL Certificate:

    • Get an SSL certificate to enable secure connections (HTTPS).
  • Backup and Monitoring:

    • Configure regular backups and monitoring solutions to ensure the reliability of your website.

By following these steps, you've successfully deployed a simple HTML/CSS website on an Ubuntu 22.04 AWS EC2 instance using NGINX.

ย