NGINX

NGINX 官方开源软件库。NGINX(读作 "engine x" 或 "en-jin-eks")是世界上最流行的 Web 服务器、高性能负载平衡器、反向代理、API 网关和内容缓存。原作者为伊戈尔-瑟索耶夫。「The official NGINX Open Source repository. 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. originally written by Igor Sysoev.」

Github星跟蹤圖

nginx [engine x]是一个HTTP和反向代理服务器、一个邮件代理服务器和一个通用的TCP/UDP代理服务器,最初由Igor Sysoev编写。 很长一段时间,它一直在许多负载很重的俄罗斯网站上运行,包括Yandex,Mail.Ru,VK和Rambler。 据Netcraft称,nginx在2018年12月服务或代理了25.89%最繁忙的网站。以下是一些成功案例:Dropbox,Netflix,Wordpress.com,FastMail.FM。

源和文档根据2条款BSD类许可证分发。

Nginx, Inc. 提供商业支持。

基本的HTTP服务器功能

  • 提供静态和索引文件,自动索引;打开文件描述符缓存;
  • 通过缓存加速反向代理;负载均衡和容错;
  • 通过缓存FastCGI,uwsgi,SCGI和memcached服务器加速支持;负载均衡和容错;
  • 模块化架构。过滤器包括gzipping,字节范围,分块响应,XSLT,SSI和图像变换过滤器。如果由代理或FastCGI / uwsgi / SCGI服务器处理,则可以并行处理单个页面中的多个SSI包含;
  • SSL和TLS SNI支持;
  • 支持HTTP / 2,具有加权和基于依赖性的优先级。

其他HTTP服务器功能

  • 基于名称和基于IP的虚拟服务器;
  • 保持活跃和流水线连接支持;
  • 访问日志格式,缓冲日志写入,快速日志轮换和syslog日志记录;
  • 3xx-5xx错误代码重定向;
  • 重写模块:使用正则表达式更改URI;
  • 根据客户端地址执行不同的功能;
  • 基于客户端IP地址,密码(HTTP基本身份验证)和子请求结果的访问控制;
  • 验证HTTP referer;
  • PUT,DELETE,MKCOL,COPY和MOVE方法;
  • FLV和MP4流媒体;
  • 响应速度限制;
  • 限制来自一个地址的同时连接或请求的数量;
  • 基于IP的地理定位;
  • A / B测试;
  • 请求镜像;
  • 嵌入式Perl;
  • njs脚本语言。

邮件代理服务器功能

  • 用户使用外部HTTP身份验证服务器重定向到IMAP或POP3服务器;
  • 使用外部HTTP身份验证服务器进行用户身份验证,并将连接重定向到内部SMTP服务器;
  • 验证方法:
  • POP3:USER / PASS,APOP,AUTH LOGIN / PLAIN / CRAM-MD5;
  • IMAP:登录,AUTH LOGIN / PLAIN / CRAM-MD5;
  • SMTP:AUTH LOGIN / PLAIN / CRAM-MD5;
  • SSL支持;
  • STARTTLS和STLS支持。

TCP/UDP代理服务器功能

  • TCP和UDP的通用代理;
  • SSL和TLS SNI支持TCP;
  • 负载均衡和容错;
  • 基于客户端地址的访问控制;
  • 根据客户端地址执行不同的功能;
  • 限制来自一个地址的同时连接数;
  • 访问日志格式,缓冲日志写入,快速日志轮换和syslog日志记录;
  • 基于IP的地理定位;
  • A/B测试;
  • njs脚本语言。

架构和可扩展性

  • 一个主要和几个工人流程;工作进程在非特权用户下运行;
  • 配置灵活;
  • 在不中断客户端服务的情况下重新配置和升级可执行文件;
  • 支持kqueue(FreeBSD 4.1+),epoll(Linux 2.6+),/ dev / poll(Solaris 7 11/99 +),事件端口(Solaris 10),select和poll;
  • 支持各种kqueue功能,包括EV_CLEAR,EV_DISABLE(暂时禁用事件),NOTE_LOWAT,EV_EOF,可用数据的数量,错误代码;
  • 支持各种epoll功能,包括EPOLLRDHUP(Linux 2.6.17 +,glibc 2.8+)和EPOLLEXCLUSIVE(Linux 4.5 +,glibc 2.24+);
  • sendfile(FreeBSD 3.1 +,Linux 2.2 +,macOS 10.5+),sendfile64(Linux 2.4.21+)和sendfilev(Solaris 8 7/01 +)支持;
  • 文件AIO(FreeBSD 4.3 +,Linux 2.6.22+);
  • DIRECTIO(FreeBSD 4.4 +,Linux 2.4 +,Solaris 2.6 +,macOS);
  • Accept-filters(FreeBSD 4.1 +,NetBSD 5.0+)和TCP_DEFER_ACCEPT(Linux 2.4+)支持;
  • 10,000个非活动HTTP保持活动连接占用大约2.5M内存;
  • 数据复制操作保持在最低限度。

经测试的操作系统和平台

  • FreeBSD 3 — 11 / i386; FreeBSD 5 — 11 / amd64;
  • Linux 2.2 — 4 / i386; Linux 2.6 — 4 / amd64; Linux 3 — 4 / armv6l, armv7l, aarch64, ppc64le;
  • Solaris 9 / i386, sun4u; Solaris 10 / i386, amd64, sun4v;
  • AIX 7.1 / powerpc;
  • HP-UX 11.31 / ia64;
  • macOS / ppc, i386;
  • Windows XP, Windows Server 2003.

注:仓库是 http://hg.nginx.org/nginx/ 的官方只读镜像,每小时更新一次。 GitHub上的拉取请求无法接受,将自动关闭。 向nginx提交更改的正确方法是通过nginx开发邮件列表,请参阅http://nginx.org/en/docs/contributing_changes.html http://nginx.org/

主要指標

概覽
名稱與所有者nginx/nginx
主編程語言C
編程語言Perl (語言數: 7)
平台BSD, Linux, Mac, Solaris, Unix-like, Windows
許可證BSD 2-Clause "Simplified" License
所有者活动
創建於2015-06-23 10:26:27
推送於2025-04-18 19:57:26
最后一次提交2025-01-14 11:11:28
發布數571
最新版本名稱release-1.27.5 (發布於 2025-04-16 16:03:18)
第一版名稱release-0.1.0 (發布於 )
用户参与
星數26.6k
關注者數1k
派生數7.3k
提交數8.4k
已啟用問題?
問題數262
打開的問題數136
拉請求數68
打開的拉請求數63
關閉的拉請求數151
项目设置
已啟用Wiki?
已存檔?
是復刻?
已鎖定?
是鏡像?
是私有?

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.

[!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.

Table of contents

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.

[!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.

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 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.

[!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.

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.

[!NOTE]
The set of directives available to your distribution of NGINX is dependent on which modules have been made available to it.

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:

  • A "master" process that maintains worker processes, as well as, reads and evaluates configuration files.
  • 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.

[!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.

Downloading and installing

Follow these steps to download and install precompiled NGINX binaries. You may also choose to build NGINX locally from source code.

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.

Linux binary installation process

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.

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

For more information on installing NGINX on FreeBSD system, visit https://nginx.org/en/docs/install.html

Windows executables

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.

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 repository as the core NGINX binaries described in previous steps.

[!TIP]
NGINX JavaScript (njs), is a popular NGINX dynamic module that enables the extension of core NGINX functionality using familiar JavaScript syntax.

[!IMPORTANT]
If desired, dynamic modules can also be built statically into NGINX at compile time.

Getting started with NGINX

For a gentle introduction to NGINX basics, please see our Beginner’s Guide.

Installing SSL certificates and enabling TLS encryption

See Configuring HTTPS servers for a quick guide on how to enable secure traffic to your NGINX installation.

Load Balancing

For a quick start guide on configuring NGINX as a Load Balancer, please see Using nginx as HTTP load balancer.

Rate limiting

See our Rate Limiting with NGINX blog post for an overview of core concepts for provisioning NGINX as an API Gateway.

Content caching

See A Guide to Caching with NGINX and NGINX Plus blog post for an overview of how to use NGINX as a content cache (e.g. edge server of a content delivery network).

Building from source

The following steps can be used to build NGINX from source code available in this repository.

Installing dependencies

Most Linux distributions will require several dependencies to be installed in order to build NGINX. The following instructions are specific to the apt package manager, widely available on most Ubuntu/Debian distributions and their derivatives.

[!TIP]
It is always a good idea to update your package repository lists prior to installing new packages.

sudo apt update

Installing compiler and make utility

Use the following command to install the GNU C compiler and Make utility.

sudo apt install gcc make

Installing dependency libraries

sudo apt install libpcre3-dev zlib1g-dev

[!WARNING]
This is the minimal set of dependency libraries needed to build NGINX with rewriting and gzip capabilities. Other dependencies may be required if you choose to build NGINX with additional modules. Monitor the output of the configure command discussed in the following sections for information on which modules may be missing. For example, if you plan to use SSL certificates to encrypt traffic with TLS, you'll need to install the OpenSSL library. To do so, issue the following command.

sudo apt install libssl-dev

Cloning the NGINX GitHub repository

Using your preferred method, clone the NGINX repository into your development directory. See Cloning a GitHub Repository for additional help.

git clone https://github.com/nginx/nginx.git

Configuring the build

Prior to building NGINX, you must run the configure script with appropriate flags. This will generate a Makefile in your NGINX source root directory that can then be used to compile NGINX with options specified during configuration.

From the NGINX source code repository's root directory:

auto/configure

[!IMPORTANT]
Configuring the build without any flags will compile NGINX with the default set of options. Please refer to https://nginx.org/en/docs/configure.html for a full list of available build configuration options.

Compiling

The configure script will generate a Makefile in the NGINX source root directory upon successful execution. To compile NGINX into a binary, issue the following command from that same directory:

make

Location of binary and installation

After successful compilation, a binary will be generated at <NGINX_SRC_ROOT_DIR>/objs/nginx. To install this binary, issue the following command from the source root directory:

sudo make install

[!IMPORTANT]
The binary will be installed into the /usr/local/nginx/ directory.

Running and testing the installed binary

To run the installed binary, issue the following command:

sudo /usr/local/nginx/sbin/nginx

You may test NGINX operation using curl.

curl localhost

The output of which should start with:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>

Asking questions and reporting issues

We encourage you to engage with us.

  • NGINX GitHub Discussions, is the go-to place to start asking questions and sharing your thoughts.
  • Our GitHub Issues page offers space to submit and discuss specific issues, report bugs, and suggest enhancements.

Contributing code

Please see the Contributing guide for information on how to contribute code.

Additional help and resources

  • See the NGINX Community Blog for more tips, tricks and HOW-TOs related to NGINX and related projects.
  • Access nginx.org, your go-to source for all documentation, information and software related to the NGINX suite of projects.

Changelog

See our changelog to keep track of updates.

License

2-clause BSD-like license


Additional documentation available at: https://nginx.org/en/docs