Backend Development 10 min read

Comprehensive Introduction to Nginx: Features, Usage, Commands, and Configuration

This article provides a detailed overview of Nginx, covering its architecture, key features such as load balancing and proxying, common commands, directory layout, configuration syntax, and practical examples, while also offering download links and code snippets for hands‑on use.

Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Mike Chen's Internet Architecture
Comprehensive Introduction to Nginx: Features, Usage, Commands, and Configuration

Nginx

Nginx is a lightweight, high‑performance web server and reverse proxy developed by Igor Sysoev, widely used for load balancing in large‑scale internet projects.

Key Features of Nginx

It is popular because it consumes less memory, offers high stability and strong concurrency, uses an event‑driven architecture to support millions of TCP connections, provides modular extensibility with many third‑party modules, and runs on multiple platforms such as Linux, Windows, and macOS.

Typical Applications

1. Forward Proxy – The client explicitly specifies the target server, while the proxy hides the client’s real IP. Example: accessing www.google.com via a proxy server.

2. Reverse Proxy – Clients are unaware of the proxy; requests are sent to the proxy, which forwards them to backend servers and returns the response, masking the real server IP.

3. Load Balancing – Distributes incoming requests across multiple servers according to load‑balancing algorithms.

4. Static/Dynamic Separation – Serves static assets from dedicated servers while dynamic pages are processed by application servers, improving performance and reducing load.

Using Nginx

1. Download – Official download page: https://nginx.org/en/download.html . Choose the stable version and upload the package to a Linux server.

Nginx Commands

Common commands:

nginx -s stop       # Fast shutdown, may not save state
nginx -s quit       # Graceful shutdown, saves state
nginx -s reload     # Reload configuration after changes
nginx -s reopen     # Reopen log files
nginx -c filename   # Use a specific configuration file
nginx -t            # Test configuration syntax only
nginx -v            # Show Nginx version
nginx -V            # Show version, compiler, and configure parameters

Directory Structure

├── conf                             # All configuration files
│   ├── nginx.conf                   # Main configuration file
│   ├── mime.types                   # Media type definitions
│   └── ...
├── html                             # Default site root
│   ├── index.html
│   └── 50x.html
├── logs                             # Access and error logs
├── sbin                             # Nginx executable
└── ...

Configuration Overview

The main configuration file is nginx/conf/nginx.conf . It consists of a global main block, events block, and an http block that can contain multiple server and location directives.

main        # Global settings
├── events  # Network connection settings
├── http    # Core HTTP features, proxy, cache, logs, etc.
│   ├── upstream # Backend server definitions for load balancing
│   ├── server   # Virtual host definitions
│   │   ├── location # URI matching and handling
│   │   └── ...
└── ...

Key directives:

worker_processes – Number of worker processes.

worker_connections – Max connections per worker.

include mime.types – Load media type mappings.

sendfile on – Enable efficient file transfer.

keepalive_timeout – Connection timeout.

server – Define listening port, server_name, and root.

location / – Set document root and index files.

error_page – Custom error pages.

Sample Configuration

worker_processes  1;  # Number of workers
events {
    worker_connections 1024;  # Max connections per worker
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

Usage Example

events {
    worker_connections 1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  192.168.71.167;
        location / {
            root   html;
            proxy_pass http://127.0.0.1:8080;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

For more in‑depth study, the author offers a 300k‑word collection of Alibaba architecture materials and a comprehensive Java interview question set, available via the linked WeChat public account.

backend developmentLoad BalancingconfigurationNginxReverse ProxyWeb Server
Mike Chen's Internet Architecture
Written by

Mike Chen's Internet Architecture

Over ten years of BAT architecture experience, shared generously!

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.