Skip to main content

Command Palette

Search for a command to run...

Day8-devops-challange

Published
โ€ข3 min readโ€ขView as Markdown

Deploy Your First Web Server with Nginx

๐ŸŒ What is Nginx?

Nginx is a high-performance open-source web server used to:

  • Serve static websites

  • Act as a reverse proxy

  • Load balance traffic

  • Handle high-traffic applications

It is fast, lightweight, and widely used in production environments.

Many big companies use Nginx in their infrastructure.

๐Ÿ–ฅ๏ธ What You Need Before Starting

  • A Linux server (Ubuntu recommended)

  • Basic terminal knowledge

  • SSH access to your server

  • Internet connection

You can use:

  • AWS EC2

  • Azure VM

  • Google Cloud VM

  • Or even VirtualBox locally

  • ๐Ÿงฑ Step 1: Launch a Server (Ubuntu Example)

    If using cloud (AWS EC2):

    1. Launch Ubuntu instance

    2. Allow inbound rule:

      • Port 22 (SSH)

      • Port 80 (HTTP)

      • ๐Ÿ“ฆ Step 2: Update the Server

        Always update packages first:

          sudo apt update
          sudo apt upgrade -y
        

        ๐Ÿ“ฅ Step 3: Install Nginx

          sudo apt install nginx -Y
        

        Check if it is running:

          sudo systemctl status nginx
        

        If running, youโ€™ll see:
        Active: active (running) โœ…

      • ๐ŸŒ Step 4: Allow Firewall (If Enabled)

          sudo ufw allow 'Nginx Full'
        

        Check status:

          sudo ufw status
        

        ๐ŸŽ‰ Step 5: Access Your Web Server

        Open your browser:

          http://your-server-ip
        

        You should see the default Welcome to Nginx! page.

        ๐ŸŽŠ Congratulations! Your web server is live.

๐Ÿ“‚ Step 6: Deploy Your Own Website

Default Nginx website folder:

    /var/www/html

Move into the directory:

    cd /var/www/html

Remove default file:

    sudo rm index.nginx-debian.html

Create your own website:

    sudo nano index.html

Paste this:

    <!DOCTYPE html>
    <html>
    <head>
        <title>My First Web Server</title>
    </head>
    <body>
        <h1>Hello DevOps World ๐Ÿš€</h1>
        <p>This website is deployed using Nginx!</p>
    </body>
    </html>

Save and exit.

Now refresh browser ๐ŸŽ‰


๐Ÿง  How Nginx Works (Simple Flow)

    User Browser
          โ†“
    Internet
          โ†“
    Server (Port 80)
          โ†“
    Nginx
          โ†“
    Website Files (/var/www/html)
          โ†“
    Response to User

โš™๏ธ Important Nginx Commands

Start Nginx:

    sudo systemctl start nginx

Stop Nginx:

    sudo systemctl stop nginx

Restart Nginx:

    sudo systemctl restart nginx

Reload Configuration:

    sudo systemctl reload nginx

๐Ÿ—๏ธ Nginx Folder Structure

Main config file:

    /etc/nginx/nginx.conf

Site config folder:

    /etc/nginx/sites-available
    /etc/nginx/sites-enabled

Website root:

    /var/www/html

๐Ÿ“ˆ Why Nginx is Popular? High performance

  • Handles thousands of connections

  • Low memory usage

  • Great for reverse proxy

  • Easy configuration

  • Perfect for microservices & DevOps

๐Ÿ“Š Real-World Use

Nginx is used by:

  • Netflix

  • WordPress

  • Airbnb

It is a core component in many DevOps pipelines.