🌐 Setting Up an NGINX Server on AWS EC2: A Step-by-Step Guide

🌐 Setting Up an NGINX Server on AWS EC2: A Step-by-Step Guide

πŸš€ From Instance Creation to NGINX Installation: Everything You Need to Know

Β·

4 min read

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:

  1. Log in to the AWS Console: Navigate to your AWS console.

  2. Open EC2 Dashboard: Go to the EC2 section by typing "EC2" in the search bar and selecting the EC2 dashboard from the results.

  3. 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):

  1. Open the VPC Dashboard: In your AWS console, search for "VPC" and open the VPC dashboard.

  2. 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.

  3. 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

  1. 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

  1. Choose an AMI: When creating the instance, select an Amazon Machine Image (AMI). For this tutorial, I’m choosing the Ubuntu AMI (64-bit).

  2. Instance Type: Choose the instance type. For the free tier, select "t2.micro".

  3. 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.

  4. Add Storage and Tags: Proceed to the "Add Storage" and "Add Tags" steps. For a simple setup, you can leave these at their defaults.

  5. Configure Security Group:

    • Allow HTTP and HTTPS traffic to ensure your web server is accessible.
  6. Review and Launch: Review all the settings and click "Launch".

πŸ” Key Pair for SSH Access

  1. 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).
  2. Select Key Pair: Choose the key pair you created when launching your instance.

πŸŒ‰ Connecting to Your Instance

  1. Instance Status: Once the instance is running, select it from the instances list and click "Connect".

  2. 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:

  1. Update Packages:

     sudo apt-get update
    

    This command updates the list of available packages and their versions.

  2. 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

  1. 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.

  2. Open Browser: Open your web browser and enter the public IP address.

  3. 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! πŸŽ‰

Β