Setting up a basic Nginx webpage on AWS EC2 Instance

This guide walks through the process of deploying a simple web page using Nginx on an AWS EC2 instance, including proper setup, and best practices. It is your starter kit for future seamless deployments.

Prerequisites

AWS account with appr…


This content originally appeared on DEV Community and was authored by Ayomide

This guide walks through the process of deploying a simple web page using Nginx on an AWS EC2 instance, including proper setup, and best practices. It is your starter kit for future seamless deployments.

Prerequisites

  • AWS account with appropriate permissions
  • Basic understanding of Linux commands
  • Web browser access to AWS Management Console

Step 1: Creating an EC2 Instance

  1. Navigate to AWS Console
    • Go to aws.amazon.com and sign in
    • Search for "EC2" in the top search bar
    • Select "EC2" from the services list

AWS homepage

  1. Launch Instance Configuration

    • Click "Launch Instance" button
    • Enter a meaningful name for your instance
    • Select Ubuntu Server as the Amazon Machine Image (AMI)
      • Alternative: Amazon Linux 2 (uses yum instead of apt)
    • Choose instance type (t2.micro is eligible for free tier)
    • Create or select a key pair for SSH access
  2. Network Security Configuration

    • Create a new security group or select existing
    • Add inbound rules:
      • HTTP (Port 80)
      • HTTPS (Port 443)
      • SSH (Port 22)
    • Configure security group name and description

Creating EC2 instance

Step 2: User Data Configuration

Add the following script in the user data section during instance creation. This script will automatically install and configure Nginx when the instance launches.

#!/bin/bash

# Update package lists
apt update
apt upgrade -y

# Install nginx
apt install -y nginx

# Display nginx version
nginx -v

# Start and enable nginx service
systemctl start nginx
systemctl enable nginx

# Set permissions for web root directory
chmod 2775 /var/www/html
find /var/www/html -type d -exec chmod 2775 {} \;
find /var/www/html -type f -exec chmod 0664 {} \;

# Create custom index page
echo "<h3> Welcome to DevOps Stage 0 - Ayomide/Mischief </h3>" > /var/www/html/index.html

Step 3: Launch and Verify

  1. Launch the instance

    • Review all configurations
    • Click "Launch Instance"
  2. Verify Deployment

    • Wait 2-3 minutes for instance to initialize
    • Copy the public IP address from instance details
    • Open a web browser and navigate to: http://54.236.249.255
    • You should see your custom welcome page

Running webpage

Step 4: Maintenance and Clean Up

  1. Regular Maintenance

    • Regularly update system packages: sudo apt update && sudo apt upgrade
    • Monitor system logs: sudo tail -f /var/log/nginx/access.log
    • Check Nginx status: sudo systemctl status nginx
  2. Clean Up

    • Stop instance when not in use: AWS Console → EC2 → Select Instance → Instance State → Stop
    • To permanently remove: AWS Console → EC2 → Select Instance → Instance State → Terminate
    • Remember to delete associated resources (EBS volumes, Elastic IPs) to avoid charges

Troubleshooting

If the web page doesn't load:

  1. Verify instance status is "running"
  2. Check security group settings
  3. Verify Nginx is running: sudo systemctl status nginx
  4. Check Nginx error logs: sudo cat /var/log/nginx/error.log

Remember: Always terminate resources you're not actively using to avoid unnecessary AWS charges.

To be connected to top talents who make the entire deployment process feel like a breeze, visit HNG Tech.


This content originally appeared on DEV Community and was authored by Ayomide


Print Share Comment Cite Upload Translate Updates
APA

Ayomide | Sciencx (2025-01-30T01:28:51+00:00) Setting up a basic Nginx webpage on AWS EC2 Instance. Retrieved from https://www.scien.cx/2025/01/30/setting-up-a-basic-nginx-webpage-on-aws-ec2-instance/

MLA
" » Setting up a basic Nginx webpage on AWS EC2 Instance." Ayomide | Sciencx - Thursday January 30, 2025, https://www.scien.cx/2025/01/30/setting-up-a-basic-nginx-webpage-on-aws-ec2-instance/
HARVARD
Ayomide | Sciencx Thursday January 30, 2025 » Setting up a basic Nginx webpage on AWS EC2 Instance., viewed ,<https://www.scien.cx/2025/01/30/setting-up-a-basic-nginx-webpage-on-aws-ec2-instance/>
VANCOUVER
Ayomide | Sciencx - » Setting up a basic Nginx webpage on AWS EC2 Instance. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/01/30/setting-up-a-basic-nginx-webpage-on-aws-ec2-instance/
CHICAGO
" » Setting up a basic Nginx webpage on AWS EC2 Instance." Ayomide | Sciencx - Accessed . https://www.scien.cx/2025/01/30/setting-up-a-basic-nginx-webpage-on-aws-ec2-instance/
IEEE
" » Setting up a basic Nginx webpage on AWS EC2 Instance." Ayomide | Sciencx [Online]. Available: https://www.scien.cx/2025/01/30/setting-up-a-basic-nginx-webpage-on-aws-ec2-instance/. [Accessed: ]
rf:citation
» Setting up a basic Nginx webpage on AWS EC2 Instance | Ayomide | Sciencx | https://www.scien.cx/2025/01/30/setting-up-a-basic-nginx-webpage-on-aws-ec2-instance/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.