Thursday, January 16, 2025
No menu items!
More
    HomeComputingHow to install NGINX on AWS EC2 Linux?

    How to install NGINX on AWS EC2 Linux?

    Introduction:

    NGINX is a powerful web server that handles high-traffic websites. It’s perfect for hosting websites and applications. AWS EC2 provides scalable computing capacity, making it an ideal platform for NGINX. This guide will help you install NGINX quickly and easily.

    Prerequisites:

    Before starting, make sure you have:

    • An AWS Account
    • A running AWS EC2 Linux instance
    • SSH access to your server
    • Basic Linux commands knowledge
    • Root or sudo access

    Step-by-Step Installation:

    1. Launch an EC2 Instance and connect via SSH

    Choose an Amazon Machine Image (AMI): Select Amazon Linux 2 AMI.

    Select Instance Type: Choose t2.micro for free tier eligibility. Depending on your requirements you can select bigger sizes or type of machines, for the sake of illustration and giving example we are selecting t2.micro instance type which as 1vCPU and 1Gig Memory.

    Configure Instance Details: Default settings are fine.

    Create a key pair, give a name of the SHS key pair and download the Public Key into your side.

    Select networking where EC2 instance is reachable from Internet, in my case, all of the subnets in VPC has a routing table and routing entry towards Internet Gateway (IGW), and EC2 instance will get public IP.

    Add Storage: 8 GB is sufficient. Depending on your use case you may need more storage or different type of storage.

    Tag Instance: Optional, but helpful for organization.

    Configure Security Group: Allow SSH, HTTP, and HTTPS. In the networking settings make sure that you can able to access the machine from your IP address via SSH,HTTP and HTTPS.

    Review and Launch: Launch your instance and download the key pair.

    Now select your instance and click on Details Tab, you will see more information about the EC2 instance. Since we have enabled auto Public IP settings in Networking, EC2 instance will get public IP.

    Bash
    ssh -i "your-key.pem" ec2-user@your-ec2-public-dns-name

    For example i have connected like this, but before connecting, assign correct permissions to SSH Public Key otherwise the remote Linux machine will reject SSH connection request.

    Bash
    chmod 400 nginx-server-sshkey.pem
    1. Update Your System:

    Once you login into AWS EC2 Linux machine, you can start with the following commands for updating and installing NGINX packages.

    Bash
    sudo yum update -y
    1. Install NGINX:
    Bash
    sudo yum install nginx -y
    1. Start NGINX:
    Bash
    sudo systemctl start nginx
    sudo systemctl enable nginx

    Basic Configuration:

    1. Check NGINX Status:
    Bash
    sudo systemctl status nginx

    Security Setup:

    1. Configure AWS Security Group:
    • Open port 80 (HTTP)
    • Open port 443 (HTTPS)
    • Restrict SSH access to your IP (you can get your local IP from this website https://whatismyipaddress.com/)
    1. Basic NGINX Security:
    • Update default configuration
    • Set proper file permissions
    • Enable HTTPS

    Common Issues:

    1. NGINX Won’t Start:
    • Check error logs: sudo cat /var/log/nginx/error.log
    • Verify ports aren’t in use: sudo netstat -tulpn
    1. Cannot Access Website:
    • Check security group settings
    • Verify NGINX is running
    • Confirm instance public IP

    Testing:

    1. Open your browser
    2. Enter your EC2 public IP
    3. You should see the NGINX welcome page

    Conclusion:

    You’ve successfully installed NGINX on your AWS EC2 Linux instance.

    Keep your system updated for security and performance.

    Burak Cansizoglu
    Burak Cansizogluhttps://cloudinnovationhub.io/
    Burak is a seasoned freelance Cloud Architect and DevOps consultant with over 16 years of experience in the IT industry. He holds a Bachelor's degree in Computer Engineering and a Master's in Engineering Management. Throughout his career, Burak has played diverse roles, specializing in cloud-native solutions, infrastructure, cloud data platforms, cloud networking and cloud security across the finance, telecommunications, and government sectors.His expertise spans leading cloud platforms and technologies, including AWS, Azure, Google Cloud, Kubernetes, OpenShift, Docker, and VMware. Burak is also certified in multiple cloud solutions and is passionate about cloud migration, containerization, and DevOps methodologies. Committed to continuous learning, he actively shares his knowledge and insights with the tech community.

    LEAVE A REPLY

    Please enter your comment!
    Please enter your name here

    Advertisingspot_img

    Popular posts

    My favorites

    I'm social

    0FansLike
    0FollowersFollow
    0FollowersFollow
    0SubscribersSubscribe
    Index