Nginx Setup

Hello everyone, in this article I’m going to share how you can setup your Nginx web server using aws ec2-Instance.

Pre-requisites:
AWS Account

Note: Please use N. Virginia (us-east-1) the charges will be less in this location and delete your instance as soon as you complete the practice, so that you can avoid the extra billing from aws.

Launching an AWS Instance:

  • First Login to your AWS Account.

  • Then navigate to Services you can see icon which is similar to icon shown below click on icon.

  • Select Compute → EC2 in that list.

  • Now you will be redirected to EC2 Page.

  • In Left Navigation Bar, Select Network & Security → Security Groups. If the Navigation bar is hidden click on the hamburger icon, the icon would be similar to icon below.

  • Now Click on Create security group you can find it on top right corner.

  • Now fill in the details:

    • Basic Details

      • Security group name → Name of your choice

      • Description → Enter some description to your security group

      • VPC → Leave it to default popped up VPC

    • Inbound Rules

      • Click on Add Rule

      • Type → All traffic

      • Source → Anywhere IPV4

    • Outbound Rules

      • Follow same steps as inbound rules.
  • In Left Navigation Bar, Select Instances→ Instances. If the Navigation bar is hidden click on the hamburger icon, the icon would be similar to icon below.

  • Now Click on the Launch Instance you can find this button on the top right corner.

Next fill the details:

  • Name → Enter Name of your choice.

  • Application and OS Images → Amazon Machine Image (AMI) → Amazon Linux 2023 AMI.

  • Instance type → Instance type → t3.micro.

  • Key pair (login) → Key pair name - required → Proceed without a key pair (Not recommended).

  • Network Settings → Firewall → Select existing security groups → Common security groups → Select the security group you have created.

  • Storage → keep the default values.

Now click on the Launch Instance from the Summary in Right Side.

Connecting to Instance

  • Now go back to your EC2 Page.

  • In Left Navigation Bar, Select Instances→ Instances. If the Navigation bar is hidden click on the hamburger icon, the icon would be similar to icon below.

  • Select the instance which you have created and click on connect.

  • you will see a new page Connect to instance

  • select on EC2 Instance Connect

  • Click on connect

  • you will be redirected to Linux Interface.

Installing Nginx in Linux Server

  • Now switch to root user using command

  •   sudo -i
    
  • Next use the dnf to install nginx

  •   dnf install nginx -y
    
  • Once installation is completed, enable the service, start the service and check the status of the service

  •   systemctl enable nginx
      systemctl start nginx
      systemctl status nginx
    
  • Now you can see the status of the service, the status should be active (running).

  • Next check the port number of nginx using

  •   netstat -lntp
    
  • you should see a line similar to the below line:

  • tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 27081/nginx: master.

  • Now open new tab in your browser and enter the public ip of your instance.

  • you will be able to see nginx start page.

  • That’s it we have successfully installed nginx web server in our EC2 Instance.

1
Subscribe to my newsletter

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

Written by

Jayachandra Rapolu
Jayachandra Rapolu