top of page
Search
  • Writer's picturejatin sharma

Step-by-Step Guide: How to Deploy Your Application on AWS Server Using Ubuntu

Introduction

If you're looking to deploy your application on the cloud, Amazon Web Services (AWS) offers a robust infrastructure to host and manage your projects. In this step-by-step guide, we'll walk through the process of creating an AWS account, setting up an Elastic IP, launching an EC2 instance, and deploying a Node.js application using Docker and Nginx on an Ubuntu system.


Step 1: Create AWS Account

  1. Visit the AWS website and click on "Create an AWS Account."

  2. Follow the on-screen instructions, providing necessary information and payment details.

  3. Verify your email address and complete the account creation process.

Step 2: Create an Elastic IP

  1. Log in to the AWS Management Console.

  2. Navigate to the EC2 Dashboard and click on "Elastic IPs" under "Network & Security."

  3. Click "Allocate Elastic IP address" and follow the prompts.

Step 3: Launch EC2 Instance

  1. In the EC2 Dashboard, click "Launch Instance."

  2. Choose an Amazon Machine Image (AMI), like "Ubuntu Server."

  3. Select an instance type based on your application's requirements.

  4. Configure instance details, storage, and security groups.

  5. Review and launch the instance, selecting or creating a key pair for SSH access.

Step 4: Connect to the EC2 Instance

  1. Open a terminal on your local Ubuntu machine.

  2. Use SSH to connect to the EC2 instance using the provided key pair and Elastic IP.

ssh -i <your-key-pair.pem> ubuntu@<your-elastic-ip>
You should now be connected to your EC2 instance.

Step 5: Install Git, Node.js, Docker, and Nginx

  1. Update the package repository.

sudo apt update && sudo apt upgrade -y

2. Install Git.

sudo apt install git -y

3. Install Node.js.

sudo apt install nodejs -y

4. Install Docker.

sudo apt install docker.io -y sudo usermod -aG docker ubuntu

5. Install Nginx.

sudo apt install nginx -y sudo systemctl start nginx

6. Ensure Docker and Nginx start on boot.

sudo systemctl enable docker sudo systemctl enable nginx

Step 6: Clone and Run the Application to Deploy

  1. Navigate to the directory for your application.

cd /path/to/your/app

2. Clone the Git repository.

git clone <your-git-repo-url>

3. Run the Node.js application using Docker. (Make sure you have docker compose file ready in your github repo which pulls the latest image from docker repository)

docker-compose up 

4. Update Nginx configuration to forward requests to the Node.js application.

sudo nano /etc/nginx/sites-available/default

Add a new location block:

location / { proxy_pass http://localhost:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection 'upgrade'; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; }

5. Restart Nginx for changes to take effect.

sudo systemctl restart nginx
Your application should now be accessible at your Elastic IP or domain.

Conclusion

Congratulations! You've successfully deployed your application on an AWS EC2 instance using Ubuntu, Docker, and Nginx. This scalable and secure setup allows you to host and manage your applications with ease. Feel free to customize the steps according to your specific requirements, and happy coding!

104 views0 comments

Commentaires


bottom of page