nginx / nginx

nginx / nginx

NGINX (pronounced “engine x” or “en-jin-eks”) is the world’s most popular Web Server, high performance Load Balancer, Reverse Proxy, API Gateway and Content Cache. NGINX is free and open source software, distributed under the terms of a simplified 2-clause BSD-like license. Enterprise distributions, commercial support and training are available from F5, Inc. NGINX(发音为“engine x”或“en-jin-eks”)是全球最受欢迎的 Web 服务器、高性能负载均衡器、反向代理、API 网关和内容缓存。NGINX 是一款免费的开源软件,根据简化的 2 条款 BSD 类许可证条款分发。企业版发行版、商业支持和培训可从 F5, Inc. 获取。

Important: The goal of this README is to provide a basic, structured introduction to NGINX for novice users. Please refer to the full NGINX documentation for detailed information on installing, building, configuring, debugging, and more. These documentation pages also contain a more detailed Beginners Guide, How-Tos, Development guide, and a complete module and directive reference. 重要提示:本 README 的目标是为初学者提供关于 NGINX 的基础结构化介绍。请参阅完整的 NGINX 文档,以获取有关安装、构建、配置、调试等方面的详细信息。这些文档页面还包含更详细的初学者指南、操作指南、开发指南以及完整的模块和指令参考。

How it works

工作原理

NGINX is installed software with binary packages available for all major operating systems and Linux distributions. See Tested OS and Platforms for a full list of compatible systems. NGINX 是一款已安装的软件,其二进制包适用于所有主流操作系统和 Linux 发行版。请参阅“已测试的操作系统和平台”以获取兼容系统的完整列表。

Important: While nearly all popular Linux-based operating systems are distributed with a community version of nginx, we highly advise installation and usage of official packages or sources from this repository. Doing so ensures that you’re using the most recent release or source code, including the latest feature-set, fixes and security patches. 重要提示:虽然几乎所有流行的基于 Linux 的操作系统都预装了社区版的 nginx,但我们强烈建议安装并使用来自本仓库的官方包或源代码。这样做可以确保您使用的是最新的版本或源代码,包括最新的功能集、修复程序和安全补丁。

Modules

模块

NGINX is comprised of individual modules, each extending core functionality by providing additional, configurable features. See “Modules reference” at the bottom of nginx documentation for a complete list of official modules. NGINX 由多个独立的模块组成,每个模块通过提供额外的、可配置的功能来扩展核心功能。请参阅 NGINX 文档底部的“模块参考”以获取官方模块的完整列表。

NGINX modules can be built and distributed as static or dynamic modules. Static modules are defined at build-time, compiled, and distributed in the resulting binaries. See Dynamic Modules for more information on how they work, as well as, how to obtain, install, and configure them. NGINX 模块可以作为静态或动态模块进行构建和分发。静态模块在构建时定义、编译并分发到生成的二进制文件中。有关它们的工作原理以及如何获取、安装和配置它们的更多信息,请参阅“动态模块”。

Tip: You can issue the following command to see which static modules your NGINX binaries were built with: nginx -V. See Configuring the build for information on how to include specific Static modules into your nginx build. 提示:您可以运行以下命令来查看您的 NGINX 二进制文件构建时包含了哪些静态模块:nginx -V。有关如何将特定的静态模块包含到您的 nginx 构建中的信息,请参阅“配置构建”。

Configurations

配置

NGINX is highly flexible and configurable. Provisioning the software is achieved via text-based config file(s) accepting parameters called “Directives”. See Configuration File’s Structure for a comprehensive description of how NGINX configuration files work. NGINX 具有高度的灵活性和可配置性。该软件的配置是通过基于文本的配置文件实现的,这些文件接受称为“指令”的参数。有关 NGINX 配置文件工作原理的全面描述,请参阅“配置文件结构”。

Note: The set of directives available to your distribution of NGINX is dependent on which modules have been made available to it. 注意:您的 NGINX 发行版可用的指令集取决于已为其启用的模块。

Runtime

运行时

Rather than running in a single, monolithic process, NGINX is architected to scale beyond Operating System process limitations by operating as a collection of processes. They include: NGINX 并非运行在单一的单体进程中,其架构设计为通过作为一组进程运行,从而突破操作系统的进程限制。这些进程包括:

  • A “master” process that maintains worker processes, as well as, reads and evaluates configuration files. 一个“主(master)”进程,负责维护工作进程,以及读取和评估配置文件。
  • One or more “worker” processes that process data (eg. HTTP requests). The number of worker processes is defined in the configuration file and may be fixed for a given configuration or automatically adjusted to the number of available CPU cores. In most cases, the latter option optimally balances load across available system resources, as NGINX is designed to efficiently distribute work across all worker processes. 一个或多个“工作(worker)”进程,负责处理数据(例如 HTTP 请求)。工作进程的数量在配置文件中定义,可以针对特定配置固定,也可以自动调整为可用 CPU 核心的数量。在大多数情况下,后一种选项能更好地平衡可用系统资源之间的负载,因为 NGINX 的设计旨在高效地将工作分配给所有工作进程。

Tip: Processes synchronize data through shared memory. For this reason, many NGINX directives require the allocation of shared memory zones. As an example, when configuring rate limiting, connecting clients may need to be tracked in a common memory zone so all worker processes can know how many times a particular client has accessed the server in a span of time. 提示:进程通过共享内存同步数据。因此,许多 NGINX 指令需要分配共享内存区域。例如,在配置速率限制时,可能需要在公共内存区域中跟踪连接的客户端,以便所有工作进程都能知道特定客户端在一段时间内访问服务器的次数。

Downloading and installing

下载与安装

Follow these steps to download and install precompiled NGINX binaries. You may also choose to build NGINX locally from source code. 请按照以下步骤下载并安装预编译的 NGINX 二进制文件。您也可以选择在本地从源代码构建 NGINX。

Stable and Mainline binaries

稳定版与主线版二进制文件

NGINX binaries are built and distributed in two versions: stable and mainline. Stable binaries are built from stable branches and only contain critical fixes backported from the mainline version. Mainline binaries are built from the master branch and contain the latest features and bugfixes. You’ll need to decide which is appropriate for your purposes. NGINX 二进制文件以两个版本构建和分发:稳定版(stable)和主线版(mainline)。稳定版二进制文件基于稳定分支构建,仅包含从主线版本向后移植的关键修复。主线版二进制文件基于主分支构建,包含最新的功能和错误修复。您需要根据自己的需求决定使用哪个版本。

Linux binary installation process

Linux 二进制安装流程

The NGINX binary installation process takes advantage of package managers native to specific Linux distributions. For this reason, first-time installations involve adding the official NGINX package repository to your system’s package manager. Follow these steps to download, verify, and install NGINX binaries using the package manager appropriate for your Linux distribution. NGINX 二进制安装流程利用了特定 Linux 发行版自带的包管理器。因此,首次安装时需要将官方 NGINX 软件包仓库添加到您系统的包管理器中。请按照以下步骤,使用适合您 Linux 发行版的包管理器来下载、验证并安装 NGINX 二进制文件。

Upgrades: Future upgrades to the latest version can be managed using the same package manager without the need to manually download and verify binaries. 升级:未来的版本升级可以使用相同的包管理器进行管理,无需手动下载和验证二进制文件。

FreeBSD installation process

FreeBSD 安装流程

For more information on installing NGINX on FreeBSD system, visit https://nginx.org/en/docs/install.html 有关在 FreeBSD 系统上安装 NGINX 的更多信息,请访问 https://nginx.org/en/docs/install.html

Windows executables

Windows 可执行文件

Windows executables for mainline and stable releases can be found on the main NGINX download page. Note that the current implementation of NGINX for Windows is at the Proof-of-Concept stage and should only be used for development and testing purposes. For additional information, please see nginx for Windows. 主线版和稳定版的 Windows 可执行文件可在 NGINX 主下载页面找到。请注意,目前 NGINX 的 Windows 实现处于概念验证(Proof-of-Concept)阶段,仅应用于开发和测试目的。有关更多信息,请参阅“nginx for Windows”。

Dynamic modules

动态模块

NGINX version 1.9.11 added support for Dynamic Modules. Unlike Static modules, dynamically built modules can be downloaded, installed, and configured after the core NGINX binaries have been built. Official dynamic module binaries are available from the same package reposi… NGINX 1.9.11 版本增加了对动态模块的支持。与静态模块不同,动态构建的模块可以在核心 NGINX 二进制文件构建完成后进行下载、安装和配置。官方动态模块二进制文件可从相同的软件包仓库获取……