# Days with DevOps | Project 01

**Nginx** **(pronounced "engine-x")**  is a open source web server software that is widely used to serve web content, reverse proxy, and load balance. Also it is widely used in production environments and is a popular choice among web developers and administrators. So the main goal of this blog post is to set up and configure an Nginx Web Server on an AWS EC2 instance to host a website.

### **Requirements :**

Before get into the project, ensure you have access to the following:

* An AWS account with permissions to create and manage EC2 instances (free tier would be better).
    
* Basic knowledge of Linux commands and SSH protocol.
    
* Familiarity with AWS services like EC2, Security Groups, and IAM roles.
    

***Step 1 : Launch an AWS Instance***

First logging in to your created AWS Management Console.Select EC2 Dashboard by searching "**EC2**" from the service menu.The EC2 dashboard will provide about EC2 instance, security groups, SSH key pairs and other resources.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724126891074/e08704f6-ace3-426b-a627-217726a6b1f2.jpeg align="center")

Click on “**Launch Instance**” to begin creating a new EC2 instance. This process involves selecting the appropriate configurations for your server.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724126946661/077b05b4-0c17-4b10-8a0a-8e9e09e84af7.jpeg align="center")

**Amazon Machine Image (AMI):** Choose Linux based image as your base image.I recommend selecting "Amazon Linux 2". This operating system is specifically optimized for running on AWS and provides a stable, secure, and high-performance execution environment

**Instance Type:** Select an appropriate instance type based on your needs. For this tutorial, the “**t2.micro**” instance type is sufficient.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724126994936/26ed968a-42e8-4d27-ac7a-62e003e30554.jpeg align="center")

**Key Pair:** Choose create a new one or an existing key pair. This key pair will be used for SSH access to your instance. Ensure you download the **key pair file (.pem)** and keep it secure.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724127128016/d54da5d8-a782-4123-a9ed-809c99be96b7.jpeg align="center")

**Security Group:** Configure the security group to allow **SSH (port 22)** and **HTTP (port 80)** traffic. This ensures that you can connect to the instance and that the web server is accessible from the internet.

Finally review the configurations and click “**Launch Instance**” Your EC2 instance will be created and available in a few moments.

***Step 2 : Connect to Instance using SSH***

Once the instance is running, SSH into it using your terminal or SSH client. First use the following command on terminal to enable permission to private key file.

`chmod 400 "<keyname.pem>"`

Then use following command, replacing **&lt;key-pair-file&gt;** with the path to your key pair file, **&lt;username&gt;** with your instance username and **&lt;instance-public-IP&gt;** with your instance's public IP address or public DNS:

`ssh -i "<key-pair-file>" <username>@<instance-public-IP or DNS>`

In my instance I used public IP,

`ssh -i "test_key.pem" ec2-user@<xxx.xxx.xxx.xxx>`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724127248272/f932a60b-570c-4d1d-944e-adffbf7880d8.jpeg align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724127278219/3830d705-47e6-4f2c-823f-5cca6d5a624e.png align="center")

***Step 3 : Update All Packages***

After logging in, it’s important to update all installed packages to ensure your instance is running the latest software versions. Run the following commands:

`sudo yum update && sudo yum upgrade`

This command updates the package index and ensures that you have access to the latest versions of the software available in the repository.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724127383893/458676b8-bbeb-47e4-97b9-c97e8cd73f78.png align="center")

***Step 4 : Install and Enable Nginx Web Server***

Next to install Nginx on instance, run the following command:

`sudo yum install nginx`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724127419952/92d0f556-0f48-46cd-9c12-d426a396a025.png align="center")

you can check weather the Nginx web server installed with command:

`sudo yum list install nginx`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724127490376/66998d8c-bc1f-469b-baaa-ab389bf0c97c.png align="center")

After installation, enable and start the Nginx web server with command:

`sudo systemctl enable nginx`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724127780847/06cd1827-abc7-4652-bdb7-89a9b3e444c2.jpeg align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724127805582/31b0ddbd-f170-4f6c-b960-557c6afd9373.png align="center")

***Step 5 : Verify the Nginx Web Server works using Public IP***

To verify that your Nginx web server is running, open your web browser and enter your instance’s public IP address. If Nginx is installed and running correctly, you should see the default Nginx welcome page.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724127921657/0dc82749-f241-473d-af7f-0e60c178e746.png align="center")

So you have successfully installed Nginx on your EC2 instance. I will now show you how to create a sample HTML file for your website using nano.  
So you need to navigate to the document root directory of default Nginx page. 

Once you run the following command:

`sudo nano /usr/share/nginx/html/index.html`

It will open the nano text editor as following

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724127983945/0443c46e-1146-4d89-a87c-4fb419111a9b.png align="center")

Add your custom HTML content, save the file and exit the editor. Refresh your browser to view your custom webpage!

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1724127961688/991f3766-26b9-4e13-81d9-8e7664fdcaab.png align="center")

So this is it ! Hoping the above steps great guide to deploying Nginx and sample files on AWS instance. Also, I think this guide will help to deploy other web servers like **Apache** Web server.

Thank you for reading my blog post! Your positive feedback inspires me to explore more about technology and innovation.

Make sure to follow me on [LinkedIn](http://linkedin.com/in/pamindakw) and [pamindatechtalk](https://sites.google.com/view/pamindak-blog/) blog where I will be posting similar content in the future! 🙋‍♂️
