What is Nginx?

What is Nginx?

Sol Vathanak
Sol Vathanak
DevOps and AutomationΒ·October 15, 2026Β·1 αž…αžΌαž›αž…αž·αžαŸ’αž

Guide to Web Servers and Reverse Proxies

Have you ever wondered how websites handle thousands of visitors at the same time without crashing? πŸ€”

Imagine you've built an amazing website using React, Next.js, Python, or Node.js.

Everything works perfectly on your computer.

But when you deploy your application to a server, you start facing problems:

  • How can users access your website through a domain name?
  • How do you handle thousands of incoming requests?
  • How can you connect multiple applications to one server?
  • How do you enable HTTPS to secure your website?
  • How can you distribute traffic across multiple application servers?

This is where Nginx comes in! πŸš€

1. What Is Nginx?

Nginx (pronounced "Engine-X") is a free, open-source, high-performance web server.

It can also work as a reverse proxy, load balancer, HTTP cache, and gateway for web applications.

In simple words, Nginx helps receive, process, and route requests from users to the correct website or application.

🚦 Think of Nginx as a traffic controller for websites.

Imagine a busy city with thousands of cars traveling to different destinations.

Without traffic management, roads could become congested.

Nginx works similarly for web traffic.

It receives incoming requests and decides how to handle them based on its configuration.

For example:

  • Requests for static website files β†’ Serve files directly.
  • Requests for an application β†’ Forward them to the application server.
  • Requests for different services β†’ Route them to the correct backend.
  • Requests across multiple servers β†’ Distribute traffic using load balancing.

The main idea:

User β†’ Nginx β†’ Website or Application β†’ Response

Nginx helps make web applications easier to manage, scale, and secure.

2. Why Do Developers Use Nginx?

Nginx is widely used in software development and DevOps because of its performance, flexibility, and reliability.

βœ… High Performance

Nginx uses an event-driven architecture to efficiently handle many concurrent connections.

βœ… Reverse Proxy

Nginx forwards incoming requests to backend applications such as Node.js, Python, Java, or PHP-based services.

βœ… Load Balancing

Nginx can distribute incoming traffic across multiple application servers.

βœ… HTTPS Support

Nginx supports SSL/TLS certificates to encrypt communication between users and websites.

βœ… Static File Serving

Nginx can efficiently serve HTML, CSS, JavaScript, images, and other static files.

βœ… Caching

Nginx can cache selected responses to reduce repeated backend processing and improve performance.

βœ… Microservices Support

Nginx can route requests to different services based on domains, URLs, or paths.

3. Important Nginx Concepts

Before using Nginx, you should understand these basic concepts.

🌐 Web Server

A web server receives HTTP requests from browsers and returns web content.

For example, when someone visits:

https://example.com

Nginx can serve the website's HTML, CSS, JavaScript, and images.

Think of a web server as a restaurant kitchen that prepares and serves what customers request.

πŸ”„ Reverse Proxy

A reverse proxy sits between users and backend application servers.

Instead of users connecting directly to your application, they connect to Nginx.

Nginx forwards their requests to the appropriate backend.

Example:

text
          Internet
             |
             v
           Nginx
        Reverse Proxy
             |
             v
      Node.js Application
         Port 3000

For example:

User visits https://example.com

Nginx forwards the request to http://127.0.0.1:3000.

The application processes the request and sends its response back through Nginx.

βš–οΈ Load Balancer

A load balancer distributes requests across multiple servers.

Imagine your website becomes popular and one application server cannot handle all the traffic.

Instead of using only one server, you deploy three application instances.

text
              Users
                |
                v
              Nginx
          Load Balancer
                |
       +--------+--------+
       |        |        |
       v        v        v
    App 1     App 2     App 3
    :3001     :3002     :3003

Nginx can distribute requests among these servers to improve scalability and availability.

πŸ” SSL/TLS Termination

Nginx can manage HTTPS connections and decrypt incoming traffic before forwarding requests to a backend.

For example:

https://example.com β†’ Nginx β†’ Application

Nginx handles the public HTTPS connection. Communication to the backend can use HTTP on a trusted local network or HTTPS when required.

πŸ“ Nginx Configuration File

Nginx uses configuration files to define how it handles requests.

On many Linux installations, the main configuration file is located at:

text
/etc/nginx/nginx.conf

Additional configuration files may be stored in directories such as:

text
/etc/nginx/conf.d/

or, on Debian/Ubuntu installations:

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

The exact structure depends on the operating system and installation method.

4. Your First Nginx Commands

Let's try Nginx with some simple commands on Ubuntu Linux.

Step 1: Install Nginx

Update your package list:

bash
sudo apt update

Install Nginx:

bash
sudo apt install nginx -y

Step 2: Check Nginx Version

bash
nginx -v

This command displays the installed Nginx version.

Step 3: Start Nginx

bash
sudo systemctl start nginx

This starts the Nginx service.

Step 4: Check Nginx Status

bash
sudo systemctl status nginx

If Nginx is running successfully, you should see:

text
Active: active (running)

Step 5: Open Nginx in Your Browser

Visit:

http://localhost

Or, from another computer:

http://YOUR_SERVER_IP

You should see the default Nginx welcome page if the service is accessible and the default site is enabled.

πŸŽ‰ Congratulations! You've successfully started your first Nginx web server.

Step 6: Test Nginx Configuration

bash
sudo nginx -t

This checks whether your Nginx configuration syntax is valid.

Step 7: Reload Nginx

bash
sudo systemctl reload nginx

This applies configuration changes without a full service restart.

Step 8: Restart Nginx

bash
sudo systemctl restart nginx

This stops and starts the Nginx service.

5. Real-World Example: Nginx as a Reverse Proxy

Imagine you've built a Node.js application running on port 3000.

You want users to access it through your website domain instead of typing:

http://example.com:3000

Nginx can help!

Step 1: Your Application Is Running

Suppose your application is listening at:

text
http://127.0.0.1:3000

Step 2: Create an Nginx Configuration

On Ubuntu, create a configuration file:

bash
sudo nano /etc/nginx/sites-available/myapp

Add this configuration:

nginx
server {
    listen 80;
    server_name example.com;

    location / {
        proxy_pass http://127.0.0.1:3000;

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For
            $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Replace example.com with your own domain.

Step 3: Enable Your Configuration

bash
sudo ln -s /etc/nginx/sites-available/myapp \
  /etc/nginx/sites-enabled/

Step 4: Test the Configuration

bash
sudo nginx -t

Step 5: Reload Nginx

bash
sudo systemctl reload nginx

Step 6: Access Your Website

Ensure your domain points to the server and port 80 is accessible.

Now visit:

http://example.com

Nginx forwards incoming requests to your Node.js application running on port 3000.

πŸŽ‰ Your application is now accessible through Nginx!

For a public production website, the next step is configuring HTTPS.

6. Nginx vs Apache

Many beginners ask:

Is Nginx the same as Apache?

Both are popular web servers, but their architectures and configurations differ.

🌐 Nginx

Nginx uses an event-driven architecture designed to handle many concurrent connections efficiently.

It is commonly used for static content, reverse proxying, load balancing, and web application routing.

πŸͺΆ Apache HTTP Server

Apache is a mature and flexible web server with a large module ecosystem.

It supports multiple processing models and directory-level configuration using .htaccess in supported setups.

Feature Nginx Apache
Architecture Event-driven Multiple processing models
Static files Highly efficient Efficient
Reverse proxy Supported Supported
Load balancing Supported Supported
.htaccess Not supported Supported
Configuration Centralized configuration Centralized and optional directory-level configuration
Common use Proxy, static sites, web apps General-purpose web hosting and web apps

Both are excellent tools.

The best choice depends on your application, server environment, and requirements.

7. Nginx with Docker

Nginx can also run inside a Docker container.

This is useful when you want to test Nginx without installing it directly on your operating system.

Step 1: Pull the Nginx Image

bash
docker pull nginx:stable

Step 2: Run an Nginx Container

bash
docker run -d \
  --name my-nginx \
  -p 8080:80 \
  nginx:stable

What does this command mean?

  • docker run β€” Creates and starts a container.
  • -d β€” Runs it in the background.
  • --name my-nginx β€” Names the container.
  • -p 8080:80 β€” Maps host port 8080 to container port 80.
  • nginx:stable β€” Specifies the Docker image.

Step 3: Open Your Browser

Visit:

http://localhost:8080

You should see the Nginx welcome page.

Step 4: Check Running Containers

bash
docker ps

Step 5: Stop the Container

bash
docker stop my-nginx

Step 6: Remove the Container

bash
docker rm my-nginx

πŸŽ‰ You've successfully run Nginx using Docker!

8. Where Is Nginx Used in Real Life?

Nginx plays an important role in modern web infrastructure.

πŸ‘¨β€πŸ’» Web Development

Developers use Nginx to serve websites and route requests to backend applications.

πŸš€ Production Deployment

DevOps engineers use Nginx as a reverse proxy in front of production applications.

☁️ Cloud Infrastructure

Nginx can run on cloud virtual machines, containers, and other server environments.

βš–οΈ Load Balancing

Teams use Nginx to distribute traffic across multiple application instances.

πŸ” HTTPS and Security

Nginx handles HTTPS connections, redirects HTTP traffic to HTTPS, and can apply access controls and request limits.

🐳 Docker and Microservices

Nginx can route requests between containerized services.

βš™οΈ Kubernetes

NGINX-based ingress controllers and gateway solutions can manage incoming traffic to Kubernetes applications.

9. Common Beginner Mistakes

❌ Changing Nginx configuration without testing

βœ… Always run sudo nginx -t before reloading Nginx.

❌ Exposing backend application ports unnecessarily

βœ… Keep backend services private when possible and route public requests through Nginx.

❌ Using HTTP for public production websites

βœ… Configure HTTPS with a valid SSL/TLS certificate.

❌ Forgetting to configure firewall rules

βœ… Allow only the ports your application requires, such as 80 and 443 for

αž…αžΌαž›αžšαž½αž˜αž€αžΆαžšαž–αž·αž—αžΆαž€αŸ’αžŸαžΆ
1 αž˜αžαž·αž™αŸ„αž”αž›αŸ‹αžšαž αžΌαžαž˜αž€αžŠαž›αŸ‹αž–αŸαž›αž“αŸαŸ‡ - αž…αžΌαž›αž…αž·αžαŸ’αž αž•αŸ’αžŠαž›αŸ‹αž˜αžαž· αž“αž·αž„αž…αŸ‚αž€αžšαŸ†αž›αŸ‚αž€αžšαž”αžŸαŸ‹αž’αŸ’αž“αž€αž“αŸ…αž›αžΎ CambostackαŸ”
αž”αžΎαž€αž€αŸ’αž“αž»αž„ Cambostack