Master Nginx: From Basics to Installation and Configuration

This guide introduces Nginx's key features, explains reverse and forward proxy concepts, walks through installation on macOS and Windows, details common commands, and demonstrates configuration structures and load‑balancing techniques for effective web server deployment.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Nginx: From Basics to Installation and Configuration

What is Nginx?

Nginx is a high‑performance HTTP server and reverse‑proxy developed by Igor Sysoev, first released on October 4, 2004. Its main advantages are low memory usage, strong concurrency (supporting up to ~50,000 connections), simple configuration, few bugs, easy installation, and high stability.

Core Concepts: Reverse and Forward Proxy

Forward proxy acts on behalf of a client to access external servers, while reverse proxy sits in front of one or more backend servers and distributes incoming client requests among them.

In a reverse‑proxy scenario, multiple backend servers (e.g., A, B, C) share the load of thousands of simultaneous client requests, reducing the pressure on any single server.

Nginx provides built‑in round‑robin and weighted round‑robin algorithms to allocate traffic according to each server’s capacity.

Static‑Dynamic Separation

Nginx can separate static resources (CSS, JS, images) from dynamic requests, allowing static files to be served directly without involving the application server, which improves overall response speed.

Installation Guide

Installation varies by operating system. On Windows, download the zip package from the official site and extract it. On Linux, tools like the Baota panel can automate installation.

Example for macOS using Homebrew:

Check if Nginx is already installed: brew info nginx Install Nginx: brew install nginx Root directory: /usr/local/var/www Configuration file: /usr/local/etc/nginx/nginx.conf Default listening port: 8080 Start Nginx: nginx Open a browser and visit localhost:8080 to see the welcome page.

Common Nginx Commands

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

The reload command applies configuration changes without interrupting active connections.

Configuration Structure

main        # 全局配置
├── events  # 网络连接配置
├── http    # 代理、缓存、日志等
│   ├── upstream   # 负载均衡配置
│   ├── server     # 虚拟主机,可有多个
│   │   ├── location   # URI 匹配,可有多个
│   │   └── ...
│   └── ...
└── ...

Typical default configuration (comments added for clarity):

worker_processes  1;  # 与 CPU 核数相同

events {
    worker_connections  1024;  # 每进程最大并发数
}

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/*;  # 加载子配置
}

Practical Adjustments

When deploying on a Linux server, change the listening port to 80 (or any open port) and set the document root to /home/www. Ensure the chosen port is allowed in the server’s firewall and any control panel security groups.

Learning Resources

Video tutorial by "狂神说" – beginner‑friendly introduction.

Black Horse Programmer Nginx course – 159 video lessons covering fundamentals to advanced topics.

Geek Time "Nginx 100 Lectures" – deep dive into principles (paid).

Article "Nginx from Beginner to Practice" on Juejin – comprehensive written guide.

Studying these materials will help you become proficient with Nginx and capable of solving real‑world server issues.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

ConfigurationInstallation
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

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.