π Setting Up an NGINX Server on AWS EC2: A Step-by-Step Guide
π From Instance Creation to NGINX Installation: Everything You Need to Know
Hello, friends, my name is Bilal Khan. Today I will be talking about how you can configure your NGINX server on an AWS EC2 instance. This is a simple project where I will walk you through the process step-by-step. First, we will create an EC2 instance and connect to it via the terminal. Then, I will demonstrate how to install the NGINX server and show you how to access it in your browser.
Here is the video explanation:
π§ Creating an EC2 Instance
First of all, I will create an EC2 instance. Here's how you can do it:
Log in to the AWS Console: Navigate to your AWS console.
Open EC2 Dashboard: Go to the EC2 section by typing "EC2" in the search bar and selecting the EC2 dashboard from the results.
Launch Instance: Click on the "Launch Instance" button.
π Setting Up VPC
To ensure your EC2 instance can connect properly, you need to configure a VPC (Virtual Private Cloud):
Open the VPC Dashboard: In your AWS console, search for "VPC" and open the VPC dashboard.
Create a VPC: Click on the "Create VPC" button. AWS will ask if you want to automatically create additional subnets, routing tables, and gateways. Choose to create these by default for simplicity.
Configure VPC Settings: Fill in the required details such as VPC name, IPv4 CIDR block, and tenancy (choose default tenancy). Leave the rest of the options at their defaults and create the VPC.
π Configuring Subnets
Public Subnet Configuration: Ensure your subnets are configured to auto-assign public IP addresses.
Go to the "Subnets" section in the VPC dashboard.
Select the public subnet and click "Actions" > "Edit Subnet Settings".
Enable the "Auto-assign public IPv4 address" option and save the changes.
Repeat the steps for all public subnets you want to use.
π Launching the EC2 Instance
Choose an AMI: When creating the instance, select an Amazon Machine Image (AMI). For this tutorial, Iβm choosing the Ubuntu AMI (64-bit).
Instance Type: Choose the instance type. For the free tier, select "t2.micro".
Configure Instance Details:
Ensure you choose the public subnet you configured earlier.
Enable "Auto-assign Public IP" if itβs not already set.
Leave the rest of the settings at their defaults.
Add Storage and Tags: Proceed to the "Add Storage" and "Add Tags" steps. For a simple setup, you can leave these at their defaults.
Configure Security Group:
- Allow HTTP and HTTPS traffic to ensure your web server is accessible.
Review and Launch: Review all the settings and click "Launch".
π Key Pair for SSH Access
Create a Key Pair: If you donβt have an existing key pair, create a new one.
- Give it a name and download the key pair file (.pem).
Select Key Pair: Choose the key pair you created when launching your instance.
π Connecting to Your Instance
Instance Status: Once the instance is running, select it from the instances list and click "Connect".
Connect Using SSH: You have multiple options to connect. You can use the EC2 Instance Connect feature directly in the browser for simplicity.
- Choose "EC2 Instance Connect" and click "Connect".
π₯ Installing NGINX
Once connected to your EC2 instance terminal, follow these steps to install NGINX:
Update Packages:
sudo apt-get update
This command updates the list of available packages and their versions.
Install NGINX:
sudo apt-get install nginx -y
This command installs the NGINX web server. The
-y
flag automatically answers "yes" to any prompts during installation.
π Accessing NGINX in Browser
Public IP Address: Note the public IP address of your EC2 instance. You can find this on the instance details page in the AWS console.
Open Browser: Open your web browser and enter the public IP address.
NGINX Welcome Page: If everything is set up correctly, you should see the default NGINX welcome page, confirming that NGINX is running.
By following these steps, you can successfully set up an NGINX server on an AWS EC2 instance. You can now use this server to host your applications and make them accessible via the web.
Got Questions?
If you have any questions or would like to share your own experiences, feel free to leave a comment below. I'm here to support and engage with you.
That's it for now. π
You can Buy Me a Coffee if you want to and don't forget to follow me on YouTube, Twitter, and LinkedIn.
Happy Journey! π