Deploying a Website on AWS EC2 instance using NGINX

Deploying a Website on AWS EC2 instance using NGINX

ยท

2 min read

Step 1: Launch an EC2 Instance :

Firstly Login to your AWS account and follow the steps :

  1. Go for Ec2 and click on launch instance.

  2. Give name for an instance and select Ubuntu as os.

  3. Select t2.micro instance type.

  4. Create a key pair.

  5. Create a Security Group and make sure these ports are allowed the traffic from anywhere:

    Port no. 80 for Http, Port no. 443 for Https and port 22 for SSH.

  6. Now Launch the instance with above configuration.

Note: We already covered how to launch EC2 instance in my Amazon Elastic Compute Cloud blog.

Step 2: Install Nginx on Ec2 instance

When instance is started running ,connect the ec2 instance through ssh using Windows PowerShell as shown in following images:

Now to install the nginx use following commands:

sudo apt update

sudo apt install nginx -y

check the status of nginx service by using systemctl status nginx command and you will get the output like this:

Also you can check by using Pubilc IP address of Ec2 instance with port number 80 on web browser and you will get the default page of nginx as shown below:

Note: If Nginx is not running with port 80, go to Edit inbound rules click "Add rule" add manually port 80.

Step 3: Deploy your website on nginx :

Nginx have its default index.html page in /var/www/html path , Replace your source code of your website by using command mv source path /* /var/www/html

Do all the process with following steps:

1.Create a directory for your source code of your project by using following command:

mkdir <Directory Name>

place your source code in this directory . Here my directory name is Project and You can check the default page of nginx by using cd /var/www/html command

Now Move your files into this path by using following command :

Step 4: Finally Launch The Website:

Now you can check by instance Public IP address:80 on web browser .Your website will be displayed:

Congratulations! ๐ŸŽ‰ You have successfully deploying a Website on AWS EC2 instance using NGINX.

Thankyou for the reading!๐Ÿ˜Š Keep Supporting ,learning and growing with each other .

ย