Backend Development 10 min read

Master Nginx: From Basics to Advanced Configuration for High‑Performance Web Servers

This guide walks you through Nginx fundamentals, reverse‑proxy concepts, load‑balancing techniques, static‑dynamic separation, cross‑platform installation steps, essential commands, and core configuration examples, equipping developers with the skills to deploy and manage a robust web server.

macrozheng
macrozheng
macrozheng
Master Nginx: From Basics to Advanced Configuration for High‑Performance Web Servers

Introduction

When building a website, Nginx is an essential high‑performance HTTP and reverse‑proxy server. First released on October 4, 2004, it is widely adopted for its low memory usage, strong concurrency (up to ~50,000 connections), simple configuration, minimal bugs, easy installation, and long‑term stability.

Key Features

Low memory consumption

High concurrency support

Concise configuration syntax

Very few bugs

Simple installation

Stable operation without frequent restarts

What Nginx Does

Reverse proxy is one of its most common functions. To understand reverse proxy, first grasp forward proxy: a client accesses a remote server via a proxy that forwards the request. In contrast, a reverse proxy sits in front of one or more backend servers, distributing incoming client requests across them.

Load balancing can be achieved with Nginx's built‑in round‑robin and weighted round‑robin algorithms, allowing servers with different capacities to handle proportionate traffic.

Another powerful feature is static‑dynamic separation : static resources (e.g., CSS, JS, images) are served directly by Nginx without involving the application server, improving overall response speed.

Installation

Installation varies by operating system. On Windows, download the zip package from the official site and extract it. On Linux, you can use package managers or control panels like Baota.

http://nginx.org/en/download.html

Example for macOS using Homebrew:

1. Check if Nginx is installed:

brew info nginx

2. Install Nginx:

brew install nginx

3. Important paths after installation:

Root directory:

/usr/local/var/www

Configuration file:

/usr/local/etc/nginx/nginx.conf

Default listening port:

8080

4. Start Nginx:

nginx

5. Open a browser and visit

localhost:8080

to see the welcome page.

Common Nginx Commands

<code>nginx   启动
nginx -s stop   停止
nginx -s quit   安全退出
nginx -s reload   重新加载配置文件
ps aux|grep nginx   查看nginx进程
</code>

The

reload

command applies configuration changes without disrupting active connections.

Configuration Structure

<code>main        # Global settings
├── events  # Network connection settings
├── http    # Proxy, cache, logging, etc.
│   ├── upstream   # Load‑balancing settings
│   ├── server     # Virtual host definitions (can have multiple)
│   │   ├── location   # URI matching blocks (can have multiple)
│   │   └── ...
│   └── ...
└── ...
</code>

Typical default configuration (comments added for clarity):

<code>worker_processes  1;  # Usually set to number of CPU cores

events {
    worker_connections  1024;  # Max concurrent connections per worker
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile      on;
    keepalive_timeout  65;

    server {
        listen       8080;
        server_name  localhost;

        location / {
            root   html;
            index  index.html index.htm;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

    include servers/*;  # Load additional server blocks
}
</code>

Further Learning Resources

Video tutorials and detailed articles can deepen your understanding of Nginx load balancing, static‑dynamic separation, and advanced configuration.

狂神说 – Nginx 入门视频教程

黑马程序员 – 完整的 Nginx 课程(159 讲)

极客时间 – Nginx 100 讲(付费)

掘金 – 《Nginx 从入门到实践》全文详解

Studying these materials will help you become the go‑to person for Nginx issues in your team.

Backend DevelopmentLoad BalancingconfigurationNginxreverse proxyweb serverInstallation
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.