8 min read

Nginx for Beginners: A Complete Guide to Installation and Static Content Hosting

Nasrul Hasan
Nasrul Hasan
Nasrul Hasan
Cover Image for Nginx for Beginners: A Complete Guide to Installation and Static Content Hosting

Nginx for Beginners: A Complete Guide

In today’s world, where most applications run in containers and microservices architectures, Nginx is an essential tool for every developer and DevOps engineer. It is widely used for serving web content, load balancing, and acting as a reverse proxy.

This beginner-friendly guide will help you understand Nginx fundamentals and get started quickly.


What Is Nginx?

Nginx (pronounced “engine-x”) is a high-performance, open-source web server. In addition to serving web pages, it can also function as:

  • Reverse proxy

  • Load balancer

  • HTTP cache

  • API gateway

Created by Igor Sysoev, Nginx is known for its speed, low memory usage, and high concurrency, making it ideal for modern applications.


Topics Covered in This Blog

  • Installing Nginx and basic commands

  • Important Nginx configuration files

  • Serving static content using Nginx


Nginx Installation and Basic Commands

Install Nginx on Debian-Based Systems (Ubuntu)

sudo apt update
sudo apt install nginx
cmake

Install Nginx on RHEL-Based Systems (Amazon Linux, CentOS, RHEL)

sudo yum update -y
sudo yum install nginx -y
cmake

Check Nginx Service Status

sudo systemctl status nginx
ebnf

If Nginx is not running, start and enable it:

sudo systemctl start nginx
sudo systemctl enable nginx
nsis

Restart or Reload Nginx

sudo systemctl restart nginx
sudo systemctl reload nginx
nsis

🔹 Restart stops and starts the service 🔹 Reload applies configuration changes without downtime

Important Nginx Configuration Files

All Nginx configuration files are located in:

/etc/nginx
awk

Key files and directories include:

  • nginx.conf → Main configuration file

  • conf.d/ → Custom configuration files

  • sites-enabled/ → Enabled site configurations

  • /var/log/nginx/ → Access and error logs

nginx.conf

The main
nginx.conf
stata
file defines:
  • Access and error log locations

  • Default server behavior

  • Configuration file includes

Common log files:

/var/log/nginx/access.log
/var/log/nginx/error.log
awk

Checking these logs is essential for troubleshooting Nginx issues.

How to Serve Static Content Using Nginx

Step 1: Create a Server Configuration

Navigate to:

cd /etc/nginx/conf.d
awk

Create a new configuration file:

sudo vim default.conf
vim

Add the following configuration:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    root /var/www/html;
    index index.html index.htm;
    server_name _;
    location / {
        try_files $uri $uri/ =404;
    }
}
nginx

Save and exit (:wq!).

📌 You can also place this file in sites-enabled/ if preferred.

Step 2: Add Static Content

Navigate to the web root directory:

cd /var/www/html
awk

Create an HTML file:

sudo vim index.html
vim

Paste the following content:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Nginx</title>
</head>
<body>
    <h1>Hello from Nginx 🚀</h1>
</body>
</html>
xml

Step 3: Reload Nginx

sudo systemctl reload nginx
ebnf

Step 4: Verify in Browser

Open your browser and visit:

http://localhost
awk
You should see your HTML page rendered successfully 🎉

Conclusion

Nginx is a powerful and lightweight web server that plays a key role in modern infrastructure. In this guide, you learned how to:

  • Install Nginx

  • Understand its configuration structure

  • Serve static content

This is just the beginning—Nginx can also be used as a reverse proxy, load balancer, and API gateway.