# https://cn.angie.software/index.md

# 欢迎！

[所有新闻](https://cn.angie.software/news/)

* [Angie 和 Angie PRO 更新至 1.11.6 版本](https://cn.angie.software/news/releases/angie-1-11-6/) - Angie 和 Angie PRO 1.11.6 修复版本已发布，移植了前一日在 nginx 中发现的 rewrite 指令漏洞 CVE-2026-9256 的修复。 (25.05.2026)
* [Angie 和 Angie PRO 更新至 1.11.5 版本](https://cn.angie.software/news/releases/angie-1-11-5/) - Angie 和 Angie PRO 1.11.5 修复版本已发布，移植了 nginx 中发现的五个漏洞的修复。这些漏洞涉及 rewrite、ssl_ocsp、scgi_pass、uwsgi_pass 和 charset_map 指令的工作，以及 HTTP/3 协议请求的处理。 (15.05.2026)

Angie Software（Web Server, LLC）是一家俄罗斯IT公司，专注于开发高负载系统解决方案。

我们的产品包括：负载均衡系统 [Angie ADC](https://cn.angie.software//adc/index.md) （应用交付控制器）、Web服务器 [Angie PRO](https://cn.angie.software//angie/pro/index.md) 以及 [Angie Ingress Controller (ANIC)](https://cn.angie.software//anic/index.md) ，这是一个用于管理Kubernetes中容器化应用流量的解决方案。

我们特别引以为傲的是 [开源Web服务器Angie](https://cn.angie.software//angie/index.md) ，它是nginx的一个分支，旨在超越原有的功能。

## 为什么选择我们的解决方案？

我们团队的核心成员是曾在全球知名的Web服务器和负载均衡市场领导者NGINX工作过的专业人士，并且曾在F5 Networks担任高级工程职位。我们定期在国际行业会议上发表演讲，拥有独特的能力，自2011年以来一直是nginx Web服务器的主要开发者。

我们的产品基于nginx技术，这些技术在安全性、容错性和高负载下的可扩展性方面表现优异。向后兼容性使您能够使用我们的解决方案而无需额外的实施和员工再培训成本。作为原始作者和开发者，我们对我们的产品有深入的理解，能够解决最复杂的问题。

除了具有扩展功能的商业产品外，我们还开发全球水平的开源产品。我们的Angie项目在自由BSD许可证下进一步开发nginx，旨在超越其能力并完全取代它。围绕Angie已经形成了一个紧密的社区，定期发布新功能和高质量标准吸引了越来越多来自世界各地的用户。

我们团队的工程师为全球最大的公司提供支持，包括《财富》500强企业。他们因其工作多次获得国际知名奖项，如2016年销售和客户服务银奖斯蒂维奖和2017年销售和客户服务金奖斯蒂维奖。

我们正式「开箱即用」支持中国的 NTLS 加密标准，并使用 TongSuo TLS 库。这意味着完全兼容性和由 TongSuo 开发者官方推荐的可靠数据保护方案。此解决方案更适合亚洲市场，有助于加强技术合作与睦邻友好关系。


# https://cn.angie.software/404.md

# 页面未找到

该页面可能已被移动或删除，或者URL中可能存在拼写错误。

返回 [首页](/) 重新开始，尝试使用 [短链接](https://angie.ws/en/)，或使用 [搜索功能](/search/)。

如果您认为这是一个错误，请通过 [社区论坛](https://forum.angie.support/) 或 [Telegram频道](https://t.me/angie_support) 与我们联系。


# https://cn.angie.software/500.md

# 服务器错误

服务器发生了意外错误。请稍候，我们将尽快修复。

[返回首页](https://cn.angie.software//index.md)


# https://cn.angie.software/vacancies/UX-UI-designer.md

# UX/UI 设计师（Angie ADC）

我们是 Angie Software 团队。公司的核心成员是参与了 nginx 早期开发的资深工程师，他们如今正在打造 nginx 的演进继任者——Angie。我们的产品已经在全球范围内获得越来越多的认可，我们也为自己设定了一个雄心勃勃的目标：超越 F5、Citrix、Radware 这样的行业巨头。

Angie ADC 是一款现代的企业级应用交付控制器。它负责流量路由、负载均衡、SSL 卸载和安全防护——确保应用程序在复杂网络环境中稳定运行所需的一切。我们坚信，制胜的关键不仅在于"引擎"的技术卓越，还在于对市场需求的深刻理解——正是这种理解将复杂的事物转化为真正受欢迎的产品。

我们的文化是非正式的、扁平的：大家平等交流，没有官僚作风，也没有多余的繁文缛节。决策迅速做出，论据比头衔更重要。

## 您将做什么：

- 全面重新思考并发展 Angie ADC 的 UX/UI，把复杂的网络概念（负载均衡、拓扑、安全策略）转化为工程师能直观理解、并且赏心悦目的界面；
- 设计用户场景、制作原型和详细的设计稿，开发 UI 组件、图标和规范，构建产品的视觉语言；
- 进行可用性测试、用户需求研究，并分析反馈，让我们基于数据而不是猜想去验证假设、持续改善体验；
- 与研发团队和技术产品负责人紧密协作：在技术可实现性、商业价值和理想用户体验之间共同寻找平衡。

## 我们想招的人：

- 相信 UX 是战略和竞争优势，而不仅仅是"好看的按钮"；
- 拥有 3 年以上 UX/UI 经验，并有为复杂基础设施或 enterprise 产品做设计的经历；
- 具备系统思维，能把技术上复杂的领域拆解为清晰的模式和场景，而不是简单跟风；
- 熟练使用 Figma 等工具，但更擅长用户调研方法和数据分析，以便向任何受众论证自己的设计决策；
- 具备技术背景，或者足够强的好奇心，能快速钻研网络相关细节，与开发人员同频对话；
- 希望打造一款被业内顶尖公司工程师使用的产品。

## 我们提供：

- 真正影响一款世界级产品的机会，看到您的决策落地，而不必承受大公司的惯性；
- 在一支业内公认的专家团队中工作，团队重视专业能力、主动性和担当；
- 扁平结构，您的声音真正被重视，官僚作风不复存在；
- 有竞争力的薪资、补充医疗保险、报销培训和会议费用——我们支持您的职业成长；
- 已认证的 IT 企业资质和透明的工作条件。

**工作形式：** 混合办公或全坐班（可商议），萨维奥洛夫斯卡娅（Савёловская）地铁站，Factoria 商务中心。

如果您感兴趣，请将英文简历发送至 [hr@wbsrv.ru](mailto:hr@wbsrv.ru)。

#### NOTE
我们仅接受英文简历，请用英文提交您的简历。


# https://cn.angie.software/angie/docs/configuration/acme.md

<!-- review: finished -->

<a id="acme-config"></a>

# ACME 配置

Angie 中的 [ACME](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 模块使用 [ACME 协议](https://datatracker.ietf.org/doc/html/rfc8555) 实现自动证书获取。ACME 协议支持
多种域名验证方法(也称为"验证");本模块实现了 [HTTP 验证](#acme-config-http)、
[DNS 验证](#acme-config-dns)、[ALPN 验证](#acme-config-alpn) 以及通过自定义外部服务进行的 [基于钩子的验证](#acme-config-hooks)。

<a id="configuration-steps"></a>

## 配置步骤

在配置中启用证书请求的常规步骤:

- **配置 ACME 客户端**:在 `http` 块中使用 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令,
  指定唯一的客户端名称和其他参数。可以配置多个 ACME 客户端。
- **指定请求证书的域名**:将为所有 `server` 块中 [server_name](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name)
  指令列出的所有域名颁发单个证书,这些块使用指向同一 ACME 客户端的 [acme](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 指令。
- **设置请求处理和 ACME 回调**:这是验证域名所有权所必需的。设置取决于所选的域名验证方法:

  | 方法                           | 用户要求                                                                                                                                                                                                                  | 多域名   | 通配符域名   |
  |------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------|---------|
  | [HTTP 验证](#acme-config-http) | 在 Angie 服务器上开放端口 80(或 [acme_http_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-http-port) 中指定的端口)<br/>以接受传入连接。                                                             | ✔     |         |
  | [DNS 验证](#acme-config-dns)   | 在 Angie 服务器上开放端口 53(或 [acme_dns_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-dns-port) 中指定的端口)<br/>以接受传入连接。<br/><br/>为 `_acme-challenge.` 子域设置 NS 记录,<br/>指向您的 Angie 服务器。 | ✔     | ✔       |
  | [ALPN 验证](#acme-config-alpn) | 在 Angie 服务器上开放端口 443(或您的服务器使用的 TLS 端口)<br/>以接受传入连接。                                                                                                                                                                   | ✔     |         |
  | [钩子验证](#acme-config-hooks)   | 创建一个外部服务(脚本或应用程序),<br/>可以根据 Angie 的请求更新 DNS 记录<br/>或通过 Web 服务器提供特殊响应。                                                                                                                                                 | ✔     | ✔       |
- **使用获取的证书和密钥配置 SSL**:该模块将证书和密钥作为 [嵌入式变量](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme-variables)
  提供,可在 [配置](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile) 中使用以填充 [ssl_certificate](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-certificate) 和 [ssl_certificate_key](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-certificate-key)。

  有关 SSL 设置说明,请参阅 [SSL配置](https://cn.angie.software//angie/docs/configuration/ssl.md#ssl-config)。

<a id="acme-config-details"></a>

## 实现细节

客户端密钥和证书以 [PEM 编码](https://datatracker.ietf.org/doc/html/rfc7468) 存储在由 `--http-acme-client-path`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 指定的目录的子目录中:

```console
$ ls /var/lib/angie/acme/example/

  account.key  certificate.pem  private.key
```

ACME 客户端需要在 CA 服务器上拥有一个账户。为了创建和管理此账户,
客户端使用私钥(`account.key`)。如果不存在密钥,则在启动时生成。
然后客户端使用此密钥向服务器注册账户。

#### NOTE
如果您已经拥有账户密钥,请在启动前将其放置在客户端的子目录中以重用该账户。
或者,使用 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 中的 `account_key` 参数指定密钥文件。

ACME 客户端还使用单独的密钥(`private.key`)用于证书签名请求(CSR)。
如果需要,此证书密钥会在启动时自动创建。

启动时,如果证书不存在,客户端会请求证书,签名并向 CA 服务器发送包含其管理的所有域名的 CSR。
服务器使用 [HTTP](#acme-config-http) 或 [DNS 验证](#acme-config-dns) 验证域名所有权,
并颁发证书,客户端将其保存在本地(`certificate.pem`)。

如前所述,单个证书涵盖同一 ACME 客户端管理的所有域名,可能产生多域名证书。
证书涵盖的所有名称列表可以在获取的证书的 Subject Alternative Name (SAN)部分中找到。
要从命令行检查:

```console
$ openssl x509 -in certificate.pem -noout -text | grep -A5 "Subject Alternative Name"
```

当证书即将过期或域名列表发生变化时,客户端会签名并向 CA 服务器发送另一个 CSR。
服务器重新验证所有权并颁发新证书,客户端将其安装在本地,替换之前的证书。

在 [配置](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile) 中,获取的证书及其对应的密钥可通过前缀变量
[$acme_cert_<名称>](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-cert-name) 和 [$acme_cert_key_<名称>](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-cert-key-name) 获得。它们的值是相应文件的内容,
应与 [ssl_certificate](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-certificate) 和 [ssl_certificate_key](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-certificate-key) 指令一起使用:

```nginx
server {

    listen 443 ssl;

    server_name example.com www.example.com;
    acme example;

    ssl_certificate $acme_cert_example;
    ssl_certificate_key $acme_cert_key_example;
}
```

<a id="acme-config-domain-collection"></a>

## 域名收集与证书使用

[acme](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 指令仅用于收集证书请求的域名,
并不控制证书可在何处使用:
任何 `server` 块都可以通过
[$acme_cert_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-cert-name) 变量
引用获取的证书,
无论该块是否包含 `acme` 指令。

例如,如果您有一个已涵盖所有子域名的通配符 `server` 块,
那么针对特定子域名的额外 `server` 块
不需要 `acme` 指令:

```nginx
http {

    resolver 127.0.0.53;

    acme_client example https://acme-v02.api.letsencrypt.org/directory
        challenge=dns;

    # This block lists the domains for the certificate request
    server {

        listen 443 ssl;

        server_name example.com *.example.com;
        acme example;

        ssl_certificate $acme_cert_example;
        ssl_certificate_key $acme_cert_key_example;
    }

    # This block uses the same certificate but does not
    # add its server_name to the certificate request
    server {

        listen 443 ssl;

        server_name app.example.com;

        ssl_certificate $acme_cert_example;
        ssl_certificate_key $acme_cert_key_example;
    }
}
```

<a id="acme-config-explicit-domains"></a>

### 显式域名列表

为了精确控制证书中的域名集合,
而不依赖于从所有 `server` 块自动收集,
可以创建一个专用的 `server` 块,
其中仅包含 [server_name](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name) 和 [acme](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 指令。
为防止此块处理实际流量,
可以将其绑定到 Unix 域套接字:

```nginx
# Dedicated block that defines the certificate's domain list
server {

    listen unix:/tmp/acme_example.sock;

    server_name example.com www.example.com;
    acme example;
}
```

其他 `server` 块随后可通过
[$acme_cert_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-cert-name) 变量
使用该证书,而不会影响请求的域名。

<a id="acme-config-http"></a>

## HTTP 验证

验证是自动处理的。该过程涉及 ACME 服务器在收到请求后,\`通过 HTTP 检索特殊令牌文件
<[https://datatracker.ietf.org/doc/html/rfc8555#section-8.3](https://datatracker.ietf.org/doc/html/rfc8555#section-8.3)>\`_,
从客户端地址 `/.well-known/acme-challenge/<TOKEN>` 获取。我们的 ACME 模块
会自动跟踪和处理此类请求。当收到包含正确内容的预期响应时,ACME 服务器确认该域名属于客户端。

<a id="configuration-example-1-1-1"></a>

### 配置示例

在此示例中,名为 `example` 的 ACME 客户端管理 `example.com` 和
`www.example.com` 的证书(注意 HTTP 验证不支持通配符证书):

```nginx
http {

    resolver 127.0.0.53; # 'acme_client' 指令所需

    acme_client example https://acme-v02.api.letsencrypt.org/directory;

    server {

        listen 80; # 如果没有服务器监听 HTTP 挑战端口,则可选
                   # (参见 'acme_http_port' 指令)

        listen 443 ssl;

        server_name example.com www.example.com;
        acme example;

        ssl_certificate $acme_cert_example;
        ssl_certificate_key $acme_cert_key_example;
    }
}
```

如前所述,必须开放端口 80 以处理 HTTP ACME 调用。
如果没有配置服务器监听 HTTP 挑战端口,
该模块会在端口 80(或 [acme_http_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-http-port) 中设置的端口)上创建专用监听器。不需要单独的 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 块。

<a id="acme-config-dns"></a>

## DNS 验证

验证是自动处理的。在处理证书请求时,ACME 服务器会对被验证域名的 `_acme-challenge.` 子域执行 [特殊的 DNS 查询](https://datatracker.ietf.org/doc/html/rfc8555#section-8.4)。一旦收到预期的响应,ACME 服务器确认该域名属于客户端。

我们的 ACME 模块会自动跟踪和处理此类请求,前提是您的 DNS 记录已正确配置,将 Angie 服务器指定为 `_acme-challenge.` 子域的权威名称服务器。

#### NOTE
Angie 服务器必须能够通过互联网在
UDP 53 端口(或 [acme_dns_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-dns-port) 中指定的端口)上访问。
如果服务器位于防火墙后,
请确保该端口对入站连接开放。

例如,要使用 IP 地址为 `93.184.215.14` 的 Angie 服务器验证域名 `example.com`,您的域名 DNS 配置应包含以下记录:

```none
_acme-challenge.example.com. 60    IN      NS       ns.example.com.
             ns.example.com. 60    IN       A       93.184.215.14
```

此配置将 `_acme-challenge.example.com` 的 DNS 解析委托给 `ns.example.com`,并通过将 `ns.example.com` 映射到 IP 地址(`93.184.215.14`)来确保其可访问。

#### WARNING
NS 记录的传播可能需要几分钟到 48 小时不等,具体取决于 TTL 和 DNS 提供商。建议在请求证书之前验证配置是否正确。

要验证 DNS 是否配置正确,您可以使用以下命令:

```console
$ dig NS _acme-challenge.example.com +short  # 检查 _acme-challenge 子域的 NS 记录

  ns.example.com.

$ dig A ns.example.com +short  # 检查名称服务器的 A 记录

  93.184.215.14

$ nc -zv 93.184.215.14 53  # 检查 DNS 服务器在端口 53 上的可访问性
```

此方法允许请求通配符证书,例如,在 Subject Alternative Name (SAN)部分包含 `*.example.com` 条目的证书。要明确请求子域的证书,例如 `www.example.com`,您必须使用上述方法单独验证该子域。

#### WARNING
此场景的适用性在很大程度上取决于您的 DNS 提供商提供的功能;某些提供商不允许此类配置。

<a id="configuration-example-1-1"></a>

### 配置示例

总体而言,配置与上一节中的示例类似。不需要 HTTP 特定的设置;只需为 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令设置 `challenge=dns` 即可。

在此示例中,名为 `example` 的 ACME 客户端管理 `example.com` 和 `*.example.com` 的证书:

```nginx
http {

    resolver 127.0.0.53;

    acme_client example https://acme-v02.api.letsencrypt.org/directory
        challenge=dns;

    server {

        server_name example.com *.example.com;
        acme example;

        ssl_certificate $acme_cert_example;
        ssl_certificate_key $acme_cert_key_example;
    }
}
```

<a id="acme-config-alpn"></a>

## ALPN 验证

验证是自动处理的。ACME 服务器使用 TLS 连接并通过 ALPN 请求 `acme-tls/1` 协议。该模块为验证请求提供临时证书。

要启用此方法,请在 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令中配置 `challenge=alpn`,并确保您的 TLS 监听器在端口 443(或用于 TLS 的端口)上可访问。

<a id="acme-config-hooks"></a>

## 基于钩子的验证

与之前的方法不同,此验证需要额外的工作。ACME 服务器执行标准的 [HTTP 验证](#acme-config-http) 或 [DNS 验证](#acme-config-dns),但它不是直接与 Angie 服务器交互,而是通过钩子调用([acme_hook](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-hook))与 Angie 服务器管理的外部服务通信。该服务配置一个单独的 DNS 或 HTTP 服务器,ACME 服务器向其发送请求。

一旦 ACME 服务器从配置的 DNS 或 HTTP 服务器收到预期的响应,它就会确认域名所有权。

当证书签发或续订需要进行域名验证时,
Angie 会向包含 [acme_hook](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-hook) 指令的命名 `location`
生成一个内部请求。
该请求的处理方式完全取决于同一 `location`
中配置的其他指令。

通用模式如下:

1. 创建一个带有 [acme_hook](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-hook) 指令的命名 `location`。
2. 在同一 `location` 中,
   使用适合您环境的模块配置请求处理程序:
   FastCGI 使用 [fastcgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-pass),
   HTTP 使用 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass),
   CGI 脚本使用 `cgi`,等等。
3. 使用处理程序支持的机制,
   将 ACME [变量](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme-variables) 传递给处理程序,
   例如 FastCGI 使用 `fastcgi_param`,
   CGI 使用 `cgi_set_var`。

处理程序必须返回 `2xx` 状态码,
可以通过 `Status` 头发送。
任何其他状态码都被视为错误,
证书续订将停止。
处理程序的输出将被忽略。

<a id="acme-config-hooks-minimal-configuration"></a>

### 最小配置

无论使用哪种处理程序,
钩子 `location` 都遵循以下结构:

```nginx
location @acme_hook {

    acme_hook example;

    # Handler directive (fastcgi_pass, proxy_pass, cgi on, ...)
    # Pass ACME variables using the handler's mechanism:
    #   ACME_HOOK       — $acme_hook_name ("add" or "remove")
    #   ACME_CHALLENGE  — $acme_hook_challenge ("dns" or "http")
    #   ACME_DOMAIN     — $acme_hook_domain
    #   ACME_TOKEN      — $acme_hook_token
    #   ACME_KEYAUTH    — $acme_hook_keyauth
}
```

对于 DNS 验证,处理程序必须使用 `ACME_HOOK`
来确定操作:
当其值为 `add` 时,
为 `_acme-challenge.*ACME_DOMAIN*` 创建一条
值为 `ACME_KEYAUTH` 的 TXT 记录;
当其值为 `remove` 时,删除该记录。

<a id="configuration-example-1"></a>

### FastCGI 示例

在此示例中,:ref:acme_client 指令通过 `challenge=dns` 参数
将 ACME 客户端 `example` 配置为使用 DNS 验证。

`server` 块适用于 `example.com` 的所有子域(例如 `*.example.com`),
并通过 [acme](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 指令使用 ACME 客户端 `example` 来管理证书。

一个命名的 `location` 块负责处理钩子调用。
[acme_hook](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-hook) 指令将其与 ACME 客户端 `example` 关联起来。
钩子请求通过 [fastcgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-pass)
发送到运行在 9000 端口上的本地 FastCGI 服务器。
`fastcgi_param` 指令将 ACME 变量
传递给外部服务。

```nginx
acme_client example https://acme-v02.api.letsencrypt.org/directory
    challenge=dns;

server {

    listen 80;

    server_name *.example.com;

    acme example;

    ssl_certificate $acme_cert_example;
    ssl_certificate_key $acme_cert_key_example;

    location @acme_hook_location {

        acme_hook example;

        fastcgi_pass localhost:9000;

        fastcgi_param ACME_CLIENT $acme_hook_client;
        fastcgi_param ACME_HOOK $acme_hook_name;
        fastcgi_param ACME_CHALLENGE $acme_hook_challenge;
        fastcgi_param ACME_DOMAIN $acme_hook_domain;
        fastcgi_param ACME_TOKEN $acme_hook_token;
        fastcgi_param ACME_KEYAUTH $acme_hook_keyauth;

        include fastcgi.conf;
    }
}
```

以下 Perl 脚本演示了相应的外部 FastCGI 服务:

```perl
#!/usr/bin/perl

use strict; use warnings;

use FCGI;

my $socket = FCGI::OpenSocket(":9000", 5);
my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, $socket);

while ($request->Accept() >= 0) {
    print "\r\n";

    my $client =    $ENV{ACME_CLIENT};
    my $hook =      $ENV{ACME_HOOK};
    my $challenge = $ENV{ACME_CHALLENGE};
    my $domain =    $ENV{ACME_DOMAIN};
    my $token =     $ENV{ACME_TOKEN};
    my $keyauth =   $ENV{ACME_KEYAUTH};

    if ($hook eq 'add') {

        DNS_set_TXT_record("_acme-challenge.$domain.", $keyauth);

    } elsif ($hook eq 'remove') {

        DNS_clear_TXT_record("_acme-challenge.$domain.");
    }
};

FCGI::CloseSocket($socket);
```

这里,:samp:DNS_set_TXT_record() 和 `DNS_clear_TXT_record()` 是假定在外部 DNS 服务器的配置中添加和删除 TXT 记录的函数,ACME 服务器会查询该 DNS 服务器。这些记录必须包含 Angie 服务器提供的数据,以允许外部 DNS 服务器成功通过验证,类似于 [DNS 验证](#acme-config-dns) 中描述的过程。此类函数的实现细节超出了本指南的范围;例如,参数也可以通过请求 URI 传递:

```nginx
# ...

location @acme_hook_location {

    acme_hook example uri=/acme_hook/$acme_hook_name?domain=$acme_hook_domain&key=$acme_hook_keyauth;

    fastcgi_pass localhost:9000;

    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param ACME_CLIENT $acme_hook_client;
    fastcgi_param ACME_CHALLENGE $acme_hook_challenge;
    fastcgi_param ACME_TOKEN $acme_hook_token;

    include fastcgi.conf;
}
```

### PHP-FPM 示例

另一个使用 PHP-FPM 的示例:

```nginx
location @acme_hook_location {

    acme_hook example;
    root /var/www/dns;
    fastcgi_pass unix:/run/php-fpm/php-dns.sock;
    fastcgi_index hook.php;
    fastcgi_param SCRIPT_FILENAME /var/www/dns/hook.php;
    include fastcgi_params;

    fastcgi_param ACME_CLIENT $acme_hook_client;
    fastcgi_param ACME_HOOK $acme_hook_name;
    fastcgi_param ACME_CHALLENGE $acme_hook_challenge;
    fastcgi_param ACME_DOMAIN $acme_hook_domain;
    fastcgi_param ACME_TOKEN $acme_hook_token;
    fastcgi_param ACME_KEYAUTH $acme_hook_keyauth;
}
```

```ini
[dns]
listen = /run/php-fpm/php-dns.sock
listen.mode = 0666
user = angie
group = angie
chdir = /var/www/dns
# ...
```

传递的参数可以在 PHP 中通过 `$_SERVER['...']` 访问。

<a id="acme-config-stream"></a>

## Stream 模块中的 ACME

[ACME](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_acme.md#stream-acme) stream 模块可为 TCP 流量启用自动化的
证书签发和使用。
为使其正常工作,您必须首先配置其 HTTP 对应部分:
ACME 客户端必须在 `http` 上下文中声明,
并且 `stream` 块本身必须放置在配置文件中 `http` 块\*之后\*。

<a id="configuration-example"></a>

### 配置示例

默认情况下,使用 HTTP 验证模式来获取证书。
如 [HTTP 验证](#acme-config-http) 部分所述,
这需要一个监听 80 端口的 HTTP 服务器:

```nginx
# HTTP 部分
http {

    resolver 127.0.0.53;

    # 用于 stream 部分的 ACME 客户端
    acme_client example https://acme-v02.api.letsencrypt.org/directory;

    # 用于 HTTP 验证的服务器
    server {

        listen 80;
        return 444;
    }
}

# Stream 部分
stream {

    server {

        listen 12345 ssl;
        proxy_pass backend_upstream;

        ssl_certificate $acme_cert_example;
        ssl_certificate_key $acme_cert_key_example;

        server_name example.com www.example.com;
        acme example; # 引用 HTTP 部分中定义的 ACME 客户端
    }

    upstream backend_upstream {

        server 127.0.0.1:54321;
    }
}
```

您也可以使用 DNS 验证,
方法是在 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令中配置 `challenge=dns`;
在这种情况下,将不需要该服务器。

<a id="acme-config-certbot"></a>

## 从 **certbot** 迁移

如果您之前在 [从 nginx 迁移到 Angie](https://cn.angie.software//angie/docs/configuration/migration.md#migration) 之前
使用 [certbot](https://certbot.eff.org/)
从 Let's Encrypt 获取和续订 SSL 证书,
请按照以下步骤过渡到使用我们的 ACME 模块。

假设您按如下方式配置了证书:

```console
$ sudo certbot --nginx -d example.com -d www.example.com
```

此命令自动创建的配置
通常位于 `/etc/nginx/sites-available/example.conf`,
看起来类似这样:

```nginx
server {

    listen 80;
    server_name example.com www.example.com;
    return 301 https://$host$request_uri;
}

server {

    listen 443 ssl;
    server_name example.com www.example.com;

    root /var/www/example;
    index index.html;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
```

在上面的示例中,需要修改高亮显示的行。
根据您的情况和偏好,使用 ACME 模块配置
[HTTP 验证](#acme-config-http)
或 [DNS 验证](#acme-config-dns)。

最终的 [Angie 配置](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)
可能如下所示:

```nginx
http {

    resolver 127.0.0.53;

    acme_client example https://acme-v02.api.letsencrypt.org/directory;

    server {

        listen 80;
        server_name example.com www.example.com;
        return 301 https://$host$request_uri;
    }

    server {
        listen 443 ssl;
        server_name example.com www.example.com;

        root /var/www/example;
        index index.html;

        acme                 example;

        ssl_certificate      $acme_cert_example;
        ssl_certificate_key  $acme_cert_key_example;
    }
}
```

请记住在 [更改后重新加载配置](https://cn.angie.software//angie/docs/configuration/runtime.md#control-config-change):

```console
$ sudo kill -HUP $(cat /run/angie.pid)
```

一旦您验证了此配置可以正常工作,
您可以删除 **certbot** 证书
并禁用或从服务器上完全移除 certbot
(如果它不再在其他地方使用),
例如:

```console
$ sudo rm -rf /etc/letsencrypt

$ sudo systemctl stop certbot.timer
$ sudo systemctl disable certbot.timer
$ # -- 或 --
$ sudo rm /etc/cron.d/certbot

$ sudo apt remove certbot
$ # -- 或 --
$ sudo dnf remove certbot
```


# https://cn.angie.software/adc.md

<a id="angie-adc-page"></a>

# Angie ADC

Angie ADC 是一款应用交付控制器级别的软件系统，
      集成了负载均衡、DNS 负载均衡，并支持通过外部和内部网关路由协议进行网络请求的路由和均衡。

Angie ADC 是一款综合性的负载均衡和网络流量管理软件，
可帮助构建灵活、高性能和安全的基础设施。
主要特性：

- 支持 L4-L7 层负载均衡。
- 支持 L2/L3 协议和技术。
- 全球 DNS 负载均衡（GSLB）。
- 后端服务器健康检查。
- 客户端会话保持。
- TLS 处理与加速。
- 高可用性解决方案。
- 已列入俄罗斯软件注册。
- 提供 Web 界面、命令行（CLI）和 API，便于集成。
- 兼容俄罗斯操作系统。
- 技术支持。

**Angie ADC |adc_pdf_version|** 已于 

```
|adc_release_date|
```

 发布。
新版本计划每月发布，并及时提供安全修复与改进。

## 为什么选择 Angie ADC？

支持多种流量分配算法（包括动态：反馈、最短时间、最小带宽、最少包数）。

支持应用层（L7）和传输层（L4）负载均衡。

支持会话管理及第三方存储。

可通过 API 基于应用信息进行负载均衡。

根据应用服务器状态和数据中心性能管理 DNS 响应。

支持地理分布式流量调度。

支持主流协议（BGP、OSPF、VRRP、RIP、PBR、BFD）。

优化入站和出站流量路由。

提供 Angie ADC 控制台用于监控和配置。

命令行（CLI）支持所有变更日志记录。

支持 BGP、OSPF、VRRP，实现主备切换。

可在单数据中心或多数据中心部署高可用方案。

DNS 和负载均衡层灵活配置，保障故障时可靠运行。

基于可用性和性能指标进行服务器状态检测。

支持 ACME 自动证书续签，包括 GOST 证书。

完全兼容本地加密模块和 GOST TLS。

提供 API，便于自动化和 CI/CD 集成。

支持 REST API 和 SNMP，便于采集指标和管理。

以虚拟设备或硬件负载均衡器形式交付。

支持高可用部署场景，包括 Anycast 和多数据中心架构。

## 技术支持

Angie ADC 产品提供 24/7 全天候技术支持，确保您随时获得帮助。

## 配套文档

Angie ADC 

```
|adc_pdf_version|
```

 PDF 文档（俄语）：

- [`Angie ADC 安装指南`](https://cn.angie.software//adc/Angie_ADC_|adc_pdf_version|_installation_guide.pdf)
- [`Angie ADC 功能说明`](https://cn.angie.software//adc/Angie_ADC_|adc_pdf_version|_functional_description.pdf)
- [`Angie ADC 运维手册`](https://cn.angie.software//adc/Angie_ADC_|adc_pdf_version|_operating_guide.pdf)

## 购买许可

本软件产品以商业许可方式分发。
如需了解产品价格、购买方式及许可协议，
请发送邮件至 [info@wbsrv.ru](mailto:info@wbsrv.ru) 咨询。


# https://cn.angie.software/news/all-news.md

# 所有新闻

## [Angie 和 Angie PRO 更新至 1.11.6 版本](https://cn.angie.software//news/releases/angie-1-11-6.md)

*25.05.2026*

Angie 和 Angie PRO 1.11.6 修复版本已发布，移植了前一日在 nginx 中发现的
[rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 指令漏洞 CVE-2026-9256 的修复。

## [Angie 和 Angie PRO 更新至 1.11.5 版本](https://cn.angie.software//news/releases/angie-1-11-5.md)

*15.05.2026*

Angie 和 Angie PRO 1.11.5 修复版本已发布，移植了 nginx 中发现的五个漏洞的
修复。这些漏洞涉及 `rewrite`、`ssl_ocsp`、`scgi_pass`、
`uwsgi_pass` 和 `charset_map` 指令的工作，以及 `HTTP/3`
协议请求的处理。

## [Angie 和 Angie PRO 更新至 1.11.0 版本](https://cn.angie.software//news/releases/angie-1-11-0.md)

*24.12.2025*

Angie 和 Angie PRO 1.11.0 已发布 — 这是该项目历史上规模最大的更新。
此版本引入了 Metrics 模块，修复了 `HTTP/3` 可靠性问题，扩展了
ACME 和图像过滤器功能；Angie PRO 改进了具有外部存储的粘性会话，并在
API 中添加了许可证详情。

## [Angie 和 Angie PRO 更新至 1.10.3 版本](https://cn.angie.software//news/releases/angie-1-10-3.md)

*13.11.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 发布了修复版本 1.10.3。
从 nginx 1.29 移植了邮件 SMTP 模块的一个潜在漏洞修复。修复了 ACME 配置
错误，并解决了在 client 块中使用变量访问传入连接时的潜在崩溃问题。
PRO 版本还修复了 UDP 健康检查和 Docker 模块服务器的相关问题。

## [Angie 和 Angie PRO 更新至 1.10.2 版本](https://cn.angie.software//news/releases/angie-1-10-2.md)

*22.08.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 发布了修复版本 1.10.2。
这些版本修复了在 1.10 版本中引入 client 块实现时出现的问题，该问题
可能会干扰 stream 模块中 ACME、Docker 和 sticky remote 模块的功能。
同时修复了通过 Docker API 更新代理服务器组的问题，并添加了两个新的
第三方模块。

## [Angie 和 Angie PRO 更新至 1.10.1 版本](https://cn.angie.software//news/releases/angie-1-10-1.md)

*17.07.2025*

发布了 Angie 和 Angie PRO 的 1.10.1 修复版本。此次更新修复了
reuseport 和 HTTP/3 的相关问题，改进了 client 配置块的逻辑，
增加了对新版本 GCC 的兼容性，并解决了 Angie PRO 中使用特殊变量时的崩溃问题。

## [Angie 和 Angie PRO 更新至 1.10.0 版本](https://cn.angie.software//news/releases/angie-1-10-0.md)

*04.07.2025*

开源 Web 服务器 Angie 及其商业版 Angie PRO 已发布 1.10.0 版本。
主要更新包括自动代理 Docker 容器、改进流模块中的 ACME 支持、
支持多路径 TCP 和带 CUBIC 的 QUIC，以及集群模式下 Angie PRO 的新功能。

## [Angie 和 Angie PRO 更新至版本 1.9.1](https://cn.angie.software//news/releases/angie-1-9-1.md)

*29.05.2025*

开源 Web 服务器 Angie 及其商业版 Angie PRO 发布了 1.9.1 版本。
本次更新重点提升了对 HTTP/3 的支持，并改进了对非标准 ACME 配置的处理，
同时修复了流模块中的一些问题。

## [Angie 和 Angie PRO 更新至 1.9.0 版本](https://cn.angie.software//news/releases/angie-1-9-0.md)

*11.04.2025*

开源网页服务器 Angie 及其商业版本 Angie PRO 已发布 1.9.0 版本。
主要更新包括将缓存索引保存到磁盘以加快重启速度、
在流模块中支持 TLS 1.3 Early Data，以及 Angie PRO 中 HTTP 负载均衡器的新功能。

## [Angie 和 Angie PRO 发布了 1.8.3 版本；Console Light 更新至 1.7.0 版本](https://cn.angie.software//news/releases/angie-1-8-3.md)

*02.04.2025*

开源版 Angie 网络服务器及其商业版 Angie PRO 发布了 1.8.3 版本，修复了统计功能；
Console Light 更新至 1.7.0 版本。

## [Angie 和 Angie PRO 发布 1.8.2 更新](https://cn.angie.software//news/releases/angie-1-8-2.md)

*13.02.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 的 1.8.2 版本包含重要的安全修复，以及其他多项改进。

## [Angie 和 Angie PRO 升级至 1.8.1 版本](https://cn.angie.software//news/releases/angie-1-8-1.md)

*28.12.2024*

开源网络服务器 Angie 和其商业版本 Angie PRO 发布了 1.8.1 版本。
此更新修复了服务器统计区域的问题，改进了 ACME 模块对通配符证书的支持，并包含 HTTP/3 的重要修复。

## [Angie 和 Angie PRO 更新至版本 1.8.0](https://cn.angie.software//news/releases/angie-1-8-0.md)

*19.12.2024*

Angie 网络服务器及其商业版本 Angie PRO 的 1.8.0 版本已发布。此更新包括 ACME 模块的新功能、对 WebAssembly 的支持，以及 API 和功能的改进。

## [Angie 启用 WebAssembly 支持](https://cn.angie.software//news/articles/wasm.md)

*29.11.2024*

此次更新使得可以构建 WASM 模块，以便 Angie 加载并在服务器配置中使用它们。

## [Angie 和 Angie PRO 收到更新 1.7.0](https://cn.angie.software//news/releases/angie-i-angie-pro-poluchili-obnovlenie-1-7-0.md)

*20.09.2024*

新版本的开源网页服务器 Angie 1.7.0 和商业版 Angie PRO 1.7.0 现已推出，提供显著的改进和新功能。

## [Rubytech集团与俄罗斯Web服务器开发商Angie整合资源与专业技术，共同推进产品开发](https://cn.angie.software//news/gruppa-rubytech-i-angie-objedinaiut-resursi.md)

*22.08.2024*

俄罗斯高负载系统软件开发商Angie（Web Server有限责任公司）已加入Rubytech集团。

![Alternative text](../../_images/news/gruppa-rubytech-i-angie-objedinaiut-resursi.webp)

## [Angie 和 Angie PRO 发布 1.6.1 更新](https://cn.angie.software//news/releases/angie-i-angie-pro-poluchili-obnovlenie-1.6.1.md)

*08.08.2024*

Web Server公司发布了开源网络服务器 Angie 1.6.1 和其商业版本 Angie PRO 1.6.1。

## [SolidWall Web应用程序防护解决方案兼容Angie PRO](https://cn.angie.software//news/integrations/reshenie-po-zaschite-web-prilojenii-solidwall-sovmestimo-s-angie-pro.md)

*15.07.2024*

与Angie PRO的集成增强了SolidWall WAF的功能，例如，实现了对HTTP/3协议的支持。

## [Angie和Angie PRO Web服务器发布更新](https://cn.angie.software//news/releases/vishli-obnovlenia-web-servera-angie-i-angie-pro.md)

*28.06.2024*

新版本显著扩展了负载均衡功能，并继续开发ACME模块。

## [Web服务器Angie新增ACME支持](https://cn.angie.software//news/releases/veb-server-angie-poluchil-podderzhku-acme.md)

*27.03.2024*

新增了http_acme模块，实现了对ACME(自动化证书管理环境)协议的支持，简化了网站数字证书的工作流程，
无需使用像EFF Certbot这样的第三方解决方案。

## [国产云环境Kubernetes解决方案Angie Ingress Controller (ANIC)发布更新](https://cn.angie.software//news/releases/vishli-obnovleniya-otechestvennogo-reshenia-ANIC.md)

*02.03.2024*

Web Server公司发布了用于Kubernetes容器化应用流量管理的俄罗斯解决方案Angie Ingress Controller (ANIC) 0.3.0版本。

## [Angie Web服务器及其专有版本Angie PRO发布更新](https://cn.angie.software//news/releases/vishli-obnovleniya-veb-servera-angie-i-ego-proprietarnoi-versii-angie-pro.md)

*15.02.2024*

Web Server公司发布了俄罗斯开源Web服务器Angie 1.4.1及其商业版本Angie PRO 1.4.1。

## [X-Config负责监控Angie PRO配置的安全性](https://cn.angie.software//news/integrations/bezopastnost-configuracii-angie-pro-kontroliruet-x-config.md)

*08.02.2024*

Angie PRO的安全配置标准将使客户能够自动监控Web服务器设置，接收按优先级排序的漏洞识别报告，并提供修复建议。

## [Angie Ingress Controller (ANIC) 已加入国产软件名录](https://cn.angie.software//news/integrations/ingress-controller-anic-voshel-v-reestr-otechestvennogo-po.md)

*12.01.2024*

大家好！我们用于 Kubernetes 云环境的解决方案 Angie Ingress Controller (ANIC) 已被添加到 [国产软件名录](https://reestr.digital.gov.ru/reestr/2057228/)。

## [俄罗斯网络服务器Angie PRO更新发布](https://cn.angie.software//news/releases/vishli-obnovleniya-rossiiskogo-veb-servera-Angie-Pro.md)

*21.12.2023*

Web Server公司宣布发布新版本的俄罗斯网络服务器Angie PRO 1.4.0。

## [俄罗斯开源Web服务器Angie发布更新](https://cn.angie.software//news/releases/vishli-obnovleniya-rossiiskogo-veb-servera-s-otkrytym-iskhodnym-kodom-Angie.md)

*12.12.2023*

"Web Server"公司发布了俄罗斯开源Web服务器Angie 1.4.0新版本。

## [Angie PRO 获得 ROSA Chrome 12 Server 操作系统认证](https://cn.angie.software//news/integrations/angie-pro-sertifitsirovan-dlya-os-rosa-chrome-12-server.md)

*01.12.2023*

俄罗斯网络服务器开发商Web Server与 ROSA IT 研究中心已确认 Angie PRO 网络服务器与 ROSA Chrome 12 Server 操作系统的兼容性，这一点已通过双方签发的证书得到证实，凸显了产品的高度兼容性和可靠性。

## [Angie和Angie PRO发布1.3.2更新](https://cn.angie.software//news/releases/angie-i-angie-pro-poluchili-obnovlenie-1.3.2.md)

*24.11.2023*

Web Server公司发布了Web服务器Angie及其商业版本Angie PRO的更新。

## [Angie新增功能助力更好的Web服务器监控](https://cn.angie.software//news/articles/novoe-v-angie-dlya-luchshego-monitoringa.md)

*17.11.2023*

2023年9月，我们通过添加Angie Console Light为Angie web服务器引入了新的监控组织方式。

## [Angie和Angie PRO针对DoS攻击的防护得到增强](https://cn.angie.software//news/releases/angie-i-angie-pro-obnovleni-dlya-uluchsheniya-zashchity-ot-dos-ataki.md)

*18.10.2023*

Web Server公司宣布发布Angie和Angie PRO的1.3.1版本。

## [Web服务器Angie PRO发布1.3.0更新](https://cn.angie.software//news/releases/veb-server-angie-pro-poluchil-obnovlenie-1.3.0.md)

*03.10.2023*

"Web Server"公司宣布发布俄罗斯Web服务器Angie PRO 1.3.0新版本。

## [开源代码的Web服务器Angie更新至版本1.3.0](https://cn.angie.software//news/releases/veb-server-angie-s-otkritim-ishodnim-kodom-1.3.0.md)

*19.09.2023*

公司“Web服务器”宣布发布俄罗斯开源Web服务器Angie 1.3.0的新版本。

## [WebmonitorEx平台与俄罗斯网络服务器Angie PRO实现兼容](https://cn.angie.software//news/integrations/platforma-vebmonitoreks-sovmestima-s-rossijskim-veb-serverom-Angie-Pro.md)

*06.09.2023*

WebmonitorEx已确保其平台与俄罗斯网络服务器Angie PRO的兼容性。这为企业提供了更高的可靠性和安全性，以防御网络威胁。

## [Web服务器Angie PRO发布1.2.0更新](https://cn.angie.software//news/releases/veb-server-angie-pro-poluchil-obnovlenie-1.2.0.md)

*19.08.2023*

"Web Server"公司宣布发布其俄罗斯Web服务器Angie PRO 1.2.0新版本。

## [Web Server公司推出Angie入口控制器](https://cn.angie.software//news/releases/kompaniya-veb-server-predstavila-angie-ingress-controller.md)

*29.06.2023*

Web Server公司推出了新产品Angie入口控制器（ANIC），可实现Kubernetes网络中的高效流量管理。

## [我们在发展并诚邀专业人才加入我们的团队](https://cn.angie.software//news/mi-rastem-i-priglashaem-na-rabotu-spetsialistov.md)

*16.06.2023*

我们在发展并诚邀专业人才加入我们的团队 - 招聘Angie网络服务器的C语言开发工程师和QA专家（Perl）

## [公司Web Server更新开源Web服务器Angie](https://cn.angie.software//news/releases/kompaniya-veb-server-obnovila-veb-server.md)

*08.06.2023*

俄罗斯开源Web服务器Angie 1.2.0新版本发布。

## [Angie Web服务器成为"俄罗斯版GitHub"的参与者](https://cn.angie.software//news/integrations/veb-server-angie-stal-uchastnikom-rossijskogo-GitHub.md)

*06.06.2023*

由前nginx团队开发的俄罗斯Web服务器Angie已成为创建俄罗斯代码仓库实验的参与者。俄罗斯数字发展部于2023年5月31日发布了相关命令。

## [Web服务器Angie PRO被列入国产软件名录](https://cn.angie.software//news/integrations/veb-server-angie-pro-voshel-v-reestr-otechestvennogo-PO.md)

*24.05.2023*

由前nginx团队开发的Web服务器Angie PRO已被列入国产软件名录。

## ["网络服务器"团队推出企业级产品 — Angie PRO](https://cn.angie.software//news/integrations/komanda-veb-servera-predstavlyaet-produkt-dlya-korporativnyh-zakazchikov-Angie-Pro.md)

*27.03.2023*

Angie已通过RED OS和Astra Linux特别版的兼容性认证。

## [俄罗斯将推出自主研发的Web服务器Angie](https://cn.angie.software//news/rossiya-poluchit-nezavisimii-veb-server.md)

*27.10.2022*

俄罗斯已开发出名为Angie的Web服务器，这将使俄罗斯企业能够替代国外解决方案并确保其基础设施的安全。

## [Angie正在招聘](https://cn.angie.software//news/angie-priglashaet-na-rabotu.md)

*28.05.2024*

大家好！我们想让全世界知道，我们也需要专业人士。

![替代文本](../../_images/news/angie-priglashaet-na-rabotu.jpeg)

## [我们的团队持续为全球开源事业做贡献！](https://cn.angie.software//news/nasha-komanda-prodolzhaet-delat-vklad-v-mirovoj-open-source.md)

*27.12.2023*

我们不仅在开发 Angie — nginx 的一个分支，还偶尔会为 nginx 本身做出贡献。

![Alternative text](../../_images/news/nasha-komanda-prodolzhaet-delat-vklad-v-mirovoj-open-source.jpeg)

## [备受尊敬的Ivan Panchenko的精彩访谈](https://cn.angie.software//news/interviews/prekrasnoe-intervyu-gluboko-uvazhaemogo-ivana-panchenko.md)

*07.02.2024*

从第25分钟开始，Ivan [谈论](https://www.youtube.com/watch?app=desktop&v=d9joPLRULeA) 我们的事情，
虽然他没有直接提到我们的名字。不过，这个一小时长的访谈中其他内容对所有从事开源项目的人来说都同样重要。

![Alternative text](../../_images/news/prekrasnoe-intervyu-gluboko-uvazhaemogo-ivana-panchenko.jpeg)

## [Angie Console - 我们正在开发新产品！](https://cn.angie.software//news/angie-console-mi-razrabativaem-novii-produkt.md)

*09.02.2024*

这是一个用于管理Web服务器集群的集中式系统，具有监控和动态配置功能。

![Alternative text](../../_images/news/angie-console-mi-razrabativaem-novii-produkt.jpg)

## [扩充第三方模块库：新增ModSecurity](https://cn.angie.software//news/integrations/popolnyaem-kollektsiyu-storonnih-modulei.md)

*04.12.2023*

大家好！在我们为即将发布的Angie和Angie PRO网络服务器更新版本进行工作的同时，我们也在持续扩充我们的第三方模块库。

![Alternative text](../../_images/news/popolnyaem-kollektsiyu-storonnih-modulei.webp)

## [Angie Web服务器一年后：新机遇与未来规划](https://cn.angie.software//news/events/veb-server-angie-god-spustya-novie-vozmozhnosti.md)

*27.11.2023*

Angie开发负责人Valentin Bartenyev将在HighLoad 2023大会上回顾项目第一年的发展历程。

![替代文本](../../_images/news/veb-server-angie-god-spustya-novie-vozmozhnosti.jpeg)

## [研发部负责人访谈](https://cn.angie.software//news/interviews/intervyu-s-rukovoditelem-otdela-razrabotki.md)

*16.11.2023*

大家好！今天我们在Habr上发布了一篇对研发部负责人Valentin Bartenyev的访谈。

![Alternative text](../../_images/news/intervyu-s-rukovoditelem-otdela-razrabotki.jpg)

## [获得Alt SP Server操作系统兼容性证书](https://cn.angie.software//news/integrations/poluchili-sertifikat-sovmestimosti-s-os-Alt-SP-Server.md)

*10.11.2023*

该证书不仅证实了测试的成功完成，也是我们产品对部分客户实施的必需文件。

![Alternative text](../../_images/news/poluchili-sertifikat-sovmestimosti-s-os-Alt-SP-Server.jpeg)

## [认识 Console Light](https://cn.angie.software//news/articles/vstrechaite-console-light.md)

*27.09.2023*

我们推出了一款用于实时活动监控的轻量级可视化控制台。

![Alternative text](../../_images/news/vstrechaite-console-light.jpg)

## [三周更新计划](https://cn.angie.software//news/tri-nedeli-obnovleniy.md)

*19.09.2023*

在接下来的三周(没错!)中，我们将以更新来庆祝并让用户感到欣喜。

![Alternative text](../../_images/news/tri-nedeli-obnovleniy.jpeg)

## [在俄罗斯推广开源](https://cn.angie.software//news/articles/populyarizuem-opensource-v-rossii.md)

*14.09.2023*

我们与科学出版物N+1的朋友们一起启动了一个在俄罗斯推广开源的特别项目。

![Alternative text](../../_images/news/populyarizuem-opensource-v-rossii.jpeg)

## [Angie与中国的经验](https://cn.angie.software//news/articles/opyt-raboti-angie-s-kitaem.md)

*04.09.2023*

当俄罗斯正在积极制定"本土"开源项目发展计划时，中国也在积极发展其自己的开源项目。

![Alternative text](../../_images/news/opyt-raboti-angie-s-kitaem.jpeg)

## [在贝加尔测试Angie PRO](https://cn.angie.software//news/integrations/testiruem-angie-pro-na-baikale.md)

*31.08.2023*

我们成功地在ARM处理器架构上编译、构建软件包并测试了我们的产品Angie/Angie PRO。

![Alternative text](../../_images/news/testiruem-angie-pro-na-baikale.jpeg)

## [Angie 与 nginx 的异同点](https://cn.angie.software//news/articles/shodstva-i-razlichiya-angie-i-nginx.md)

*25.08.2023*

Angie 项目和 Angie PRO 产品与其前身 nginx 及其商业版本 NGINX Plus 的关系。

![Angie vs. nginx](../../_images/news/shodstva-i-razlichiya-angie-i-nginx.webp)

## [ANIC - Angie Ingress Controller](https://cn.angie.software//news/articles/anic-angie-ingress-controller.md)

*11.08.2023*

今天我们将讨论Angie Ingress Controller（ANIC）- Web Server公司为简化Kubernetes中的流量管理而推出的解决方案。

![Alternative text](../../_images/news/anic-angie-ingress-controller.jpg)

## [Angie 和 N+1 探索俄罗斯开源世界](https://cn.angie.software//news/articles/angie-i-Nplus1-issleduyut-opensors-v-rossii.md)

*04.08.2023*

我们将与 N+1 编辑团队一起，用一年时间探索使用开源原则的软件开发世界。

![Alternative text](../../_images/news/angie-i-Nplus1-issleduyut-opensors-v-rossii.jpg)

## [Angie 一周年！](https://cn.angie.software//news/angie-1-god.md)

*21.07.2023*

今天，7月21日，Angie迎来了它的第一个生日。我们正在各大平台上开设博客，向您介绍我们的发展情况。

![Alternative text](../../_images/news/angie-1-god.jpeg)


# https://cn.angie.software/news/releases/angie-1-10-0.md

# Angie 和 Angie PRO 更新至 1.10.0 版本

*04.07.2025*

开源 Web 服务器 Angie 及其商业版 Angie PRO 已发布 1.10.0 版本。
主要更新包括自动代理 Docker 容器、改进流模块中的 ACME 支持、
支持多路径 TCP 和带 CUBIC 的 QUIC，以及集群模式下 Angie PRO 的新功能。

我们已将开源 Web 服务器 Angie 及其商业版 Angie PRO 更新至 1.10.0 版本。

此版本的重点功能是内置支持自动代理和负载均衡运行在 Docker 或 Podman 容器中的 Web 服务。带有特定标签的容器会自动添加到配置的上游组中，并实时跟踪其启动/停止生命周期——无需重新加载配置。

ACME 模块现在可以完全在流上下文中工作，扩展了自动配置 TLS 和更新证书的能力。

HTTP 上下文中新增了 `client` 块——类似于 `server` 块，但用于出站请求。这允许灵活配置与 ACME 服务器和 Docker API 的交互。

多路径 TCP 支持已从 freenginx 移植到 http、stream 和 mail 模块。Angie 现在还包括 nginx 1.27.5 版本的所有功能，包括 QUIC 连接中的 CUBIC 拥塞控制。与 nginx 不同，Angie 也可以使用 QUIC 进行到后端的出站连接。

在 Angie PRO 中，集群模式在使用外部存储时增强了新的会话粘性机制。流模块还获得了一种新的回退模式，避免立即返回到主服务器组。

我们还修复了 `drain` 模式统计中服务器停机时间计算的一个小错误。

了解更多变更：

- [Angie 1.10.0 变更](https://cn.angie.software/angie/docs/oss_changes/#angie-1-10-0)
- [Angie PRO 1.10.0 变更](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-10-0)

我们将很快在 Habr 上发布一篇详细文章，探讨此版本及未来发展。

祝您有美好的一天！😊


# https://cn.angie.software/news/releases/angie-1-10-1.md

# Angie 和 Angie PRO 更新至 1.10.1 版本

*17.07.2025*

发布了 Angie 和 Angie PRO 的 1.10.1 修复版本。此次更新修复了
reuseport 和 HTTP/3 的相关问题，改进了 client 配置块的逻辑，
增加了对新版本 GCC 的兼容性，并解决了 Angie PRO 中使用特殊变量时的崩溃问题。

我们发布了开源版 Angie 和商业版 Angie PRO 的修复版本 — 1.10.1。

在 Angie 中，修复了在 `listen` 指令中使用 `reuseport` 参数时，
所有连接都由同一个工作进程处理的问题。同时也解决了使用较新 OpenSSL 版本时
HTTP/3 代理失败的情况。

新版中改进了 `client  ` 配置块的逻辑，使其行为更清晰、使用更方便。

此外，更新增加了对新版本 GCC 编译器的兼容性，并修复了在使用 `-O3`
优化等级编译时的构建错误。

在 Angie PRO 中，修复了在非预期上下文中访问仅用于外部会话存储请求的特殊变量时
导致的工作进程崩溃问题。

详细更新内容：

- [Angie 1.10.1 的更新说明](https://cn.angie.software/angie/docs/oss_changes/#angie-1-10-1)
- [Angie PRO 1.10.1 的更新说明](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-10-1)

感谢大家的反馈与支持！


# https://cn.angie.software/news/releases/angie-1-10-2.md

# Angie 和 Angie PRO 更新至 1.10.2 版本

*22.08.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 发布了修复版本 1.10.2。
这些版本修复了在 1.10 版本中引入 client 块实现时出现的问题，该问题
可能会干扰 stream 模块中 ACME、Docker 和 sticky remote 模块的功能。
同时修复了通过 Docker API 更新代理服务器组的问题，并添加了两个新的
第三方模块。

开源 Web 服务器 Angie 及其商业版本 Angie PRO 发布了修复版本 — 1.10.2。

这些版本修复了在 1.10 版本中引入 `client` 块实现时出现的问题，该问题
导致 `http` 块级别的一些代理模块设置可能会干扰 stream 模块中 ACME、
Docker 和 sticky remote 模块的功能。

同时修复了当列表中只有一个服务器时，通过 Docker API 更新代理服务器组的问题。

此外，构建中添加了两个新的第三方模块：

- Auth TOTP 用于基于 TOTP 一次性密码的身份验证；
- Combined Upstreams 允许将多个代理服务器组合并为一个。

关于更改的详细信息：

- [Angie 1.10.2 更改日志](https://cn.angie.software/angie/docs/oss_changes/#angie-1-10-2)
- [Angie PRO 1.10.2 更改日志](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-10-2)

祝您度过愉快的一天！


# https://cn.angie.software/news/releases/angie-1-10-3.md

# Angie 和 Angie PRO 更新至 1.10.3 版本

*13.11.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 发布了修复版本 1.10.3。
从 nginx 1.29 移植了邮件 SMTP 模块的一个潜在漏洞修复。修复了 ACME 配置
错误，并解决了在 client 块中使用变量访问传入连接时的潜在崩溃问题。
PRO 版本还修复了 UDP 健康检查和 Docker 模块服务器的相关问题。

开源 Web 服务器 Angie 及其商业版本 Angie PRO 发布了修复版本 — 1.10.3。

这些版本包括：

- 从 nginx 1.29 移植了邮件 SMTP 模块的一个潜在漏洞修复。
- 修复了 ACME 配置错误。
- 解决了在 `client` 块中使用变量访问传入连接时的潜在崩溃问题。
  在该块中不存在这样的连接。

在商业版本 Angie PRO 中另外：

- 解决了活跃 UDP 健康检查的问题。
- 修复了通过 Docker 模块添加的服务器的活跃健康检查问题。
- 修正了配置重新加载后 learn-session 超时的问题。

关于更改的详细信息：

- [Angie 1.10.3 更改日志](https://cn.angie.software/angie/docs/oss_changes/#angie-1-10-3)
- [Angie PRO 1.10.3 更改日志](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-10-3)

祝您度过愉快的一天！


# https://cn.angie.software/news/releases/angie-1-11-0.md

# Angie 和 Angie PRO 更新至 1.11.0 版本

*24.12.2025*

Angie 和 Angie PRO 1.11.0 已发布 — 这是该项目历史上规模最大的更新。
此版本引入了 Metrics 模块，修复了 `HTTP/3` 可靠性问题，扩展了
ACME 和图像过滤器功能；Angie PRO 改进了具有外部存储的粘性会话，并在
API 中添加了许可证详情。

Angie 及其商业版本 Angie PRO — 1.11.0 — 现已发布。这是项目历史上规模最大的更新，
每个版本包含数十项改进。

主要亮点：

- 新增 Metrics 模块，用于实时数据采集和聚合（移动平均和指数平均、计数器、
  直方图等）。Metrics 可从任意变量构建，通过 HTTP API 以 JSON 和 Prometheus
  格式暴露，并可通过变量和日志使用。
- 修复了配置重加载和二进制升级时 `HTTP/3` 的可靠性问题；通过 BPF
  更新改进了进程间的 QUIC 数据包路由。
- ACME 增强：支持 ALPN 验证、API（及 Prometheus）中的续期状态、简化的
  HTTP 挑战配置，以及修复了在没有 `acme` 指令时从 `stream`
  块访问证书的问题。
- 图像过滤器更新，支持 AVIF 和 HEIC 格式，以及格式转换。
- 支持 ECH（Encrypted Client Hello）。
- 代理以及 `GET` 和 `HEAD` 请求正确缓存的改进。
- 移植了最新 nginx 版本的功能和 freenginx 的部分改进。

在 Angie PRO 中另外：

- 改进了对外部存储的会话绑定，便于构建多个负载均衡器组成的集群。
- 许可证和限制信息现在可通过 API 获取。

PHP 应用运行器作为 PHP-FPM 的替代方案未能纳入本版本 — 工作仍在进行中。

关于更改的详细信息：

- [Angie 1.11.0 更改日志](https://cn.angie.software/angie/docs/oss_changes/#angie-1-11-0)
- [Angie PRO 1.11.0 更改日志](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-11-0)

祝您度过愉快的一天！


# https://cn.angie.software/news/releases/angie-1-11-5.md

# Angie 和 Angie PRO 更新至 1.11.5 版本

*15.05.2026*

Angie 和 Angie PRO 1.11.5 修复版本已发布，移植了 nginx 中发现的五个漏洞的
修复。这些漏洞涉及 `rewrite`、`ssl_ocsp`、`scgi_pass`、
`uwsgi_pass` 和 `charset_map` 指令的工作，以及 `HTTP/3`
协议请求的处理。

Angie 及其商业版本 Angie PRO 修复版本 — 1.11.5 — 现已发布，移植了 nginx 中
发现的若干漏洞的修复。

已修复 5 个漏洞：
[CVE-2026-42945](https://nvd.nist.gov/vuln/detail/CVE-2026-42945)、
[CVE-2026-40701](https://nvd.nist.gov/vuln/detail/CVE-2026-40701)、
[CVE-2026-40460](https://nvd.nist.gov/vuln/detail/CVE-2026-40460)、
[CVE-2026-42946](https://nvd.nist.gov/vuln/detail/CVE-2026-42946) 和
[CVE-2026-42934](https://nvd.nist.gov/vuln/detail/CVE-2026-42934)。

nginx 中发现的第六个漏洞
[CVE-2026-42926](https://nvd.nist.gov/vuln/detail/CVE-2026-42926)
不影响已发布的 Angie 版本。

这些漏洞涉及 `rewrite`、`ssl_ocsp`、`scgi_pass`、
`uwsgi_pass` 和 `charset_map` 指令的工作，以及 `HTTP/3`
协议请求的处理。

关于更改的详细信息：

- [Angie 1.11.5 更改日志](https://cn.angie.software/angie/docs/oss_changes/#angie-1-11-5)
- [Angie PRO 1.11.5 更改日志](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-11-5)

祝您度过愉快的一天！


# https://cn.angie.software/news/releases/angie-1-11-6.md

# Angie 和 Angie PRO 更新至 1.11.6 版本

*25.05.2026*

Angie 和 Angie PRO 1.11.6 修复版本已发布，移植了前一日在 nginx 中发现的
[rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 指令漏洞 CVE-2026-9256 的修复。

Angie 及其商业版本 Angie PRO 修复版本 — 1.11.6 — 现已发布，移植了
前一日在 nginx 中发现的漏洞
[CVE-2026-9256](https://nvd.nist.gov/vuln/detail/CVE-2026-9256)
的修复。

当配置中使用 [rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 指令以及包含嵌套捕获的正则表达式时，
可能触发该漏洞，例如：
`rewrite ^/((.*))$ http://127.0.0.1:8080/?$1$2;`。

关于更改的详细信息：

- [Angie 1.11.6 更改日志](https://cn.angie.software/angie/docs/oss_changes/#angie-1-11-6)
- [Angie PRO 1.11.6 更改日志](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-11-6)

祝您度过愉快的一天！


# https://cn.angie.software/news/releases/angie-1-8-0.md

# Angie 和 Angie PRO 更新至版本 1.8.0

*19.12.2024*

Angie 网络服务器及其商业版本 Angie PRO 的 1.8.0 版本已发布。此更新包括 ACME 模块的新功能、对 WebAssembly 的支持，以及 API 和功能的改进。

开源网络服务器 Angie 及其商业版本 Angie PRO 的 1.8.0 版本已发布。这是 2024 年计划中的第四个 Angie 版本。

通过此次发布，用于自动化 TLS 证书设置的 ACME 模块现在支持发行通配符证书。

新的实现允许 Angie 使用自身的功能处理域名验证的 DNS 查询，与现有的自动化工具如 certbot 相比，这大大简化了设置过程。

有关这些功能的更多详细信息，请参阅我们为此次发布准备的 [综合指南](https://cn.angie.software//angie/docs/configuration/acme.md#acme-config)。

1.8.0 版本还包括 [之前宣布的 WASM 模块](https://cn.angie.software//news/articles/wasm.md) 为 Angie。这些模块添加了对 WebAssembly (WASM) 的支持，并提供了一个专用 SDK 用于创建 WASM 模块。Angie 中的 WASM 实现允许开发人员使用服务器 API 和 SDK 在流行的编程语言中编写扩展，为定制和灵活配置开辟了可能性。

此外，此更新还包括：

- Angie PRO 中 [粘性学习](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky) 模式的新设置，实现会话绑定与外部存储的结合。现在您可以创建具有会话绑定的整个负载均衡器集群！
- API 指标的改进： [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令现在支持变量，允许基于任意标准提供详细统计信息。
- 从 freenginx 项目和 nginx 版本 1.27.3 移植的功能。

有关新功能的更多详细信息，请访问以下链接：

- [Angie 1.8.0 更改](https://angie.software/angie/docs/oss_changes/#angie-1-8-0)
- [Angie PRO 1.8.0 更改](https://angie.software/angie/docs/pro_changes/#angie-pro-1-8-0)


# https://cn.angie.software/news/releases/angie-1-8-1.md

# Angie 和 Angie PRO 升级至 1.8.1 版本

*28.12.2024*

开源网络服务器 Angie 和其商业版本 Angie PRO 发布了 1.8.1 版本。
此更新修复了服务器统计区域的问题，改进了 ACME 模块对通配符证书的支持，并包含 HTTP/3 的重要修复。

开源网络服务器 Angie 和其商业版本 Angie PRO 已升级至 1.8.1 版本。

此版本修复了在 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令中添加对变量的支持后引入的服务器统计区域处理问题。

同时，修复了 [ACME 模块](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 中与获取通配符证书相关的功能问题，提高了证书配置的可靠性。

1.8.1 版本还包含了从未发布的 nginx 1.27.4 版本中移植的 HTTP/3 协议重要问题修复。由于供应商政策的变更（详见 [提交记录](https://github.com/nginx/nginx/commit/c73fb273acc31bff7c4e469efda5f3fd66c48557)），这些修复只会在 nginx 主分支的下一个版本中出现。

我们理解在年末最后一个工作日发布更新并不理想，但这是为了修复已发现的问题并确保稳定性所必须的。

更多有关更新的信息，请访问：

- [Angie 1.8.1 版本更新内容](https://cn.angie.software/angie/docs/oss_changes/#angie-1-8-1)
- [Angie PRO 1.8.1 版本更新内容](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-8-1)


# https://cn.angie.software/news/releases/angie-1-8-2.md

# Angie 和 Angie PRO 发布 1.8.2 更新

*13.02.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 的 1.8.2 版本包含重要的安全修复，以及其他多项改进。

我们已将开源 Web 服务器 Angie 及其商业版本 Angie PRO 更新至 1.8.2 版本。

首先，该版本移植了最近在 nginx 1.27.4 中修复的 [CVE-2025-23419](https://www.cve.org/CVERecord?id=CVE-2025-23419) 漏洞。此漏洞源于在不同于创建会话的虚拟主机中重用 TLS 会话，
可能绕过客户端 TLS 证书验证。当多个虚拟主机的客户端证书验证设置不同，而会话恢复机制或会话缓存启用时，该问题就会出现。

此外，本次更新修复了 HTTP/3 协议统计计算问题、API 请求处理错误，以及通过 ACME 协议处理域名时的错误。同时，它还修复了
在流模块中使用主动健康检查时导致的工作进程崩溃问题。

有关更新的更多详细信息，请参阅以下链接：

- [Angie 1.8.2 更新说明](https://cn.angie.software/angie/docs/oss_changes/#angie-1-8-2)
- [Angie PRO 1.8.2 更新说明](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-8-2)


# https://cn.angie.software/news/releases/angie-1-8-3.md

# Angie 和 Angie PRO 发布了 1.8.3 版本；Console Light 更新至 1.7.0 版本

*02.04.2025*

开源版 Angie 网络服务器及其商业版 Angie PRO 发布了 1.8.3 版本，修复了统计功能；
Console Light 更新至 1.7.0 版本。

我们已将开源版 Angie 网络服务器及其商业版 Angie PRO 更新至 1.8.3 版本。

1.8.3 版本修复了以下问题：在 HTTP 模块的 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 块中，
[status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 的统计信息可能在以下情况下计算不正确：
请求在一个连接中命中多个统计区域，或在请求处理早期阶段发生错误。

该问题首次出现在 1.8.2 版本中，由社区发现。
我们建议当前使用 Angie 1.8.\* 较早版本的用户升级至 1.8.3 版本。

这个错误修复版本发布在即将推出新功能的 1.9.0 版本之前，
确保那些尚未准备好升级到新版本的用户也能获得更新。

作为此次发布的一部分，可视化控制台 Angie Console Light 也已更新至
[1.7.0](https://cn.angie.software//angie/docs/configuration/monitoring.md#monitoring) 版本。它可以帮助实时监控网络服务器指标，包括性能和负载。

更多更新详情请查看：

- [Angie 1.8.3 的更改内容](https://cn.angie.software/angie/docs/oss_changes/#angie-1-8-3)
- [Angie PRO 1.8.3 的更改内容](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-8-3)


# https://cn.angie.software/news/releases/angie-1-9-0.md

# Angie 和 Angie PRO 更新至 1.9.0 版本

*11.04.2025*

开源网页服务器 Angie 及其商业版本 Angie PRO 已发布 1.9.0 版本。
主要更新包括将缓存索引保存到磁盘以加快重启速度、
在流模块中支持 TLS 1.3 Early Data，以及 Angie PRO 中 HTTP 负载均衡器的新功能。

我们已将开源网页服务器 Angie 和其商业版本 Angie PRO 更新至 1.9.0 版本。

这是 2025 年计划发布的四个主要版本中的第一个。

1.9.0 版本的主要变化是能够将共享内存中的缓存索引保存到磁盘，
并在重启时无需缓存加载器即可立即加载。该创新可在处理大规模缓存时加快服务器恢复速度。

在 Angie PRO 中，HTTP 负载均衡器新增了 [backup_switch (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-backup-switch) 指令。
它允许灵活配置在切换到备用服务器组时的行为，并控制停留的时间。

其他重要更新包括：

- 在流模块中支持 TLS 1.3 Early Data (0-RTT)；
- 新增服务器连接数耗尽时的状态 `busy`；
- 改进 [ACME](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 模块，简化证书续期管理；
- 缓存通过变量设置的「动态」TLS 证书（如 [ssl_certificate_cache](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-certificate-cache) 等指令）。

详细更新内容请见：

- [Angie 1.9.0 的更新内容](https://en.angie.software/angie/docs/oss_changes/#angie-1-9-0)
- [Angie PRO 1.9.0 的更新内容](https://en.angie.software/angie/docs/pro_changes/#angie-pro-1-9-0)

我们建议您更新至 1.9.0 版本以体验新功能。

在接下来的几天里，我们将发布特别文章，详细介绍 1.9.0 版本的变化，
并部分透露 1.10.0 版本的计划。

祝大家周末愉快！


# https://cn.angie.software/news/releases/angie-1-9-1.md

# Angie 和 Angie PRO 更新至版本 1.9.1

*29.05.2025*

开源 Web 服务器 Angie 及其商业版 Angie PRO 发布了 1.9.1 版本。
本次更新重点提升了对 HTTP/3 的支持，并改进了对非标准 ACME 配置的处理，
同时修复了流模块中的一些问题。

我们已将开源 Web 服务器 Angie 及其商业版本 Angie PRO 升级至 1.9.1 版本。

这是一个以提升稳定性和修复已知问题为主的修订版本。

主要更新内容：

- 提升了与 HTTP/3 协议交互时的稳定性；
- 改进了 [ACME](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 模块对非标准配置的支持；
- 修复了流模块中代理服务器状态显示不正确的问题；
- 修复了 `drain` 模式下的一个错误。

详细更新内容请参阅：

- [Angie 1.9.1 的变更](https://angie.software/angie/docs/oss_changes/#angie-1-9-1)
- [Angie PRO 1.9.1 的变更](https://angie.software/angie/docs/pro_changes/#angie-pro-1-9-1)

我们曾在 Habr 上详细介绍了从 1.9.0 版本开始的新功能：
[https://habr.com/zh/articles/900672/](https://habr.com/zh/articles/900672/)


# https://cn.angie.software/news/angie-1-god.md

# Angie 一周年！

*21.07.2023*

今天，7月21日，Angie迎来了它的第一个生日。我们正在各大平台上开设博客，向您介绍我们的发展情况。

![Alternative text](../../_images/news/angie-1-god.jpeg)![Alternative text](../../_images/news/angie-1-god.jpeg)

各位同事、客户和合作伙伴们，大家好！

2022年7月，我们组建了一支由曾参与NGINX Web服务器开发和支持的顶尖工程师组成的团队，创立了Web Server公司，并开始开发俄罗斯开源Web服务器Angie。今天，7月21日，Angie迎来了它的第一个生日。我们正在各大平台上开设博客，向您介绍我们的发展情况。

以下是我们一年来取得的成就简报：

2022年秋季，Web Server团队发布了Angie的开源版本。它是基于NGINX（这是我们最熟悉且最流行的Web服务器）的一个分支，但同时也是一个独立的项目，会定期更新新功能。比如，这款国产Web服务器已经支持HTTP/3协议。

但Angie的本质不在于复制：我们正在使我们的Web服务器变得更可靠、更经济、更快速。统计数据收集功能使我们能够及时应对资源过度使用、错误和攻击；会话绑定和DNS服务器更新有助于在现代基础设施中实现负载均衡。我们目前正在添加均衡服务器的主动检查和配置管理功能，以提高容错能力并简化管理。

Angie团队认为开源版本是其工作中最重要的领域之一——我们也参与了创建俄罗斯代码仓库的实验，与Basalt、Red Soft和T1 Innovations等俄罗斯IT市场巨头共同合作。

我们也为企业客户提供优质服务。2023年春季，我们发布了Angie PRO——这是唯一一款获得与国产操作系统RED OS、Astra Linux Special Edition和Alt Server 10兼容性认证的商业俄罗斯Web服务器。我们的另一个产品——Angie Ingress Controller (ANIC)——是一个使用Ingress Controller管理Kubernetes中容器化应用程序流量的解决方案。

我们的目标是满足俄罗斯市场的技术需求。Web服务器的付费版和开源版都提供俄语文档和支持；我们还计划添加符合GOST标准的加密功能。在我们的代码仓库中，我们发布了适用于各种操作系统和硬件平台（包括国产平台）的现成软件包，以及补充Web服务器核心功能的流行动态模块。

但这仅仅是开始。我们一定会给您带来惊喜。不止一次，也不止两次。

在这个博客中，我们将讨论俄罗斯IT市场如何运作（不仅是运作，还包括失败、卡顿和宕机的情况），分享我们与中国客户合作的经验（是的，我们确实有这样的经验），并分享技术专长——我们不仅会告诉您产品开发的进展，最终还会在这里集成技术支持聊天功能。

我们还将发布职位招聘信息（欢迎开发人员等加入——我们在这个领域拥有很强的专业知识），并讨论我们认为有趣的项目和媒体报道。我们更注重深思熟虑的公关，而不是铺天盖地的宣传。

朋友们，这将会很有趣！

此致
Angie团队

[我们的网站](https://cn.angie.software)
[Telegram频道](https://t.me/angie_software)


# https://cn.angie.software/news/angie-console-mi-razrabativaem-novii-produkt.md

# Angie Console - 我们正在开发新产品！

*09.02.2024*

这是一个用于管理Web服务器集群的集中式系统，具有监控和动态配置功能。

![Alternative text](../../_images/news/angie-console-mi-razrabativaem-novii-produkt.jpg)![Alternative text](../../_images/news/angie-console-mi-razrabativaem-novii-produkt.jpg)

我们的目标是创建一个用户友好且直观的负载均衡系统控制台。为此，我们正在开发一个新产品——Angie Console。这是一个用于管理Web服务器集群的集中式系统，具有监控和动态配置功能。产品即将发布，敬请关注！


# https://cn.angie.software/news/articles/angie-i-Nplus1-issleduyut-opensors-v-rossii.md

# Angie 和 N+1 探索俄罗斯开源世界

*04.08.2023*

我们将与 N+1 编辑团队一起，用一年时间探索使用开源原则的软件开发世界。

![Alternative text](../../_images/news/angie-i-Nplus1-issleduyut-opensors-v-rossii.jpg)![Alternative text](../../_images/news/angie-i-Nplus1-issleduyut-opensors-v-rossii.jpg)

大家好！

近年来，俄罗斯越来越多地思考如何开发开源项目——可信赖的代码仓库正在建立，法规框架正在完善，专门的组织机构也在成立，承诺培育开源项目开发的生态系统。

[Angie 网络服务器](https://wbsrv.ru) 最初就被设计为一个开源项目——我们相信这能确保我们产品的高质量。然而，在发布第一个版本、与合作伙伴对话以及内部讨论期间，我们意识到并非所有人都理解什么是开源软件，以及它为什么如此重要。

我们将与俄罗斯最权威的科技媒体 N+1 的编辑团队一起，用一年时间探索使用开源原则的软件开发世界。我们将讨论这类项目的历史、经济、安全性以及哲学和伦理。我们将研究国家和大型企业的利益如何影响这些项目。当然，我们也将努力理解这些项目在俄罗斯的未来发展。

我们工作的最终目标是创建俄罗斯首个关于开源项目开发文化的研究。我们邀请所有真正关心这个话题的人加入讨论。

在我们准备第一批材料期间（将在9月份开始发布，届时我们会再次公告），您可以在 [N+1 网站](https://nplus1.ru) 上阅读其他新闻。例如关于 [为了科学研究而让人体模型出汗的实验](https://nplus1.ru/news/2023/07/25/sweating-robot)。


# https://cn.angie.software/news/releases/angie-i-angie-pro-obnovleni-dlya-uluchsheniya-zashchity-ot-dos-ataki.md

# Angie和Angie PRO针对DoS攻击的防护得到增强

*18.10.2023*

Web Server公司宣布发布Angie和Angie PRO的1.3.1版本。

Web Server公司宣布发布Angie和Angie PRO的1.3.1版本。

此次发布包含了多项变更，其中包括对HTTP/2协议数据流的限制，这增强了对"HTTP/2 Rapid Reset" DoS攻击的防护。Web Server公司认为Angie并不受此问题影响，但仍决定采取额外的预防措施。

Angie 1.3.1和Angie PRO 1.3.1代表了俄罗斯Web服务器发展的重要一步。更新后的版本提供了更高水平的安全性和性能。

早些时候，在10月11日，谷歌报告 <[https://www.opennet.ru/opennews/art.shtml?num=59901/](https://www.opennet.ru/opennews/art.shtml?num=59901/)> 其基础设施遭受了最大规模DDoS攻击，攻击强度达到每秒3.98亿次请求。这种新的攻击技术被命名为"Rapid Reset"，它利用了HTTP/2提供的多路复用功能，允许在已建立的连接中形成请求流，无需开启新的网络连接，也无需等待数据包确认。该漏洞被视为HTTP/2协议缺陷的结果，该协议在其规范中指出，当尝试打开过多流时，应该只取消超出限制的流，而不是关闭整个网络连接。


# https://cn.angie.software/news/releases/angie-i-angie-pro-poluchili-obnovlenie-1-7-0.md

# Angie 和 Angie PRO 收到更新 1.7.0

*20.09.2024*

新版本的开源网页服务器 Angie 1.7.0 和商业版 Angie PRO 1.7.0 现已推出，提供显著的改进和新功能。

Angie 开源网页服务器及其商业版 Angie PRO 的 1.7.0 版本已发布。此更新包括多个增强功能，以提高服务器的可靠性和弹性，同时从 freenginx 项目移植了一些功能。

基于客户的请求，我们引入了三个关键特性：

1. **DNS 查询统计**：跟踪内置缓存解析器发出的外部 DNS 查询的统计信息。
2. **证书类型变量**：显示所使用证书类型的信息，这在具有多种证书类型的配置中尤为有用。
3. **后端移除时强制断开连接**：类似于 NGINX Plus 中的 proxy_session_drop 的功能，但具有几项改进：
   - 在流模块和 HTTP 模块中均有效，对于长期 WebSocket 连接特别有帮助。
   - 允许配置强制关闭连接前的等待时间。
   - 在 Angie PRO 中，可以通过 API 动态为每个服务器启用此模式。

此外，Angie PRO 还引入了增强的流量管理工具，包括新的负载均衡模式和错误修复。


# https://cn.angie.software/news/releases/angie-i-angie-pro-poluchili-obnovlenie-1.3.2.md

# Angie和Angie PRO发布1.3.2更新

*24.11.2023*

Web Server公司发布了Web服务器Angie及其商业版本Angie PRO的更新。

Web Server公司发布了Web服务器Angie及其商业版本Angie PRO的更新。在新版本1.3.2中，修复了与代理服务器相关的主动检查问题、Prometheus指标统计收集问题以及连接计数问题。

 *"我们感谢向我们报告问题的用户，因此我们努力及时解决这些问题，并迅速回应论坛上的问题，"* 公司首席执行官Zaur Abasmirzoev表示。


# https://cn.angie.software/news/releases/angie-i-angie-pro-poluchili-obnovlenie-1.6.1.md

# Angie 和 Angie PRO 发布 1.6.1 更新

*08.08.2024*

Web Server公司发布了开源网络服务器 Angie 1.6.1 和其商业版本 Angie PRO 1.6.1。

Web Server公司发布了开源网络服务器 [Angie 1.6.1](https://cn.angie.software/oss_changes/#angie-1-6-1) 和其商业版本 [Angie PRO 1.6.1](https://cn.angie.software/pro_changes/#angie-pro-1-6-1)。这些版本针对 nginx 1.27 中新增的功能，改进了 [stream 模块 API](https://cn.angie.software/configuration/modules/http/http_api/#status-stream-server-zones-zone) 中的统计数据收集，同时修复了 [ACME 协议实现](https://cn.angie.software/configuration/modules/http/http_acme/) 中的一个缺陷以及缓存响应处理的一个问题。

这些修复的实现离不开用户的反馈，他们主动分享报告并告知我们所遇到的任何问题。我们努力回应通过 [论坛](https://forum.angie.support) 和 [GitHub](https://github.com/webserver-llc/angie/issues) 提交的所有错误报告和需求，并在规划新版本时参考这些反馈。

我们还采纳了另一个来自社区的建议：现在 Angie 不仅整合了来自原始 [nginx](https://nginx.org/) 的更改，还包含了其最新分支 [freenginx](https://freenginx.org/) 的更改；我们始终将快速响应各种改进并秉持开源精神公正地实施这些改进作为首要任务。


# https://cn.angie.software/news/angie-priglashaet-na-rabotu.md

# Angie正在招聘

*28.05.2024*

大家好！我们想让全世界知道，我们也需要专业人士。

![替代文本](../../_images/news/angie-priglashaet-na-rabotu.jpeg)![替代文本](../../_images/news/angie-priglashaet-na-rabotu.jpeg)

我们是一家年轻的软件供应商公司，我们需要你来征服这个世界。我们每天都在为此努力。

 *— 嘿，Brain，我们今晚要做什么？*

 *— 我们要做的还是跟往常一样，Pinky，试图征服世界。*

 *© Pinky和Brain⁠⁠.*

你可以阅读和观看关于我们的内容：

[Kommersant，nginx正在俄罗斯重建。](https://www.kommersant.ru/doc/5634072)

[Vedomosti，首个俄罗斯网络服务器已被纳入国内软件注册。](https://www.vedomosti.ru/technology/articles/2023/05/24/976527-pervii-rossiiskii-veb-server-vnesen-v-reestr-otechestvennogo-po?shared_token=cbe20f6feeee8a5bcf52f077d2d6ad62b66e3917)

[Habr，"网络服务器"推出ANIC——Kubernetes网络中的流量管理软件。](https://habr.com/news/744654/)

我们首席执行官Zaur Abasmirzoev在Forbes的一些专栏文章：[开发者市场：如何发展俄罗斯的GitHub。](https://www.forbes.ru/mneniya/491830-marketplejs-dla-razrabotcikov-kak-razvivat-rossijskij-github)，Forbes [开放源代码的封闭区域：中俄如何发展开源。](https://www.forbes.ru/tekhnologii/495635-zakrytye-zony-otkrytogo-koda-kak-kitaj-i-rossia-razvivaut-open-source)

[与我们首席开发员Valentin Bartenev在Habr的访谈。](https://habr.com/articles/774274/)

[Valentin Bartenev在HighLoad的演讲（YouTube）。](https://www.youtube.com/watch?v=CKHNqMawUiE)

![替代文本](../../_images/news/02-team_1.webp)

例如，在开源产品——Angie网络服务器中——我们的团队继续按照质量和稳定性的传统开发老牌nginx，扩展其功能以满足现代需求。请查看已累积的 [变更日志](https://wbsrv.ru/angie-pro/docs/#index-features-oss)。

对于开源产品，我们提供社区支持。无论我们在公司的角色如何，我们都会尽可能地监控各种平台——Telegram聊天、论坛、GitHub、技术博客的评论。我们不排斥与匿名人士沟通。我们还尝试在每年的HighLoad会上分享关于我们项目的更新。例如，如果开发人员能够做到，今年我们将推出WASM支持，并在会议上讨论这一点。

所有这些都是针对国际市场的长期战略，我们正在逐渐在使用统计中攀升。

下一个产品是基于Angie PRO的ANIC入口控制器的开发，因为这与我们在负载均衡系统（以及客户请求）上的发展方向一致。然后，我们逻辑上得出结论，我们需要将符合企业多样化需求的产品推向市场。具体而言：

- 以虚拟设备形式提供的"负载均衡系统"类的盒装解决方案（未来还有硬件-软件解决方案）
- 用于配置网络参数的Web面板，支持鼠标点击
- 面向工程师和集成的API/CLI
- 全球服务器负载均衡——全球流量负载均衡（例如，在DNS级别，考虑接收流量的服务器状态）
- 在L4-L7网络级别操作的高性能负载均衡器
- 一组组件，用于将盒装解决方案集成到L2-L3网络级别的网络拓扑中

最终，我们发展出了应用交付控制器（Angie ADC）——一个满足所有上述客户请求的产品类别。为了理解，你可以参考现有的产品，如Citrix Netscaler（ADC）或F5 Big-IP。该产品既有趣又庞大，我们绝对知道如何使其在俄罗斯和全球市场上具有竞争力。

简而言之，我们有几年的发展战略——我们想要实现什么，追求什么商业结果——并且我们始终遵循这一战略。

现在，让我们谈谈我们的开发过程是如何组织的。

对我们来说，里程碑是季度发布。我们尽量在所有产品中遵循这个时间表。例如，你可以在这里查看开源版本网络服务器的变更历史：[https://angie.software/oss_changes/](https://angie.software/oss_changes/)。公司的开发日程和所有预发布活动都与这些里程碑保持一致。甚至为作者版权的后勤工作也与之保持一致。

除了发布，我们还为公司设定每周几个目标，基本上围绕跨团队互动展开。我们尽量在短时间内专注于这些目标。每周至少一次，开发团队会举行内部状态会议。有时根据会议结果，我们会调整路线图。同时，团队之间没有每日站立会议或电话会议（或者我只是没听说过）。

我们还在公司举行每周一次的总会议（视频通话），每个团队分享他们的成功、失败以及任何帮助人们保持信息灵通的内容。总体而言，开放性和内部透明度相当高。与一些公司相比，这个水平极高。我们甚至要求财务人员以所有其他同事能够理解的方式解释他们的工作，让大家知道这些可怜的人在办公室里做什么。

这就是简单明了的工作和开发过程，然而，这需要同事们具备一定的独立性。哦——这就是责任。

我们的办公室位于莫斯科，维亚茨卡亚街。我们完全采用混合办公模式。偶尔会有勇敢的尝试在工作时间把大家聚在一起，但目前为止，唯一的机会是在公司活动期间。

让我们回到我们的产品在技术栈方面：

![替代文本](../../_images/news/05-portfolio.webp)
- 我们用C语言编写Angie，并继续在Perl中进行测试。
- 内部包含Angie Pro的Angie入口控制器使用Go开发。
- Angie控制台作为虚拟设备的一部分，是一个经典的Web应用程序，包含后端和前端。使用Go、Python（测试）、Typescript、React、Next.js、Jest。
- 我们使用Ansible、Jenkins、qemu、Docker、rpm构建来构建一切。
- Angie ADC继承了上述所有内容，另外网络组件再次使用Go和BGP/VRRP等技术。

由此可见，我们正在寻找的专业人员的档案：

- 后端和前端开发人员
- 测试工程师
- 技术写作人员
- 技术产品经理

除了技术团队外，我们还对能够区分Web服务器和数据库的经验丰富的销售专家感兴趣。是的，这是一句玩笑。
目前，Angie ADC团队的招聘是我们的优先事项。
我们正在有针对性地寻找加入我们团队的同事。我们甚至愿意考虑招聘一个团结的团队。但我们会谨慎选择——保持内部氛围的舒适性很重要。我们不容忍争吵，也不害怕工作冲突。我们知道如何区分这两者。
我们重视冷静和愿意来工作、创造，并在必要时学习的人，而不是围着咖啡机转（尽管我们办公室里确实有咖啡机）。团队领导是市场上该领域最优秀的专业人士。我们的同事都很出色。
薪资，通常所说，是有竞争力的。公司被列入认可的IT组织名录。

你可以写信至hr@wbsrv.ru。如果你不确定应该将询问发送到哪里，可以直接联系我，邮箱是zaur@wbsrv.ru，或者在Telegram上联系我@izaurio，以便我们互相认识。如果你觉得自己可能适合我们（或者我们适合你），请不要犹豫。无需发送标准简历；最好写1-2段关于你自己、你的经验和你的目标的内容。
总的来说，我想说的是：来和我们一起工作，让我们一起创造伟大的事物。

爱你的，Zaur Abasmirzoev。


# https://cn.angie.software/news/integrations/angie-pro-sertifitsirovan-dlya-os-rosa-chrome-12-server.md

# Angie PRO 获得 ROSA Chrome 12 Server 操作系统认证

*01.12.2023*

俄罗斯网络服务器开发商Web Server与 ROSA IT 研究中心已确认 Angie PRO 网络服务器与 ROSA Chrome 12 Server 操作系统的兼容性，这一点已通过双方签发的证书得到证实，凸显了产品的高度兼容性和可靠性。

俄罗斯网络服务器开发商Web Server与 ROSA IT 研究中心已确认 Angie PRO 网络服务器与 ROSA Chrome 12 Server 操作系统的兼容性，这一点已通过双方签发的证书得到证实，凸显了产品的高度兼容性和可靠性。

该认证证书证明 Angie PRO 网络服务器满足 ROSA Chrome 12 Server 操作系统的所有要求，可以在企业环境中使用。这为用户提供了高效且安全工作的新机会。

Web Server在网络服务器开发方面拥有深厚的知识和丰富的经验，而 ROSA IT 研究中心则是操作系统和基础设施软件开发领域的领导者。

ROSA Chrome 是基于其自有仓库 ROSA 2021.1 构建的操作系统，该仓库为服务器、桌面和移动操作系统提供支持。ROSA Chrome 操作系统仓库是世界上最大的仓库之一，包含超过35,000个应用程序和组件。它支持 x86 和 ARMv8 硬件平台、e2k（Elbrus）和 RISC-V。

该操作系统的优势包括：安全性、在俄罗斯完全本地化的开发和支持、为 Windows 用户提供熟悉的工作环境、软件产品的开发和组装环境（ABF）、灵活的技术政策，以及被列入俄罗斯联邦数字发展、通信和大众传媒部维护的统一俄罗斯软件注册表，注册号为1607。

Angie PRO 网络服务器与 ROSA Chrome 12 Server 操作系统的兼容性是俄罗斯技术和产品发展的又一步，表明其可以与国外同类产品竞争。Web Server和 ROSA IT 研究中心将继续致力于产品的开发和功能的扩展。

此前，Angie 已通过了国产操作系统的兼容性认证：Red OS、Astra Linux Special Edition、Alt 及其 FSTEC 版本 Alt SP，并已被列入国产软件注册表（编号17604）。

**参考信息**

ROSA IT 研究中心（NTC IT ROSA）是俄罗斯领先的信息技术开发商和供应商。该公司基于自有仓库 ROSA 2021.1 开发系统和基础设施软件。公司的技术栈能够满足国家和大型企业的广泛 IT 需求。产品组合包括操作系统 ROSA Chrome、ROSA Fresh、ROSA Barium、ROSA Cobalt 和 ROSA Mobile，ROSA 虚拟化平台、操作系统管理平台和混合虚拟基础设施。公司的产品已被列入俄罗斯数字发展部的国产软件注册表，并获得了相应的 FSTEC 证书，可处理机密信息。
www.rosalinux.ru


# https://cn.angie.software/angie.md

# Angie

Angie 是 nginx 的一个自由分支，是一个强大且可扩展的 web 服务器。
      代码在公共仓库中以 BSD 类型的自由许可证开放。

Angie 是一个强大且可扩展的 web 服务器，发展了 nginx 的理念：

- 由前 nginx 开发者创建，旨在朝着一个新方向发展。
- 作为前身的替代品提供，
  无需重新配置和模块重开发。
- 包含 [nginx |nginxversion|](https://nginx.org/en/CHANGES) 的所有功能
  并增加了一些新功能。

[二进制包](https://cn.angie.software//angie/docs/installation/oss_packages.md) 可用于
各种操作系统和架构，以及 [Docker 镜像](https://cn.angie.software//angie/docs/installation/docker.md)。项目代码在 [公共仓库](https://cn.angie.software//angie/docs/development.md)
中开放，遵循 BSD 类型的自由许可证。

动态模块用于扩展基本功能。
它们经过测试、编译，
也可以在 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-dynamicmodules) 中获取。

**Angie |angie_version|** 于 **|angie_release_date|** 发布。
新版本每季度发布；
重要修复和改进按时发布。
另见 [版本历史](https://cn.angie.software//angie/docs/oss_changes.md)。

您可以在 [我们的网站](docs/) 上找到完整文档。

## Why Angie?

[HTTP/3 协议](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md)
支持客户端连接和与 [代理服务器](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md) 的连接，允许从不同方面独立使用不同的协议 (HTTP/1.x、HTTP/2、HTTP/3)。

通过 REST 风格的 [API 接口](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 以 JSON 格式访问有关 web 服务器的基本信息、其 [配置](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api-config-files) 和 [统计信息](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics)，包括代理服务器、客户端连接、共享内存区等许多其他内容。

支持 [Prometheus 格式](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#id3) 和
[可自定义模板](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#prometheus-template)。

自动代理和负载均衡运行在 [Docker 容器](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker) 中的服务。

通过 `slow_start` 选项实现
[server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 指令的功能。

通过内置的 [ACME](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md) 支持获取 TLS 证书。

用于通过浏览器监控服务器的 [Console Light](https://cn.angie.software//angie/docs/configuration/monitoring.md) 控制台。
在线示例: [https://console.angie.software/](https://console.angie.software/)

[会话绑定模式](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky)，其中会话中的所有请求都路由到同一代理服务器。

流模块的 [mqtt_preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#s-mqtt-preread) 指令，扩展 MQTT 协议的授权和负载均衡能力。

为我们自己的模块和第三方模块提供现成的 [包](https://cn.angie.software//angie/docs/installation/external-modules/index.md#install-thirdpartymodules)。

## Support and Development

如果您遇到问题但在 [文档](docs/) 中找不到解决方案，请在 [社区论坛](https://forum.angie.support/) 或在 Telegram 的 [支持聊天](https://t.me/angie_support) 中提问。
通过 [GitHub](https://github.com/webserver-llc/angie/issues) 分享新功能的想法或您自己的改进。

## Legal Information

* [Angie 软件产品许可证](https://cn.angie.software//angie/license-angie.md)
* [许可组件存在声明](https://cn.angie.software//angie/doc-license.md)
* [贡献者许可协议](https://cn.angie.software//angie/contributor-agreement.md)


# https://cn.angie.software/news/articles/anic-angie-ingress-controller.md

# ANIC - Angie Ingress Controller

*11.08.2023*

今天我们将讨论Angie Ingress Controller（ANIC）- Web Server公司为简化Kubernetes中的流量管理而推出的解决方案。

![Alternative text](../../_images/news/anic-angie-ingress-controller.jpg)![Alternative text](../../_images/news/anic-angie-ingress-controller.jpg)

Kubernetes是一个流行的容器编排系统。它的任务之一是将请求路由到系统内的应用程序。这是通过两个组件来实现的：Ingress和Ingress Controller。Ingress是请求的入口点，有助于路由和负载均衡流量。但是，要使其正常运行，需要Ingress Controller。我们将解释Web Server公司的新产品\*\*Angie Ingress Controller（ANIC）\*\*如何帮助简化Kubernetes中的流量管理。

Ingress Controller允许您根据指定的设置管理代理和负载均衡。当设置发生变化时，Ingress Controller会收到信号并根据新数据重新配置Ingress。这样，我们就可以通过修改设置来管理对运行在Kubernetes集群中的应用程序的外部请求。Ingress可以配置为将外部URL绑定到内部服务、提供流量均衡以及处理SSL/TLS连接。通常，反向代理服务器被用作Ingress。

**Angie Ingress Controller（ANIC）** 支持两种安装方式：DaemonSet和Deployment。

如果您需要安装单个Ingress Controller实例并动态更改实例数量，请使用Deployment。如果您需要在集群的每个节点上安装Ingress Controller，请使用DaemonSet。

ANIC使用Angie PRO网络服务器作为Ingress。它是世界上最强大的网络服务器之一。Angie PRO有效地解决了分配给Ingress的核心任务。大量的设置允许灵活代理，并能够通过REST接口动态管理上游组设置。此外，Angie PRO还可以作为L4-L7负载均衡器。

**除了Angie PRO的标准功能外：**

* 它允许创建虚拟服务器并具有众多灵活的设置。
* 它支持HTTP/2协议，使您能够在监听套接字上接受HTTP/2连接。
* 它支持会话持久性（粘性会话），确保客户端会话中的所有请求都绑定到上游组中的单个服务器。
* 流量分割允许进行A/B测试和金丝雀部署。
* 它通过RESTful接口提供广泛的统计信息和实时监控。以JSON格式提供基本服务器信息，以及客户端连接、共享内存区域、DNS查询、HTTP请求、HTTP响应缓存、流模块会话、http_upstream和其他模块区域的统计信息。
* 它允许通过REST接口动态管理上游组设置。

有关更多详细信息，您可以 [访问我们的网站了解](https://wbsrv.ru/anic/)。


# https://cn.angie.software/anic.md

# ANIC

ANIC 是 NGINX Ingress Controller 的一个分支，集成了 Angie PRO 的功能。

Angie Ingress Controller (ANIC) 是一个用于管理 Kubernetes 中容器化应用流量的解决方案。

ANIC 部署并在集群内运行，管理 Ingress 功能，并能够配置流量处理规则。该产品基于 Angie PRO 的能力，允许构建安全、可扩展、高性能的环境，提供专业迁移服务和俄语技术支持的俄罗斯解决方案。

**ANIC |anic_pdf_version|** 已于 

```
|anic_release_date|
```

 发布。

## 为什么选择 ANIC？

| 功能                    | ANIC    | K8S Ingress Controller   | NGINX Ingress Controller   | Kong Ingress Controller   | Traefik   | Istio   | HAProxy   | Contour   |
|-----------------------|---------|--------------------------|----------------------------|---------------------------|-----------|---------|-----------|-----------|
| Prometheus 格式指标       |         |                          |                            |                           |           |         |           |           |
| 粘性会话                  |         |                          |                            |                           |           |         |           |           |
| 日志的变量                 |         |                          |                            |                           |           |         |           |           |
| 通过注释配置 TLSPassthrough |         |                          |                            |                           |           |         |           |           |
| 对 Ingress 实体使用片段      | backlog |                          |                            |                           |           |         |           |           |
| OpenID Connect (OIDC) |         |                          |                            |                           |           |         |           |           |
| 路径的 JWT 验证配置          |         |                          |                            |                           |           |         |           |           |
| 通过注释添加上游参数            | backlog |                          |                            |                           |           |         |           |           |
| 通过注释添加粘性路由参数          | backlog |                          |                            |                           |           |         |           |           |
| 读取 DOCKER 标签以便在容器中使用  | backlog |                          |                            |                           |           |         |           |           |
| OpenTelemetry         | backlog |                          |                            |                           |           |         |           |           |
| OpenTracing           | backlog |                          |                            |                           |           |         |           |           |
| HTTP3                 | backlog |                          |                            |                           |           |         |           |           |

## 系统要求

除了常见的发行版外，还支持俄罗斯操作系统，如 RED OS、Astra Linux、Alt 和 ROSA。完整的列表可以在 [此链接](https://cn.angie.software//angie/docs/installation/oss_packages.md) 找到。

## 技术支持

我们提供两种技术支持选项：标准的工作时间支持和企业支持——提供 24/7 的支持，确保在您需要时随时可用。

## 随附文档

PDF 文档（俄语）：

- [`ANIC 安装指南`](https://cn.angie.software//anic/ANIC_|anic_pdf_version|_installation_guide.pdf)
- [`ANIC 功能规格`](https://cn.angie.software//anic/ANIC_|anic_pdf_version|_functional_description.pdf)
- [`ANIC 操作指南`](https://cn.angie.software//anic/ANIC_|anic_pdf_version|_operating_guide.pdf)

## 许可证购买

该软件产品以商业许可证分发。
有关软件价格、购买条件以及许可证协议的信息,
可以通过以下电子邮件地址写信给我们:
[info@wbsrv.ru](mailto:info@wbsrv.ru)。


# https://cn.angie.software/news/articles.md

# 文章

## [Angie 启用 WebAssembly 支持](https://cn.angie.software//news/articles/wasm.md)

*29.11.2024*

此次更新使得可以构建 WASM 模块，以便 Angie 加载并在服务器配置中使用它们。

## [Angie新增功能助力更好的Web服务器监控](https://cn.angie.software//news/articles/novoe-v-angie-dlya-luchshego-monitoringa.md)

*17.11.2023*

2023年9月，我们通过添加Angie Console Light为Angie web服务器引入了新的监控组织方式。

## [多方位监控 Angie —— nginx Web 服务器的分支](https://cn.angie.software//news/articles/multifaceted-monitoring.md)

*27.09.2023*

Angie 监控能力的详细概述：用于统计的内置 API、
用于实时可视化的 Console Light，以及无需第三方模块的 Prometheus 集成。

## [认识 Console Light](https://cn.angie.software//news/articles/vstrechaite-console-light.md)

*27.09.2023*

我们推出了一款用于实时活动监控的轻量级可视化控制台。

![Alternative text](../../_images/news/vstrechaite-console-light.jpg)

## [在俄罗斯推广开源](https://cn.angie.software//news/articles/populyarizuem-opensource-v-rossii.md)

*14.09.2023*

我们与科学出版物N+1的朋友们一起启动了一个在俄罗斯推广开源的特别项目。

![Alternative text](../../_images/news/populyarizuem-opensource-v-rossii.jpeg)

## [Angie与中国的经验](https://cn.angie.software//news/articles/opyt-raboti-angie-s-kitaem.md)

*04.09.2023*

当俄罗斯正在积极制定"本土"开源项目发展计划时，中国也在积极发展其自己的开源项目。

![Alternative text](../../_images/news/opyt-raboti-angie-s-kitaem.jpeg)

## [Angie 与 nginx 的异同点](https://cn.angie.software//news/articles/shodstva-i-razlichiya-angie-i-nginx.md)

*25.08.2023*

Angie 项目和 Angie PRO 产品与其前身 nginx 及其商业版本 NGINX Plus 的关系。

![Angie vs. nginx](../../_images/news/shodstva-i-razlichiya-angie-i-nginx.webp)

## [ANIC - Angie Ingress Controller](https://cn.angie.software//news/articles/anic-angie-ingress-controller.md)

*11.08.2023*

今天我们将讨论Angie Ingress Controller（ANIC）- Web Server公司为简化Kubernetes中的流量管理而推出的解决方案。

![Alternative text](../../_images/news/anic-angie-ingress-controller.jpg)

## [Angie 和 N+1 探索俄罗斯开源世界](https://cn.angie.software//news/articles/angie-i-Nplus1-issleduyut-opensors-v-rossii.md)

*04.08.2023*

我们将与 N+1 编辑团队一起，用一年时间探索使用开源原则的软件开发世界。

![Alternative text](../../_images/news/angie-i-Nplus1-issleduyut-opensors-v-rossii.jpg)


# https://cn.angie.software/angie/docs/installation/external-modules/auth-jwt.md

<!-- review: finished -->

<a id="external-auth-jwt"></a>

# Auth JWT

该模块通过使用指定密钥验证提供的 JSON Web Token (JWT) 来实现客户端授权。

- 支持 JSON Web Signature (JWS)。
- 可用于通过 OpenID Connect 进行身份验证。

<a id="installation"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-auth-jwt`
- Angie PRO：`angie-pro-module-auth-jwt`

<a id="loading-the-module"></a>

## 加载模块

在 `main{}` 上下文中加载模块：

```nginx
load_module modules/ngx_http_auth_jwt_module.so;
```

<a id="configuration-example-78"></a>

## 配置示例

```nginx
location / {
    auth_jwt          "closed site";
    auth_jwt_key_file conf/keys.json;
}
```

完整配置示例可在以下位置获取：
[https://github.com/kjdev/nginx-auth-jwt/tree/main/example](https://github.com/kjdev/nginx-auth-jwt/tree/main/example)

<a id="additional-information"></a>

## 其他信息

详细文档和源代码可在以下位置获取：
[https://github.com/kjdev/nginx-auth-jwt](https://github.com/kjdev/nginx-auth-jwt)


# https://cn.angie.software/angie/docs/installation/external-modules/auth-ldap.md

<!-- review: finished -->

<a id="external-ldap"></a>

# Auth LDAP

LDAP 模块支持跨多个 LDAP 服务器进行身份验证。

<a id="installation-1"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-auth-ldap`
- Angie PRO：`angie-pro-module-auth-ldap`

<a id="loading-the-module-1"></a>

## 加载模块

在 `main{}` 上下文中加载模块：

```nginx
load_module modules/ngx_http_auth_ldap_module.so;
```

<a id="configuration-example-79"></a>

## 配置示例

```nginx
http {
    ldap_server test1 {
        url ldap://192.168.0.1:3268/DC=test,DC=local?sAMAccountName?sub?(objectClass=person);
        binddn "TEST\\LDAPUSER";
        binddn_passwd LDAPPASSWORD;
        group_attribute uniquemember;
        group_attribute_is_dn on;
        require valid_user;
    }

    ldap_server test2 {
        url ldap://192.168.0.2:3268/DC=test,DC=local?sAMAccountName?sub?(objectClass=person);
        binddn "TEST\\LDAPUSER";
        binddn_passwd LDAPPASSWORD;
        group_attribute uniquemember;
        group_attribute_is_dn on;
        require valid_user;
    }

    server {
        listen       8000;
        server_name  localhost;

        auth_ldap "Forbidden";
        auth_ldap_servers test1;
        auth_ldap_servers test2;

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

<a id="additional-information-1"></a>

## 其他信息

详细文档和源代码可在此处获取：
[https://github.com/kvspb/nginx-auth-ldap](https://github.com/kvspb/nginx-auth-ldap)


# https://cn.angie.software/angie/docs/installation/external-modules/auth-pam.md

<!-- review: finished -->

<a id="external-auth-pam"></a>

# Auth PAM

该模块添加了对 PAM 身份验证的支持。

<a id="installation-2"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-auth-pam`
- Angie PRO：`angie-pro-module-auth-pam`

<a id="loading-the-module-2"></a>

## 加载模块

在 `main{}` 上下文中加载模块：

```nginx
load_module modules/ngx_http_auth_pam_module.so;
```

<a id="configuration-example-80"></a>

## 配置示例

```nginx
location /secure {
    auth_pam              "Secure Zone";
    auth_pam_service_name "angie";
}
```

例如，要在 LDAP 服务器上对用户进行身份验证（使用 `pam_ldap.so` 模块），`/etc/pam.d/angie` 文件可能包含以下内容：

```none
auth    required     /lib/security/pam_ldap.so
account required     /lib/security/pam_ldap.so
```

<a id="additional-information-2"></a>

## 附加信息

详细文档和源代码可在以下位置获取：
[https://github.com/sto/ngx_http_auth_pam_module](https://github.com/sto/ngx_http_auth_pam_module)


# https://cn.angie.software/angie/docs/installation/external-modules/auth-spnego.md

<!-- review: finished -->

<a id="external-auth-spnego"></a>

# Auth SPNEGO

该模块提供对 SPNEGO 的支持。
目前仅支持通过 GSSAPI 进行 Kerberos 身份验证。

<a id="installation-3"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-auth-spnego`
- Angie PRO:`angie-pro-module-auth-spnego`

<a id="loading-the-module-3"></a>

## 加载模块

在 `main{}` 上下文中加载模块:

```nginx
load_module modules/ngx_http_auth_spnego_module.so;
```

<a id="additional-information-3"></a>

## 其他信息

详细文档和源代码可在以下位置获取:
[https://github.com/stnoonan/spnego-http-auth-nginx-module](https://github.com/stnoonan/spnego-http-auth-nginx-module)


# https://cn.angie.software/angie/docs/installation/external-modules/auth-totp.md

<!-- review: finished -->

<a id="external-auth-totp"></a>

# Auth TOTP

该模块实现基于时间的一次性密码 (TOTP) 算法，并提供短时有效的一次性密码机制。

特性：

- 使用 TOTP 的标准 HTTP 认证。
- 在 TOTP 过期后基于 cookie 跟踪已认证客户端。
- 可配置的密钥、时间基准、时间步长和截断长度，用于生成 TOTP。
- 可配置的 TOTP 校验时间窗口。

<a id="installation-106"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-auth-totp`
- Angie PRO：`angie-pro-module-auth-totp`

<a id="loading-the-module-106"></a>

## 加载模块

要使用该模块，请在 `main{}` 上下文中加载它：

```nginx
load_module modules/ngx_http_auth_totp_module.so;
```

<a id="configuration-example-106"></a>

## 配置示例

```nginx
server {
    listen 80;

    location /protected {
        auth_totp_realm "Protected";
        auth_totp_file /etc/angie/totp.conf;
        auth_totp_length 8;
        auth_totp_reuse off;
        auth_totp_skew 1;
        auth_totp_step 1m;
        auth_totp_cookie "totp-session";
        auth_totp_expiry 1d;
    }
}
```

<a id="additional-information-106"></a>

## 其他信息

详细文档和源代码可在以下位置获取：
[https://github.com/61131/nginx-http-auth-totp](https://github.com/61131/nginx-http-auth-totp)


# https://cn.angie.software/news/integrations/bezopastnost-configuracii-angie-pro-kontroliruet-x-config.md

# X-Config负责监控Angie PRO配置的安全性

*08.02.2024*

Angie PRO的安全配置标准将使客户能够自动监控Web服务器设置，接收按优先级排序的漏洞识别报告，并提供修复建议。

俄罗斯现代信息安全软件产品开发商Spacebit已将Angie PRO Web服务器添加到其配置安全由X-Config保障的软件列表中。

X-Config系统旨在检测和消除软件配置文件中的漏洞。X-Config允许对系统和应用软件配置的整个管理过程进行结构化，从IT基础设施分析到监控已识别漏洞的实际修复，并使设置符合安全配置的最佳实践和监管要求。

Spacebit开发的Angie PRO安全配置标准将使客户能够自动监控Web服务器设置，接收按优先级排序的漏洞识别报告，并提供修复建议。得益于灵活的配置机制，信息安全专家可以对标准进行修改并制定企业安全配置策略。使用X-Config将显著提高Angie PRO处理、负载均衡和代理事务的基础设施的信息安全水平，这对于具有关键信息基础设施和高负载基础设施的企业尤为重要。

"在Web服务器遭受攻击密度增加的背景下，其配置的安全性已成为组织网络安全的基本要素之一。考虑到采用经认证的俄罗斯基础设施软件替代品的趋势，为Angie PRO Web服务器开发安全配置标准是保护俄罗斯基础设施的重要方面，"Spacebit的X-Config产品经理Valery Ledovskoy如是说。


# https://cn.angie.software/angie/docs/installation/external-modules/brotli.md

<!-- review: finished -->

<a id="external-brotli"></a>

# Brotli

这是一组两个模块:

- `ngx_brotli_filter` — 用于即时压缩响应。
- `ngx_brotli_static` — 用于提供预压缩文件。

<a id="installation-4"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-brotli`
- Angie PRO:`angie-pro-module-brotli`

<a id="loading-modules"></a>

## 加载模块

在 `main{}` 上下文中加载模块:

```nginx
load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;
```

<a id="example-configuration-for-dynamic-compression"></a>

## 动态压缩的配置示例

```nginx
server {
    listen 80 default_server;
    brotli on;
    brotli_comp_level 1;
    brotli_types text/plain text/css;

    location / {
        root /usr/share/angie/html;
        index index.html;
    }
}
```

<a id="preparing-for-demonstration"></a>

## 演示准备

首先,让我们放置测试文件 `war-and-peace.txt`:

```console
$ ls -l /usr/share/angie/html/

  total 3292
  -rw-r--r-- 1 root root     497 Feb 13 07:40 50x.html
  -rw-r--r-- 1 root root     543 Feb 13 07:40 index.html
  -rw-r--r-- 1 root root 3359405 Feb 26 12:47 war-and-peace.txt
```

```console
$ mkdir tmp
```

请求压缩文件:

```console
$ curl -s -H 'Accept-encoding: br' -o tmp/war-and-peace.br localhost/war-and-peace.txt
```

```console
$ ls -l tmp/

  total 1092
  -rw-r--r-- 1 asv asv 1115616 Feb 26 16:52 war-and-peace.br
```

<a id="example-configuration-for-serving-pre-compressed-files"></a>

## 提供预压缩文件的配置示例

```nginx
server {
    listen 80 default_server;

    brotli_static on;
    brotli_types text/plain text/css;

    location / {
        root /usr/share/angie/html;
        index index.html;
    }
}
```

<a id="moving-the-pre-compressed-file"></a>

## 移动预压缩文件

```console
$ sudo mv tmp/war-and-peace.br /usr/share/angie/html/war-and-peace.txt.br

$ ls -l /usr/share/angie/html/

  total 4384
  -rw-r--r-- 1 root root     497 Feb 13 07:40 50x.html
  -rw-r--r-- 1 root root     543 Feb 13 07:40 index.html
  -rw-r--r-- 1 root root 3359405 Feb 26 12:47 war-and-peace.txt
  -rw-r--r-- 1 root root 1115616 Feb 26 16:57 war-and-peace.txt.br
```

请求压缩文件:

```console
$ curl -s -H 'Accept-encoding: br' -o tmp/war-and-peace.br localhost/war-and-peace.txt
```

```console
$ ls -l tmp/

  total 1092
  -rw-r--r-- 1 asv asv 1115616 Feb 26 17:13 war-and-peace.br
```

<a id="combining-dynamic-and-static-compression"></a>

## 组合动态和静态压缩

在一个配置中,可以组合使用动态压缩(`brotli on`)和静态选择(`brotli_static on`)。在这种情况下,系统将首先查找相应的静态压缩文件。如果找不到这样的文件,将对请求中指定的文件进行动态压缩。

<a id="additional-information-4"></a>

## 附加信息

指令的完整文档和源代码可在以下位置获取:
[https://github.com/google/ngx_brotli](https://github.com/google/ngx_brotli)。


# https://cn.angie.software/vacancies/business-assistant.md

# 商务助理

我们是 Angie Software 团队。公司的核心成员是参与了 nginx 早期开发的资深工程师，他们如今正在打造 nginx 的演进继任者——Angie。我们的产品已经在全球范围内获得越来越多的认可，我们也为自己设定了一个雄心勃勃的目标：超越 F5、Citrix、Radware 这样的行业巨头。

我们的文化是非正式的、扁平的：大家平等交流，没有官僚作风，也没有多余的繁文缛节。决策迅速做出，论据比头衔更重要。

## 您将做什么：

- 参与公司战略项目的落地执行；
- 根据总经理的要求收集、分析并整理信息；
- 撰写分析简报；
- 编写项目进展报告；
- 制作演示文稿、报告以及其他材料；
- 跟进总经理交办的任务与指示的执行情况；
- 保障总经理与各部门之间的高效沟通；
- 规划并协调总经理的工作日程；
- 组织各类会议和团队活动；
- 与公司各层级员工保持有效协作。

## 我们想招的人：

- 拥有至少 3 年商务助理、私人助理或运营经理岗位的工作经验；
- 精通文书工作和商务沟通礼仪；
- 熟练使用电脑（MS Office: Word, Excel, PowerPoint）；
- 善于处理大量信息，并能在多任务并行的状态下高效推进工作；
- 具备出色的规划、组织与跟进控制能力；
- 善于团队协作，能够与公司不同部门顺畅对接；
- 拥有全流程项目协调经验，能够从零搭建流程或对现有流程进行优化改造。

## 我们提供：

- 真正影响一款世界级产品的机会，看到您的决策落地，而不必承受大公司的惯性；
- 在一支业内公认的专家团队中工作，团队重视专业能力、主动性和担当；
- 扁平结构，您的声音真正被重视，官僚作风不复存在；
- 有竞争力的薪资、补充医疗保险、报销培训和会议费用——我们支持您的职业成长；
- 已认证的 IT 企业资质和透明的工作条件。

**工作形式：** 混合办公或全坐班（可商议），萨维奥洛夫斯卡娅（Савёловская）地铁站，Factoria 商务中心。

如果您感兴趣，请将英文简历发送至 [hr@wbsrv.ru](mailto:hr@wbsrv.ru)。

#### NOTE
我们仅接受英文简历，请用英文提交您的简历。


# https://cn.angie.software/angie/docs/installation/external-modules/cache-purge.md

<!-- review: finished -->

<a id="external-cache-purge"></a>

# 缓存清除

允许清除缓存内容。

<a id="installation-5"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie: `angie-module-cache-purge`
- Angie PRO: `angie-pro-module-cache-purge`

<a id="loading-the-module-4"></a>

## 加载模块

在 `main{}` 上下文中加载模块:

```nginx
load_module modules/ngx_http_cache_purge_module.so;
```

<a id="configuration-example-81"></a>

## 配置示例

```nginx
log_format test_cache '[$time_local] "$request" '
                      '$status $body_bytes_sent rt="$request_time" '
                      'ucs="$upstream_cache_status" us="$upstream_status" '
                      'ubr=$upstream_bytes_received';

proxy_cache_path /var/cache/angie/cache keys_zone=cache_zone:10m;

server {
    listen 80 default_server;

    location / {
        access_log /var/log/angie/cache-access.log test_cache;
        proxy_pass http://127.0.0.1:8080;

        proxy_cache cache_zone;
        proxy_cache_valid 10m;
        proxy_cache_key $uri$is_args$args;
        proxy_cache_purge PURGE from 127.0.0.1;
    }
}
```

<a id="preparing-for-demonstration-1"></a>

## 演示准备

从服务器请求文件:

```console
$ curl -s -o testf1.txt http://127.0.0.1/storage/testf1.txt
```

检查缓存(MISS — 文件未在缓存中找到):

```console
[05/Mar/2025:17:44:24 +0300] "GET /storage/testf1.txt HTTP/1.1" 200 519 rt="0.001" ucs="MISS" us="200" ubr=752
```

重新请求(HIT — 文件从缓存中提供):

```console
$ curl -s -o testf1.txt http://127.0.0.1/storage/testf1.txt
```

```console
[05/Mar/2025:17:46:02 +0300] "GET /storage/testf1.txt HTTP/1.1" 200 519 rt="0.000" ucs="HIT" us="-" ubr=-
```

<a id="clearing-the-cache"></a>

## 清除缓存

```console
$ curl -X PURGE http://127.0.0.1/storage/*

<html><head><title>Successful purge</title></head><body bgcolor="white"><center><h1>Successful purge</h1><p>Key : /storage/*</p></center></body></html>
```

清除缓存后请求文件(MISS — 文件再次加载):

```console
$ curl -s -o testf1.txt http://127.0.0.1/storage/testf1.txt
```

```console
[05/Mar/2025:17:52:05 +0300] "GET /storage/testf1.txt HTTP/1.1" 200 519 rt="0.002" ucs="MISS" us="200" ubr=752
```

<a id="configuration-example-for-a-separate-cache-clearing-location"></a>

## 单独缓存清除位置的配置示例

```nginx
proxy_cache_path /var/cache/angie/cache keys_zone=cache_zone:10m;

map $uri $wpurgeuri {
    "~/purge(?<wpurge>/.*)" $wpurge;
    default $uri;
}

server {
    listen 80 default_server;

    location / {
        access_log /var/log/angie/cache-access.log test_cache;
        proxy_pass http://127.0.0.1:8080;

        proxy_cache cache_zone;
        proxy_cache_valid 10m;
        proxy_cache_key $uri$is_args$args;
    }

    location /purge {
        allow 127.0.0.1;
        deny all;
        proxy_cache_purge cache_zone $wpurgeuri$is_args$args;
    }
}
```

在这种情况下清除缓存的请求:

```console
$ curl -X PURGE http://127.0.0.1/purge/storage/*
```

<a id="additional-information-5"></a>

## 附加信息

指令的完整文档和源代码可在以下位置获取:
[https://github.com/nginx-modules/ngx_cache_purge](https://github.com/nginx-modules/ngx_cache_purge)


# https://cn.angie.software/angie/docs/installation/external-modules/cgi.md

<!-- review: finished -->

<a id="external-cgi"></a>

# CGI

该模块添加了对 CGI 的支持。

需要注意的是,CGI **不** 适用于:

- 高 QPS;
- 大流量;
- 高并发。

<a id="installation-6"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-cgi`
- Angie PRO:`angie-pro-module-cgi`

<a id="loading-the-module-5"></a>

## 加载模块

在 `main{}` 上下文中加载模块:

```nginx
load_module modules/ngx_http_cgi_module.so;
```

<a id="configuration-example-82"></a>

## 配置示例

```nginx
server {
    listen 80;

    root /usr/share/angie/html;
    index index.html index.htm;

    location /cgi {
        alias /usr/share/angie/cgi-bin;
        cgi on;
    }
}
```

<a id="test-script"></a>

## 测试脚本

一个示例测试可执行脚本 `test.sh`:

```bash
#!/bin/sh
echo "Content-Type: text/plain" # Add header to the response
echo "" # Separator between headers and body of the response

# Environment variables
echo "query string: $QUERY_STRING"
echo "server addr: $SERVER_ADDR"
echo "server port: $SERVER_PORT"

# Request headers via environment variables
echo "http host: $HTTP_HOST"
echo "http accept: $HTTP_ACCEPT"
echo "http Some-Field: $HTTP_SOME_FIELD"

body=$(cat) # Reads the request body into a variable
echo "Request body: $body"
```

<a id="placing-the-script"></a>

## 放置脚本

根据配置,脚本必须放置在 `/usr/share/angie/cgi-bin/` 目录中。
该文件必须具有读取和执行权限。

<a id="example-of-request-execution"></a>

## 请求执行示例

```console
$ curl  -H 'Some-Field:some text' -d '{"key1":"value1", "key2":"value2"}' -i \
  'http://127.0.0.1/cgi/hello.sh?a=valueA&b=valueB'

HTTP/1.1 200 OK
Server: Angie/|angie_version|
Date: |sampledatelong| 19:15:35 GMT
Transfer-Encoding: chunked
Connection: keep-alive
Content-Type: text/plain

query string: a=valueA&b=valueB
server addr: 127.0.0.1
server port: 80
http host: 127.0.0.1
http accept: */*
http Some-Field: some text
Request body: {"key1":"value1", "key2":"value2"}
```

<a id="additional-information-6"></a>

## 其他信息

详细文档和源代码可在以下位置获取:
[https://github.com/pjincz/nginx-cgi](https://github.com/pjincz/nginx-cgi)


# https://cn.angie.software/angie/docs/configuration/cluster.md

<!-- review: finished -->

<a id="cluster-setup"></a>

# Angie 集群设置

本指南介绍了创建具有自动配置同步和虚拟 IP 地址故障转移的容错 Angie 集群的过程。

<a id="cluster-preparation"></a>

## 准备集群节点以进行同步

第一步是通过配置用户账户并确保服务器之间的安全访问来准备所有集群节点。

<a id="users-permissions"></a>

### 配置用户和访问权限

在所有节点上创建一个用户(例如,:samp:angie-ha-sync)并赋予 `sudo` 权限:

```console
$ sudo adduser angie-ha-sync
```

如有必要,设置密码:

```console
$ sudo passwd angie-ha-sync
```

#### NOTE
在某些操作系统中(例如 Alt Linux),
您应该将用户添加到 `wheel` 组:

```console
$ sudo usermod -a -G wheel angie-ha-sync
```

在 Astra Linux 中启用 MAC 时要使用 `rsync`,请设置
正确的完整性级别:

```console
$ sudo pdpl-user -i 63 angie-ha-sync
```

配置无密码 sudo:

```console
$ echo "angie-ha-sync ALL=(ALL:ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers
```

在主节点上,创建 SSH 密钥并将其复制到备份节点:

```console
$ su - angie-ha-sync
$ ssh-keygen -t rsa
$ ssh-copy-id angie-ha-sync@node2_hostname
```

#### WARNING
在复制 SSH 密钥之前,请确保
`/etc/ssh/sshd_config` 文件中有以下选项:

`PasswordAuthentication yes`

设置基于密钥的访问后,将该值设置为 `no` 以提高
安全性。

#### NOTE
对于 Angie 配置的交叉同步,请将用户密钥
复制到所有节点:

```console
$ scp -p ~angie-ha-sync/.ssh/id_rsa angie-ha-sync@node2_hostname:.ssh/
```

<a id="install"></a>

## 安装 Angie 和 angie-ha-sync

准备好节点后,您需要安装主要的集群组件:
Angie 和配置同步包。

根据您的系统包的说明在所有节点上配置仓库:

- [Angie 说明](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)
- [Angie PRO 说明](https://cn.angie.software//angie/docs/installation/pro_packages.md#pro-packages)

<a id="install-ha-sync"></a>

### 安装 angie-ha-sync

配置同步模块在以下包中可用:

- Angie:`angie-ha-sync`
- Angie PRO:`angie-pro-ha-sync`

#### NOTE
在干净的系统上安装此包时,
相应的 `angie` 或 `angie-pro` 包
也将作为依赖项安装。

在所有节点上,使用您的操作系统包管理器安装该包,例如:

```console
$ sudo {apk|apt|pkg|yum|zypper} {add|install} angie-pro-ha-sync
```

<a id="sync"></a>

## 配置配置同步

下一步是设置集群节点之间配置文件的自动同步。

#### NOTE
同步原则:

- 通过 `rsync` 执行同步。
- 仅在 Angie 服务运行时发生。
- 手动执行(命令 `angiehasync -Sd`)。
- 单向工作:从主节点到备份节点。
- `rsync` 以守护进程模式运行。

<a id="rsync"></a>

### 配置 `rsync`

在节点上创建 `rsync` 配置(`/etc/rsyncd.conf`):

```ini
[angie] # Angie 配置目录
    path = /etc/angie
# 用于同步的用户
    uid = angie-ha-sync
# 用户组
    gid = angie-ha-sync
# 允许连接的 IP 或子网
    hosts allow = 10.21.8.0/24
# 拒绝所有其他
    hosts deny = *
```

根据操作系统,启动守护进程:

```console
$ sudo service rsyncd start # 或 $ sudo service rsync start
```

#### NOTE
对于某些系统,有现成的说明:

- [Alt](https://www.altlinux.org/Настройка_rsync-сервера)
- [Astra](https://wiki.astralinux.ru/pages/viewpage.action?pageId=41191598#id-Архивированиеивосстановлениефайловссохранениеммандатныхатрибутов-RSYNC)

<a id="sync-config"></a>

### 配置同步文件

编辑 `/etc/angiehasync/angiehasync.conf`:

```ini
M_NODE="<node1_hostname>"            # 此节点的主机名或 IP
TARGET_HOSTS="<node2_hostname>"      # 用于同步的主机/IP 列表(空格分隔)。
                                     # 在备份节点上可以省略。
SSH_USER="user"                      # 用于同步的用户(具有管理员权限)
SSH_ID="/home/$SSH_USER/.ssh/id_rsa" # 私钥路径
```

#### NOTE
对于交叉同步,
在所有节点上填写 `TARGET_HOSTS` 列表;
但是,不要在列表中包含当前正在配置的节点。

<a id="healthcheck"></a>

### 配置 Angie 的健康检查

在 Angie 配置中添加健康检查块
(`/etc/angie/angie.conf`):

```ini
server {

    listen unix:/tmp/angie_hcheck.sock; # 用于检查的 Unix 套接字
    access_log off;
    error_log /dev/null;
    default_type text/plain;
    return 200 'ok\n';
}
```

启动 Angie:

```console
$ sudo angie -t && sudo service angie start
```

启动同步:

```console
$ sudo angiehasync -Sd
```

#### NOTE
该脚本将自动检查配置,与所有节点执行同步,并应用它。

<a id="keepalived"></a>

## 配置 Keepalived

为了在集群节点之间实现自动故障转移,使用 Keepalived —
一个用于管理虚拟 IP 地址(VIP)的服务。

#### NOTE
如果未安装 `keepalived` 包 — 请安装它:

```console
$ sudo {apk|apt|pkg|yum|zypper} {add|install} keepalived
```

要将进程绑定到非本地 IP 地址,
允许系统执行相应的操作:

```console
$ sudo sysctl -w net.ipv4.ip_nonlocal_bind=1
```

更多详情:
[https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt#ip_nonlocal_bind](https://www.kernel.org/doc/Documentation/networking/ip-sysctl.txt#ip_nonlocal_bind)

假设 VIP `10.21.11.230`
分配给主节点(`10.21.8.26`)
或备份节点(`10.21.8.27`)。

如果 Angie 监听此 VIP(`listen 10.21.11.230:80;`)
但地址尚未分配,
没有 `ip_nonlocal_bind` 参数,Angie 将无法启动。

<a id="keepalived-config"></a>

### Keepalived 配置

在主节点上(`/etc/keepalived/keepalived.conf`):

```ini
global_defs {
    enable_script_security
}

vrrp_script angie_check {
    script "/usr/bin/curl -s --connect-timeout 5 -A 'angie_hcheck_script'
    --no-buffer -XGET --unix-socket /tmp/angie_hcheck.sock http://hcheck/"
    interval 5 user angie
}

vrrp_instance angie {
    state MASTER interface enp0s2 virtual_router_id 254 priority 100
    advert_int 2 unicast_src_ip 10.21.8.26

    unicast_peer {
        10.21.8.27
    }

    virtual_ipaddress {
        10.21.11.230
    } track_script {
        angie_check
    }
}
```

在备份节点上:

```ini
global_defs {
    enable_script_security
}

vrrp_script angie_check {
    script "/usr/bin/curl -s --connect-timeout 5 -A 'angie_hcheck_script'
    --no-buffer -XGET --unix-socket /tmp/angie_hcheck.sock http://hcheck/"
    interval 5 user angie
}

vrrp_instance angie {
    state MASTER interface enp0s2 virtual_router_id 254 priority 99
    advert_int 2 unicast_src_ip 10.21.8.27

    unicast_peer {
        10.21.8.26
    }

    virtual_ipaddress {
        10.21.11.230
    } track_script {
        angie_check
    }
}
```

#### NOTE
在 `vrrp_instance angie` 部分中,设置以下值:

- `unicast_src_ip` — 当前节点的 IP
- `unicast_peer` — 相邻节点的 IP
- `virtual_ipaddress` — 虚拟 IP(VIP)
- `interface` — 网络接口

启动服务:

```console
$ sudo keepalived -t && sudo service keepalived start
```

<a id="keepalived-details"></a>

### Keepalived 配置详解

让我们详细研究 Keepalived 配置的主要元素,
以了解集群的运行原理。

配置包含两个部分:

- `global_defs` — 全局设置
- `vrrp_instance` — VRRP 参数(VIP 切换)

主要元素:

- `enable_script_security` — 允许执行健康检查脚本
- `vrrp_script` — Angie 健康检查脚本
- `state MASTER` — 初始节点状态
- `priority` — 优先级(MASTER 角色分配给优先级最高的节点)
- `advert_int` — VRRP 通告间隔
- `unicast_src_ip` — 当前节点 IP
- `unicast_peer` — 邻居节点 IP
- `virtual_ipaddress` — VIP 地址
- `track_script` — 通过健康检查脚本进行可用性监控

#### NOTE
如果原主节点恢复,
它将重新获得 MASTER 角色(因为优先级更高)。
要禁用故障恢复,请使用 `nopreempt` 参数:

```none
vrrp_instance angie {
    ... nopreempt
}
```

<a id="testing"></a>

## 测试集群运行

完成配置后,需要测试集群运行情况
并确保节点之间正确切换。

检查 VIP 状态:

```console
$ ip addr show enp0s2 | grep "10.21.11.230"
```

测试容错能力:

在主节点上停止 Angie:

```console
$ sudo service angie stop
```

检查 VIP 是否转移到备份节点:

```console
$ ip addr show enp0s2 | grep "10.21.11.230"
```

再次在主节点上启动 Angie:

```console
$ sudo service angie start
```

此后,VIP 应该返回到主节点。


# https://cn.angie.software/angie/docs/installation/external-modules/combined-upstreams.md

<!-- review: finished -->

<a id="external-combined-upstreams"></a>

# Combined Upstreams

该模块允许将多个服务器组组合为一个。

它引入了 `add_upstream`、`combine_server_singlets` 和
`extend_single_peers` 指令，这些指令可在 `upstream` 配置块内使用；
同时新增 `upstrand` 配置块，用于创建更高层级的 `upstream` 块。
此外，引入 `dynamic_upstrand` 指令，用于在运行时选择 `upstream` 块。

<a id="installation-107"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-combined-upstreams`
- Angie PRO：`angie-pro-module-combined-upstreams`

<a id="loading-the-module-107"></a>

## 加载模块

要使用该模块，请在 `main{}` 上下文中加载它：

```nginx
load_module modules/ngx_http_combined_upstreams_module.so;
```

<a id="additional-information-107"></a>

## 其他信息

详细文档和源代码可在以下位置获取：
[https://github.com/lyokha/nginx-combined-upstreams-module](https://github.com/lyokha/nginx-combined-upstreams-module)

模块指令的配置示例与详细说明：

- [http://lin-techdet.blogspot.com/2011/10/nginx.html](http://lin-techdet.blogspot.com/2011/10/nginx.html)
- [http://lin-techdet.blogspot.com/2015/12/nginx.html](http://lin-techdet.blogspot.com/2015/12/nginx.html)


# https://cn.angie.software/company.md

# 关于我们

我们是一家俄罗斯IT公司，从事软件开发工作。
我们公司由前NGINX员工创立，开发了Angie——
一个高性能且可扩展的Web服务器，它是nginx的一个分支，
旨在超越原版的功能，成为集群软件解决方案市场中备受青睐的
Web服务器。

目前，我们正在积极开发基于Angie的一系列解决方案，
根据市场需求添加新功能。

我们的产品：

- Angie及其商业版本Angie PRO。与nginx相比，它们显著提高了
  容错能力、性能和运行条件，"Web Server"公司的
  [技术支持](https://cn.angie.software//service.md) 专家将协助设置基于Angie的
  解决方案和nginx的不间断运行。
- Angie Ingress Controller（ANIC）。这是一个用于管理
  Kubernetes中容器化应用程序流量的解决方案。
  ANIC基于Angie PRO的功能，允许使用俄罗斯解决方案构建安全、
  可扩展、高性能的环境，并提供专业的迁移服务和俄语技术支持。
- Angie Application Delivery Controller（Angie ADC）目前正在开发中。
  它是一个"负载均衡系统"类别的盒装解决方案，以虚拟设备的形式提供
  （未来将提供硬件-软件解决方案），解决俄罗斯市场在这一领域的
  多样化企业需求。

Angie PRO、ANIC和Angie ADC已被列入俄罗斯电子计算机和数据库软件统一注册表。
公司的产品正在与国产系统Astra Linux、Alt、RED OS和ROSA进行
兼容性测试。

我们的服务：

- [标准技术支持](https://cn.angie.software//support/index.md)；
- [企业技术支持](https://cn.angie.software//support/enterprise.md)；
- 高素质的 [专业服务](https://cn.angie.software//professional-service.md)，
  用于在客户基础设施中进行我们产品的迁移、
  适配和优化。

我们与合作伙伴一起开发培训课程和认证项目，
用于我们产品的使用。

关于我们的媒体报道：

- [Kommersant，nginx在俄罗斯重建。](https://www.kommersant.ru/doc/5634072)
- [Vedomosti，第一个俄罗斯Web服务器被列入国产软件注册表。](https://www.vedomosti.ru/technology/articles/2023/05/24/976527-pervii-rossiiskii-veb-server-vnesen-v-reestr-otechestvennogo-po?shared_token=cbe20f6feeee8a5bcf52f077d2d6ad62b66e3917)
- [Habr，"Web Server"推出ANIC——Kubernetes网络流量管理软件。](https://habr.com/news/744654/)
- [开发者市场：如何发展俄罗斯的GitHub。](https://www.forbes.ru/mneniya/491830-marketplejs-dla-razrabotcikov-kak-razvivat-rossijskij-github)
- [开源代码的封闭区域：中国和俄罗斯如何发展开源。](https://www.forbes.ru/tekhnologii/495635-zakrytye-zony-otkrytogo-koda-kak-kitaj-i-rossia-razvivaut-open-source)
- [我们的首席开发者Valentin Bartenev在Habr上的采访。](https://habr.com/articles/774274/)
- [Valentin Bartenev在HighLoad的演讲（YouTube）。](https://www.youtube.com/watch?v=CKHNqMawUiE)


# https://cn.angie.software/angie/docs/configuration/configfile.md

<!-- review: finished -->

<a id="configfile"></a>

# 配置文件

Angie 使用基于文本的配置文件。默认情况下，该文件名为
`angie.conf`，根据 [--conf-path](https://cn.angie.software//angie/docs/installation/sourcebuild.md#paths) 构建参数的位置，通常位于 `/etc/angie` 目录下。

配置文件通常由以下上下文组成：

- [events](https://cn.angie.software//angie/docs/configuration/modules/core.md#events) – 一般连接处理
- [http](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#d-http) – HTTP 流量
- [mail](https://cn.angie.software//angie/docs/configuration/modules/mail/index.md#m-mail) – 邮件流量
- [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-stream) – TCP 和 UDP 流量
- [wasm_modules](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#wasm-modules) – WASM 运行时

放置在这些上下文之外的指令被视为在 `main` 上下文中：

```nginx
user angie; # 在 'main' 上下文中的指令

events {

    # 连接处理的配置
}

http {

    # 特定于 HTTP 的配置，影响所有虚拟服务器

    server {

        # HTTP 虚拟服务器 1 的配置
        location /one {

            # 处理以 '/one' 开头的 URI 的配置
        }
        location /two {

            # 处理以 '/two' 开头的 URI 的配置
        }
    }

    server {

        # HTTP 虚拟服务器 2 的配置
    }
}

stream {

    # 特定于 TCP/UDP 的配置，影响所有虚拟服务器
    server {

        # TCP 虚拟服务器 1 的配置
    }
}
```

为了简化配置管理，我们建议在主 `angie.conf` 文件中使用 [include](https://cn.angie.software//angie/docs/configuration/modules/core.md#include) 指令引用特定功能文件的内容：

```nginx
include /etc/angie/http.d/*.conf;
include /etc/angie/stream.d/*.conf;
```

<a id="inheritance"></a>

## 继承

一般来说，子上下文（包含在另一个上下文中的上下文，被视为其父上下文）继承在父级定义的指令设置。一些指令可以出现在多个上下文中；在这种情况下，您可以通过在子上下文中包含该指令来覆盖从父级继承的设置。

<a id="syntax"></a>

## 语法

<a id="measurement-units"></a>

### 测量单位

可以使用以下单位来指定大小：

| 无后缀      | 字节   |
|----------|------|
| `k`, `K` | 千字节  |
| `m`, `M` | 兆字节  |
| `g`, `G` | 吉字节  |

例如：`1024`、`8k`、`1m`、`16g`。

时间间隔可以以毫秒、秒、分钟、小时、天等来指定，使用以下后缀：

| `ms`   | 毫秒            |
|--------|---------------|
| `s`    | 秒             |
| `m`    | 分钟            |
| `h`    | 小时            |
| `d`    | 天             |
| `w`    | 周             |
| `M`    | 月（假定等于 30 天）  |
| `y`    | 年（假定等于 365 天） |

多个单位可以通过按顺序从最重要到最不重要指定它们来组合成一个值，选用空格分隔。例如，`"1h 30m"` 指定的持续时间与 `"90m"` 或 `"5400s"` 相同。没有后缀的值被解释为秒。建议始终指定后缀。

某些时间间隔只能以秒级精度指定。

<a id="directives"></a>

### 指令

每个指令由一个名称和一组参数组成。
如果指令的任何部分需要包含空格，
它应被引号括起来或转义空格：

```nginx
add_header X-MyHeader "foo bar";
add_header X-MyHeader foo\ bar;
```

如果命名参数需要空格，并且您使用了引号，
则其名称也必须用引号括起来：

```nginx
server example.com "sid=server 1";
```

<a id="configure-hashes"></a>

## 设置哈希

为了有效处理静态数据集，例如服务器名称、[map](https://cn.angie.software//angie/docs/configuration/modules/http/http_map.md#id3) 指令值、MIME 类型和请求头名称，Angie 使用哈希表。在启动和每次重新配置时，Angie 确定这些哈希表的最佳大小，以确保存储具有相同哈希值的键的桶大小不超过配置参数（hash bucket size）。表的大小以桶为单位测量，并调整直到超过 hash max size 参数。大多数哈希表都有相应的指令来调整这些参数，例如 [server_names_hash_max_size](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-names-hash-max-size) 和 [server_names_hash_bucket_size](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-names-hash-bucket-size) 用于服务器名称。

hash bucket size 参数与处理器的缓存行大小对齐。这种对齐提高了现代处理器上键搜索的效率，减少了内存访问的次数。如果 hash bucket size 等于一个缓存行大小，则在键搜索期间的最大内存访问次数将为两个：一个用于计算桶地址，另一个用于在桶内搜索。因此，如果 Angie 指示应该增加 hash max size 或 hash bucket size，则首先增加 hash max size。

<a id="configfile-reloading"></a>

### 重新加载配置

要应用对配置文件的更改，必须重新加载它。您可以先通过配置语法检查重启 Angie 进程：

```console
$ sudo angie -t && sudo service angie restart
```

或者，您可以重新加载服务，以在不中断当前请求处理的情况下应用新配置：

```console
$ sudo angie -t && sudo service angie reload
```


# https://cn.angie.software/angie/docs/configuration.md

<!-- review: finished -->

<a id="configuration"></a>

# 配置

本页面包含用于配置 Angie 的文章、参考、索引和说明。

## 一般信息

这些文章涵盖 Angie 的安装和配置、
启动和停止 Web 服务器、管理服务器,
以及请求处理和与其他服务器交互的各个方面。

* [配置](https://cn.angie.software//angie/docs/configuration/configfile.md)
* [管理](https://cn.angie.software//angie/docs/configuration/runtime.md)
* [连接、会话、请求、日志](https://cn.angie.software//angie/docs/configuration/processing.md)

## 参考和索引

这些摘要部分提供有关内置模块的参考信息、
它们的配置示例以及支持的指令和变量。

* [模块](https://cn.angie.software//angie/docs/configuration/modules/index.md)
* [指令](https://cn.angie.software//genindex.md)
* [变量](https://cn.angie.software//angie/docs/configuration/varindex.md)
* [NJS API 参考](https://cn.angie.software//angie/docs/configuration/njs-reference.md)

您还可以使用 [https://angie.ws/](https://angie.ws/) 上的短链接服务
快速查找单个指令和变量:

* [快速访问](https://cn.angie.software//angie/docs/configuration/quickaccess.md)

<a id="llm-resources"></a>

## 面向 AI 助手的文档

本站为每个文档页面提供机器可读的副本,以便 Claude Code、Cursor、
ChatGPT 等基于 LLM 的代理工具可以直接获取内容,而无需抓取渲染后的
HTML。

### llms.txt 与 llms-full.txt

每个语言子域名都提供一份 [llms.txt](https://llmstxt.org/) 索引
文件,其中包含项目的简短描述以及全部页面的列表(标题、绝对 URL、
摘要)。配套的 `llms-full.txt` 将所有页面的完整 Markdown 内容
拼接为一个文件,适合一次性加载到模型中:

- [https://cn.angie.software/llms.txt](https://cn.angie.software/llms.txt)
- [https://cn.angie.software/llms-full.txt](https://cn.angie.software/llms-full.txt)

上述 URL 也通过 `Llms:` 指令在
[robots.txt](https://cn.angie.software/robots.txt) 中声明,
LLM 爬虫可以自动发现它们。

### 页面的 Markdown 版本

每个 HTML 页面都有对应的 Markdown 版本。将文档页面 URL 末尾的斜杠
替换为 `.md` 即可获取其 Markdown 版本:

- HTML: [https://cn.angie.software/angie/docs/configuration/](https://cn.angie.software/angie/docs/configuration/)
- Markdown: [https://cn.angie.software/angie/docs/configuration.md](https://cn.angie.software/angie/docs/configuration.md)

Markdown 版本与 HTML 版本由相同的 reStructuredText 源文件构建,
因此内容始终保持同步。

### Context7

Angie 文档已收录于 [Context7](https://context7.com/) —— 一个
通过 MCP 服务器为 AI 代码编辑器提供最新库文档的目录。中文版
Angie 在 Context7 的页面位于
[https://context7.com/websites/cn_angie_software_angie](https://context7.com/websites/cn_angie_software_angie)。

## 说明

此处提供了配置 Angie 特定方面的分步说明。

* [配置 ACME](https://cn.angie.software//angie/docs/configuration/acme.md)
* [配置集群](https://cn.angie.software//angie/docs/configuration/cluster.md)
* [配置 OIDC](https://cn.angie.software//angie/docs/configuration/oidc.md)
* [配置 SSL](https://cn.angie.software//angie/docs/configuration/ssl.md)
* [Console Light 面板](https://cn.angie.software//angie/docs/configuration/monitoring.md)
* [自定义指标](https://cn.angie.software//angie/docs/configuration/custom-metrics.md)
* [从 nginx 迁移](https://cn.angie.software//angie/docs/configuration/migration.md)
* [Grafana 面板](https://cn.angie.software//angie/docs/configuration/grafana.md)

<a id="community-content"></a>

## 社区材料

我们收集了社区资源,这些资源将帮助您更好地理解
Angie 的配置和使用。

### 文章

- [Angie: A New NGINX Fork Developed by Some of Its Former Devs](https://linuxiac.com/angie-web-server-is-a-new-nginx-fork/)
  on Linuxiac
- [What's New in the Angie 1.9 Web Server (an nginx fork) and What to Expect from 1.10?](https://habr.com/en/articles/911444/)
  on Habr

### 课程

目前没有英文的 Angie 课程。
请参阅官方 Angie 文档和下面的实用指南。

### 实用指南

- [Migrating from Nginx to Angie: A Real-World Journey from Certbot to Built-in ACME](https://dev.to/stan-breaks/migrating-from-nginx-to-angie-a-real-world-journey-from-certbot-to-built-in-acme-7a3)
  on DEV Community

### 访谈和播客

- "NGINX is Dead? // Angie Web Server Migration Guide" by DevOps Toolbox
  ([YouTube](https://www.youtube.com/watch?v=HFCtaiJMDGg), 27.03.2026)
- "Nginx Has a BIG Problem..." by DevOps Toolbox ([YouTube](https://www.youtube.com/watch?v=acJBNVTW42I), 30.01.2026)


# https://cn.angie.software/contacts.md

# 联系方式

电话：+7 (495) 120 50 33
<br/>
邮箱：[info@wbsrv.ru](mailto:info@wbsrv.ru)
<br/>
地址：127015，莫斯科，维亚茨卡亚街，27号，7栋
<br/>
[在Telegram上支持](https://t.me/angie_support) (俄语、英语)
<br/>
[在Telegram上查看新闻](https://t.me/angie_software) (俄语)
<br/>


# https://cn.angie.software/angie/contributor-agreement.md

# 贡献者许可协议

本协议管理公司与贡献者之间的关系，双方承担协议文本中规定的权利和义务，以下称为协议：

**术语和定义**：

**贡献** 是智力活动的结果（包括但不限于源代码、设计实体、文本和文档），这些都是程序的元素。

**程序** 是公司拥有独占权的软件（计算机程序），以及此类程序的所有新（后续）版本。

**贡献者** 是，（1）如果贡献是由个人以其自身名义作出的，则是具有必要法律能力并已接受本协议所有条款的个人；（2）如果贡献是由个人代表法人实体或个体企业家作为其雇主作出的，则是适用的法人实体或个体企业家。

**公司** 是Web Server, LLC，一个根据俄罗斯联邦法律注册的法人实体（OGRN: 1227700436578），注册地址为：俄罗斯莫斯科，127015，Vyatskaya St., 27, bld. 7。

**当事方** 是协议的其中一方，即贡献者或公司。

1. 本协议的主题是贡献者授予公司在非独占、免版税、不可撤销的许可条款下使用贡献的权利，包括本协议中明确规定和说明的所有手段。

该许可的授权期限为贡献的独占权的整个持续时间，允许的地域为世界各国。

贡献可以由贡献者以任何方式（在有形媒介上、通过电子邮件的电子形式、以变更请求的形式，或使用在GitHub、GitLab或其他类似网站上使用的贡献转移系统）提供给公司。贡献应被视为在公司收到它们的日期作出。

在实际提交贡献给公司的日期，贡献者表示完全无条件地同意本协议的所有条款。

1. **公司对贡献的使用**。公司有权以以下方式使用贡献：

2.1. 在任何程序中（包括开放源代码和闭源代码）出于商业和非商业目的使用贡献；在公司拥有权利的任何其他智力活动成果中使用贡献；

2.2. 对贡献进行任何更改、删节和补充，在使用贡献时添加评论、图片或解释；

2.3. 基于贡献创建任何其他（衍生）智力活动成果；

2.4. 将贡献翻译成其他语言，包括其他编程语言；

2.5. 以任何方式分发贡献，包括直接向第三方提供贡献，以及作为任何程序的一部分，以"现状"基础提供，且不需要对其可操作性/无缺陷和错误提供任何保证；

2.6. 进行公开展示，将贡献提供给公众；

2.7. 拆解、反编译（将目标代码转换为源代码）、对贡献进行工程分析。

2.8. 在不提及作者姓名和/或笔名（匿名）的情况下使用贡献。

1. 贡献者授予公司在全球所有国家的非独占、免版税、永久、不可撤销的许可，涵盖贡献者的专利权。该许可包括贡献者持有的所有专利权。
2. **陈述**。贡献者向公司提供以下陈述，涉及公司认为对协议的执行和签订重要的事项：

4.1. 贡献者拥有签署协议所需的所有权利；

4.2. 贡献者提供给公司的贡献是由贡献者个人开发的，除非贡献的独占权由其他人（权利人）拥有，但在这些权利人的同意下，无需与权利人协调且无需向他们支付报酬即可分发，且贡献者在合法基础上使用这些贡献；

4.3. 贡献不受任何第三方权利的限制；

4.4. 贡献者已获得贡献中包含的知识产权所有者的同意（如有）以便公司按照协议中规定的所有方式使用；

4.5. 公司进一步使用贡献的形式不侵犯任何第三方知识产权或其他合法利益和权利。

1. **责任**。如果公司因使用贡献者的贡献而面临任何索赔或诉讼，贡献者同意赔偿公司可能因这些索赔或诉讼而产生的所有损失。
2. **责任限制**。贡献者向公司提供的所有贡献均为"现状"基础，且不提供任何保证。
3. **商标**。贡献者仅在获得公司事先书面同意的情况下使用公司的徽标和商标。为获得书面同意，贡献者必须向公司的电子邮箱发送信件：[legal@wbsrv.ru](mailto:legal@wbsrv.ru)。
4. **争议解决和适用法律**。本协议应根据俄罗斯联邦的法律进行管辖和解释。如果各方未能就争议问题达成一致，则该争议应受公司所在地法院的管辖，法律另有直接规定的除外。
5. 公司没有义务向贡献者提供关于贡献使用的报告。
6. **协议语言**。本协议以俄语和英语书写。

俄文版本的协议可在以下地址获取：
[https://angie.software/angie/contributor-agreement/](https://angie.software/angie/contributor-agreement/)

中文版本的协议可在以下地址获取：
[https://cn.angie.software/angie/contributor-agreement/](https://cn.angie.software/angie/contributor-agreement/)

如俄文和英文版本的协议之间存在任何不一致，以俄文条款为准。

1. **协议生效**。本协议在公司收到来自贡献者的以本协议第1条中提到的任何形式和方式的贡献时被视为生效并已由双方签署。这包括但不限于，接收贡献到公司在GitHub和/或GitLab网站上的企业账户。

Web Server, LLC.

OGRN: 1227700436578.

地址：俄罗斯莫斯科，127015，Vyatskaya St., 27, bldg. 7.

电话：+7 (495) 120 50 33.

电子邮件：[legal@wbsrv.ru](mailto:legal@wbsrv.ru).

发布日期：2023年11月08日。


# https://cn.angie.software/angie/docs/configuration/modules/core.md

<!-- review: finished -->

<a id="core"></a>

# 核心模块

该模块提供服务器基本运行所需的核心功能和配置指令,
并处理关键任务,如管理工作进程、
配置事件驱动模型、
以及处理传入的连接和请求。
它包含用于设置主进程、错误
日志记录以及在底层控制服务器行为的关键指令。

<a id="configuration-example-1-1-1-1"></a>

## 配置示例

```nginx
user www www;
worker_processes 2;

error_log /var/log/error.log info;

events {

    use kqueue; worker_connections 2048;
}
```

<a id="directives-1"></a>

## 指令

<a id="index-0"></a>

<a id="accept-mutex"></a>

### accept_mutex

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `accept_mutex` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `accept_mutex off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | events                         |

当启用 `accept_mutex` 时,
工作进程将轮流接受新连接。
如果不设置此项,所有工作进程都会收到新连接的通知,
这可能导致系统资源的低效使用,
特别是在新连接数量较少的情况下。

#### NOTE
在支持 `EPOLLEXCLUSIVE` 标志的系统上
或使用 [reuseport](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#listen) 指令时,
无需启用 `accept_mutex`。

<a id="index-1"></a>

<a id="accept-mutex-delay"></a>

### accept_mutex_delay

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `accept_mutex_delay` time;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `accept_mutex_delay 500ms;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | events                       |

如果启用了 [accept_mutex](#accept-mutex),
此指令指定工作进程在另一个工作进程正在处理新连接时,
等待继续接受新连接的最长时间。

<a id="index-2"></a>

<a id="daemon"></a>

### daemon

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `daemon` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | `daemon on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                     |

确定 Angie 是否应作为守护进程运行。
这主要在开发过程中使用。

<a id="index-3"></a>

<a id="debug-connection"></a>

### debug_connection

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `debug_connection` address | CIDR | `unix:`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | —                                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | events                                         |

为特定客户端连接启用调试日志。
其他连接将使用 [error_log](#error-log) 指令设置的日志级别。
您可以通过 IPv4 或 IPv6 地址、网络或主机名指定连接。
对于使用 UNIX 域套接字的连接,
使用 `unix:` 参数启用调试日志。

```nginx
events {

    debug_connection 127.0.0.1;
    debug_connection localhost;
    debug_connection 192.0.2.0/24;
    debug_connection ::1;
    debug_connection 2001:0db8::/32;
    debug_connection unix:;
    #  ...
}
```

#### NOTE
要使此指令生效,
必须在构建 Angie 时启用 [调试日志](https://cn.angie.software//angie/docs/troubleshooting.md#debug-logging)。

<a id="index-4"></a>

<a id="debug-points"></a>

### debug_points

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `debug_points` `abort` | `stop`;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | —                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                               |

此指令用于调试。

当发生内部错误时,
例如在工作进程重启期间发生套接字泄漏,
启用 `debug_points` 将创建核心文件 (`abort`)
或停止进程 (`stop`) 以便使用系统调试器进行进一步分析。

<a id="index-5"></a>

<a id="env"></a>

### env

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `env` variable[=value];   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `env TZ;`                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                      |

默认情况下,
Angie 会删除从其父进程继承的所有环境变量,
但 `TZ` 变量除外。
此指令允许您保留某些继承的变量、
修改它们的值或创建新的环境变量。

这些变量随后:

- 在 [可执行文件的实时升级](https://cn.angie.software//angie/docs/configuration/runtime.md#service-upgrade) 期间被继承
- 被 [Perl](https://cn.angie.software//angie/docs/configuration/modules/http/http_perl.md#http-perl) 模块使用
- 对工作进程可用

请注意,以这种方式控制系统库可能并不总是有效,
因为库通常仅在初始化期间检查变量,
而初始化发生在此指令生效之前。
`TZ` 变量始终被继承
并可供 [Perl](https://cn.angie.software//angie/docs/configuration/modules/http/http_perl.md#http-perl) 模块访问,
除非明确配置为其他方式。

示例:

```nginx
env MALLOC_OPTIONS;
env PERL5LIB=/data/site/modules;
env OPENSSL_ALLOW_PROXY_CERTS=1;
```

#### NOTE
`ANGIE` 环境变量由 Angie 内部使用,
不应由用户直接设置。

<a id="index-6"></a>

<a id="error-log"></a>

### error_log

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `error_log` file [level] [[`filter=`type:value] ...];                                                                                            |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `error_log logs/error.log error;`<br/>(路径取决于 `--error-log-path` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#paths)) |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main, http, mail, stream, server, location                                                                                                       |

配置日志记录,
允许在同一配置级别指定多个日志。
如果在 `main` 配置级别未明确定义日志文件,
将使用默认文件。

第一个参数指定存储日志的文件。
特殊值 `stderr` 选择标准错误流。
要配置到 [syslog](https://cn.angie.software//angie/docs/configuration/processing.md#syslog-logging) 的日志记录,
使用 `"syslog:"` 前缀。
要记录到 [循环内存缓冲区](https://cn.angie.software//angie/docs/troubleshooting.md#cyclic-memory-buffer),
使用 `"memory:"` 前缀后跟缓冲区大小;
这通常用于调试。

第二个参数设置日志级别,可以是以下之一:
`debug`、`info`、`notice`、`warn`、`error`、
`crit`、`alert` 或 `emerg`。
这些级别按严重性递增的顺序列出。
设置日志级别将捕获相同和更高严重性的消息:

| 设置       | 捕获的级别                                                              |
|----------|--------------------------------------------------------------------|
| `debug`  | `debug`、`info`、`notice`、`warn`、`error`、<br/>`crit`、`alert`、`emerg` |
| `info`   | `info`、`notice`、`warn`、`error`、<br/>`crit`、`alert`、`emerg`         |
| `notice` | `notice`、`warn`、`error`、<br/>`crit`、`alert`、`emerg`                |
| `warn`   | `warn`、`error`、`crit`、`alert`、`emerg`                              |
| `error`  | `error`、`crit`、`alert`、`emerg`                                     |
| `crit`   | `crit`、`alert`、`emerg`                                             |
| `alert`  | `alert`、`emerg`                                                    |
| `emerg`  | `emerg`                                                            |

如果省略此参数,
将使用 `error` 作为默认日志级别。

可选的 `filter=` 参数限制将哪些消息写入日志。
支持的过滤器有:

- `filter=file:`prefix 匹配源文件前缀(例如,
  `ngx_http_access_module.c`);
- `filter=event:`prefix 匹配事件 ID 前缀(例如,
  `http.upstream.peer`);
- `filter=tag:`tag 匹配附加到日志条目的标签。

多个 `filter=file:` 或 `filter=event:` 参数通过前缀匹配,
任何匹配都允许消息通过。多个
`filter=tag:` 参数要求所有标签都存在。
标签可以由模块自动添加(例如,
`http`、`stream`、`mail`、`upstream`、
`peer`、`subrequest`),也可以通过
[error_log_user_tag](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#error-log-user-tag) 指令添加。

#### NOTE
要使 `debug` 日志级别生效,
必须在构建 Angie 时启用 [调试日志](https://cn.angie.software//angie/docs/troubleshooting.md#debug-logging)。

错误日志中的每个条目具有以下格式:

```text
timestamp [level] PID#TID: *request_id message
```

其中:

- `timestamp` — 事件的日期和时间
- `level` — 事件的日志级别
- `PID#TID` — 进程和线程标识符
- `*request_id` — 唯一的请求标识符(如果适用)
- `message` — 错误或事件消息文本

<a id="index-7"></a>

<a id="events"></a>

### events

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `events` { ... };   |
|--------------------------------------------------------------------------------------|---------------------|
| 默认值                                                                                  | —                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                |

为影响连接处理的指令
提供配置文件上下文。

<a id="index-8"></a>

<a id="include"></a>

### include

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `include` file | mask;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | —                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | any                      |

将另一个文件或与指定 mask 匹配的文件
包含到配置中。
包含的文件必须包含语法正确的指令和块。

示例:

```nginx
include mime.types;
include vhosts/*.conf;
```

<a id="index-9"></a>

<a id="load-module"></a>

### load_module

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `load_module` file;   |
|--------------------------------------------------------------------------------------|-----------------------|
| 默认值                                                                                  | —                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                  |

从指定文件加载动态模块。
如果提供的是相对路径,则基于
`--prefix` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 进行解释。要验证路径:

```console
$ sudo angie -V
```

示例:

```nginx
load_module modules/ngx_mail_module.so;
```

如果动态模块是为不同的 Angie 构建版本构建的,加载将失败并显示类似以下的错误:"module "..." was built for "..." but you are running "Angie""。

<a id="index-10"></a>

<a id="lock-file"></a>

### lock_file

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `lock_file` file;                                                                                                                      |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `lock_file logs/angie.lock;`<br/>(路径取决于 `--lock-path` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#paths)) |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                                                                                                                                   |

Angie 使用锁机制来实现 [accept_mutex](#accept-mutex)
并序列化对共享内存的访问。
在大多数系统上,锁是使用原子操作管理的,
因此不需要此指令。
但是,在某些系统上,会使用替代的 lock file 机制。
此指令设置锁文件名的前缀。

<a id="index-11"></a>

<a id="master-process"></a>

### master_process

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `master_process` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `master_process on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                             |

决定是否启动工作进程。
此指令供 Angie 开发人员使用。

<a id="index-12"></a>

<a id="multi-accept"></a>

### multi_accept

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `multi_accept` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `multi_accept off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | events                         |

| `on`   | 工作进程将同时接受所有新连接。   |
|--------|-------------------|
| `off`  | 工作进程每次接受一个新连接。    |

#### NOTE
如果使用 [kqueue](https://cn.angie.software//angie/docs/configuration/processing.md#kqueue) 连接处理方法,
则忽略此指令,
因为它会提供准备接受的新连接数量。

<a id="index-13"></a>

<a id="pcre-jit"></a>

### pcre_jit

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `pcre_jit` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `pcre_jit off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                       |

为配置解析时已知的正则表达式
启用或禁用"即时编译"(PCRE JIT)。

PCRE JIT 可以显著加速正则表达式处理。

#### NOTE
JIT 在 PCRE 库 8.20 版本及以上可用,
前提是使用 `--enable-jit` 配置选项构建。
当使用 PCRE 库构建 Angie 时 (`--with-pcre=`),
使用 `--with-pcre-jit` 选项启用 JIT 支持。

<a id="index-14"></a>

<a id="pid"></a>

### pid

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `pid` file | `off`;                                                                                                            |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `pid logs/angie.pid;`<br/>(路径取决于 `--pid-path` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#paths)) |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                                                                                                                           |

指定将存储 Angie 主进程 ID 的 file。
该文件以原子方式创建,这确保其内容始终正确。
`off` 设置禁用创建此文件。

#### NOTE
如果在重新配置期间修改了 file 设置,
但它指向先前 PID 文件的符号链接,
则不会重新创建该文件。

<a id="index-15"></a>

<a id="ssl-engine"></a>

### ssl_engine

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_engine` 设备;   |
|--------------------------------------------------------------------------------------|--------------------|
| 默认                                                                                   | —                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main               |

指定硬件 SSL 加速器的名称。

<a id="index-16"></a>

<a id="ssl-object-cache-inheritable"></a>

### ssl_object_cache_inheritable

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_object_cache_inheritable` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | `ssl_object_cache_inheritable on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                                           |

如果启用,SSL 对象(SSL 证书、私钥、受信任的 CA 证书、
CRL 列表)在配置重新加载时会被继承。

如果从文件加载的 SSL 对象的修改时间和文件
索引自上次配置加载以来没有更改,则会被继承。指定为 `engine:name:id` 的私钥
永远不会被继承,而指定为 `data:value` 的私钥
始终会被继承。

从变量加载的 SSL 对象无法被继承。

示例:

```nginx
ssl_object_cache_inheritable on;

http {
    server {
        ssl_certificate     example.com.crt;
        ssl_certificate_key example.com.key;
    }
}
```

<a id="index-17"></a>

<a id="thread-pool"></a>

### thread_pool

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `thread_pool` name `threads=`number [`max_queue=`number];   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------|
| 默认值                                                                                  | `thread_pool default threads=32 max_queue=65536;`           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                                                        |

定义线程池的 name 和参数,
用于多线程读取和发送文件,
[不阻塞](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#aio) 工作进程。

`threads` 参数定义池中的线程数。

如果池中的所有线程都忙于执行任务,新任务将在队列中等待。
`max_queue` 参数限制允许在队列中等待的任务数量。
默认情况下,队列中最多可以有 65536 个任务。
当队列溢出时,任务将以错误完成。

<a id="index-18"></a>

<a id="timer-resolution"></a>

### timer_resolution

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `timer_resolution` interval;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | —                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                           |

降低工作进程中的计时器分辨率,
从而减少 `gettimeofday()` 系统调用的次数。
默认情况下,每次接收到内核事件时都会调用 `gettimeofday()`。
降低分辨率后,:samp:gettimeofday() 仅在指定间隔内调用一次。

示例:

```nginx
timer_resolution 100ms;
```

间隔的内部实现取决于所使用的方法:

- 如果使用 [kqueue](https://cn.angie.software//angie/docs/configuration/processing.md#kqueue),则使用 `EVFILT_TIMER` 过滤器;
- 如果使用 [eventport](https://cn.angie.software//angie/docs/configuration/processing.md#eventport),则使用 `timer_create()`;
- 否则使用 `setitimer()`。

<a id="index-19"></a>

<a id="use"></a>

### use

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `use` method;   |
|--------------------------------------------------------------------------------------|-----------------|
| 默认值                                                                                  | —               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | events          |

指定用于 [连接处理](https://cn.angie.software//angie/docs/configuration/processing.md#methods-use) 的 method。
通常不需要显式指定,
因为 Angie 默认会使用最高效的方法。

<a id="index-20"></a>

<a id="user"></a>

### user

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `user` user [group];                 |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `user <构建参数 --user> <构建参数 --group>;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                                 |

定义工作进程使用的 user 和 group 凭据
(另请参阅 [构建参数](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure))。
如果省略 group,则使用与 user 同名的组。

<a id="index-21"></a>

<a id="worker-aio-requests"></a>

### worker_aio_requests

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `worker_aio_requests` number;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `worker_aio_requests 32;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | events                          |

当使用 [aio](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#aio) 和 [epoll](https://cn.angie.software//angie/docs/configuration/processing.md#epoll) 连接处理方法时,
设置单个工作进程的最大未完成异步 I/O 操作数。

<a id="index-22"></a>

<a id="worker-connections"></a>

### worker_connections

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `worker_connections` number;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `worker_connections 512;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | events                         |

设置工作进程可以打开的最大同时连接数。

应该记住,此数字包括所有连接
(例如与代理服务器的连接等),
而不仅仅是与客户端的连接。
另一个考虑因素是,实际的同时连接数
不能超过当前打开文件数的最大限制,
该限制可以通过 [worker_rlimit_nofile](#worker-rlimit-nofile) 更改。

<a id="index-23"></a>

<a id="worker-cpu-affinity"></a>

### worker_cpu_affinity

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `worker_cpu_affinity` cpumask ...;<br/><br/>`worker_cpu_affinity` auto [cpumask];   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                                                                                |

将工作进程绑定到 CPU 集合。
每个 CPU 集合由允许的 CPU 位掩码表示。
应该为每个工作进程定义一个单独的集合。
默认情况下,工作进程不绑定到任何特定的 CPU。

例如:

```nginx
worker_processes    4;
worker_cpu_affinity 0001 0010 0100 1000;
```

此配置将每个工作进程绑定到单独的 CPU。

或者:

```nginx
worker_processes    2;
worker_cpu_affinity 0101 1010;
```

这将第一个工作进程绑定到 CPU0 和 CPU2,
将第二个工作进程绑定到 CPU1 和 CPU3。
此设置适用于超线程。

特殊值 `auto`
允许自动将工作进程绑定到可用的 CPU:

```nginx
worker_processes auto;
worker_cpu_affinity auto;
```

可选的掩码参数可用于限制
可用于自动绑定的 CPU:

```nginx
worker_cpu_affinity auto 01010101;
```

#### NOTE
该指令仅在 FreeBSD 和 Linux 上可用。

<a id="index-24"></a>

<a id="worker-priority"></a>

### worker_priority

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `worker_priority` number;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `worker_priority 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                        |

定义工作进程的调度优先级,类似于
**nice** 命令的做法:负数 number
表示更高的优先级。
允许的范围通常从 -20 到 20。

示例:

```nginx
worker_priority -10;
```

<a id="index-25"></a>

<a id="worker-processes"></a>

### worker_processes

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `worker_processes` number | `auto`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `worker_processes 1;`                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                                  |

定义工作进程的数量。

最佳值取决于许多因素,包括(但不限于)
CPU 核心数、存储数据的硬盘驱动器数量
以及负载模式。
如果不确定,将其设置为可用 CPU 核心数
是一个不错的起点(值"`auto`"将尝试自动检测)。

<a id="index-26"></a>

<a id="worker-rlimit-core"></a>

### worker_rlimit_core

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `worker_rlimit_core` size;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | —                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                         |

更改工作进程的核心文件最大大小限制(`RLIMIT_CORE`)。
用于在不重启主进程的情况下增加限制。

<a id="index-27"></a>

<a id="worker-rlimit-nofile"></a>

### worker_rlimit_nofile

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `worker_rlimit_nofile` number;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                             |

更改工作进程的最大打开文件数限制(`RLIMIT_NOFILE`)。
用于在不重启主进程的情况下增加限制。

<a id="index-28"></a>

<a id="worker-shutdown-timeout"></a>

### worker_shutdown_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `worker_shutdown_timeout` time;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                              |

配置工作进程优雅关闭的超时时间(以秒为单位)。
当指定的时间到期时,
Angie 将尝试关闭当前打开的所有连接
以便于关闭。

优雅关闭通过向主进程发送 [QUIT 信号](https://cn.angie.software//angie/docs/configuration/runtime.md#control-signals) 来启动,该信号指示工作进程
停止接受新连接并允许现有连接完成。
工作进程继续处理活动请求直到完成,
然后优雅地关闭。如果连接保持打开的时间
超过 `worker_shutdown_timeout`,Angie 将强制关闭这些
连接以完成关闭。
此外,客户端保持活动连接仅在空闲时间
至少达到 [lingering_timeout](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#lingering-timeout) 指定的时间时才会关闭。

<a id="index-29"></a>

<a id="working-directory"></a>

### working_directory

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `working_directory` directory;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                             |

定义工作进程的当前工作目录。
它主要在写入核心文件时使用,
在这种情况下,工作进程应该对
指定的目录具有写入权限。


# https://cn.angie.software/angie/docs/configuration/custom-metrics.md

<!-- review: finished -->

<a id="custom-metrics-config"></a>

# 自定义指标配置

Angie 可以在共享内存中收集自定义数值指标，并通过实时 [统计 API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics) 在 `/status/http/metric_zones/` 公开它们。这由 [Metric](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#http-metric) 模块提供。

<a id="configuration-steps-1"></a>

## 配置步骤

1. 在 `http` 块中定义指标区域：
   - [metric_zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#metric-zone) 创建具有单个指标模式的区域。
   - [metric_complex_zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#metric-complex-zone) 创建具有多个命名指标的区域。
2. 使用 [metric](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#id5) 指令在请求处理中更新指标。
   使用 `key=value` 对（两者都是 [复杂值](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)），并使用 `on=` 选择更新阶段（`request`、`response` 或 `end`）。
3. 使用 `location` 公开 API：
   ```nginx
   location /status/ {
       api /status/http/metric_zones/;
   }
   ```

<a id="example"></a>

## 示例

统计每个主机的请求数并在 API 中公开指标：

```nginx
http {
    metric_zone requests:128k count;

    server {
        listen 80;

        location / {
            metric requests $host=1;
        }

        location /status/ {
            api /status/http/metric_zones/;
        }
    }
}
```

<a id="notes"></a>

## 注意事项

- 如果在区域上设置了 `expire=on` 且共享内存已满，则最近最少使用的条目将过期。如果设置了 `expire=off`，新的更新将被丢弃，`discarded` 计数器会增长。
- 如果设置了 `discard_key`，过期条目的指标将在 API 输出中聚合到该键下。
- 键和值限制为 255 字节；较长的键在 API 中会被截断。
- 空值被视为 `0`，没有前导数字的非空值被视为 `1`。


# https://cn.angie.software/angie/docs/installation/external-modules/dav-ext.md

<!-- review: finished -->

<a id="external-dav-ext"></a>

# DAV-Ext

此模块通过 PROPFIND、OPTIONS、LOCK 和 UNLOCK 方法扩展了 WebDAV 支持。

标准 [DAV](https://cn.angie.software//angie/docs/configuration/modules/http/http_dav.md#http-dav) 模块提供了 WebDAV 的部分实现,
仅支持 GET、HEAD、PUT、DELETE、MKCOL、COPY 和 MOVE 方法。
要获得完整的 WebDAV 支持,您需要启用标准的
`http_dav_module` 模块,以及此模块来支持缺失的方法。

<a id="installation-7"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-dav-ext`
- Angie PRO:`angie-pro-module-dav-ext`

<a id="loading-the-module-6"></a>

## 加载模块

在 `main{}` 上下文中加载模块:

```nginx
load_module modules/ngx_http_dav_ext_module.so;
```

<a id="configuration-example-83"></a>

## 配置示例

```nginx
dav_ext_lock_zone zone=lock_zone:10m;
server {
    listen 80 default_server;

    location / {
        root /usr/share/angie/html;

        dav_methods PUT DELETE MKCOL COPY MOVE;
        dav_ext_methods PROPFIND OPTIONS LOCK UNLOCK;
        dav_ext_lock zone=lock_zone;
    }
}
```

<a id="request-execution-examples"></a>

## 请求执行示例

将文件上传到服务器:

```console
$ curl -i -X PUT -d @testf1.txt http://127.0.0.1/testf1.txt
HTTP/1.1 201 Created
Server: Angie/|angie_version|
Date: |sampledatelong| 19:15:35 GMT
Content-Length: 0
Location: http://127.0.0.1/testf1.txt
Connection: keep-alive
```

覆盖同一文件:

```console
$ curl -i -X PUT -d @testf1.txt http://127.0.0.1/testf1.txt
HTTP/1.1 204 No Content
Server: Angie/|angie_version|
Date: |sampledatelong| 19:15:35 GMT
Connection: keep-alive
```

锁定文件防止被覆盖:

```console
$ curl -i -X LOCK http://127.0.0.1/testf1.txt
HTTP/1.1 200 OK
Server: Angie/|angie_version|
Date: |sampledatelong| 19:15:35 GMT
Content-Type: text/xml; charset=utf-8
Content-Length: 392
Connection: keep-alive
Lock-Token: <urn:7502d56f>
```

尝试覆盖文件:

```console
$ curl -i -X PUT -d @testf1.txt http://127.0.0.1/testf1.txt
HTTP/1.1 423
Server: Angie/|angie_version|
Date: |sampledatelong| 19:15:35 GMT
Content-Length: 0
Connection: keep-alive
```

文件已被锁定。解锁文件:

```console
$ curl -i -X UNLOCK -H 'Lock-Token: <urn:7502d56f>' http://127.0.0.1/testf1.txt
HTTP/1.1 204 No Content
Server: Angie/|angie_version|
Date: |sampledatelong| 19:15:35 GMT
Connection: keep-alive
```

覆盖文件:

```console
$ curl -i -X PUT -d @testf1.txt http://127.0.0.1/testf1.txt
HTTP/1.1 204 No Content
Server: Angie/|angie_version|
Date: |sampledatelong| 19:15:35 GMT
Connection: keep-alive
```

文件已成功解锁并覆盖。

<a id="additional-information-7"></a>

## 附加信息

详细文档和源代码可在以下位置获取:
[https://github.com/arut/nginx-dav-ext-module](https://github.com/arut/nginx-dav-ext-module)


# https://cn.angie.software/angie/docs/developer_guide.md

<!-- review: finished -->

<a id="developer-guide"></a>

# 开发者指南

<a id="coding-conventions"></a>

## 编码约定

源代码遵循以下结构和约定。

<a id="code-layout"></a>

### 代码布局

* `auto` — 构建脚本
* `src`
  * `core` — 基本类型和函数 — 字符串、数组、日志、
    池等。
  * `event` — 事件核心
    * `modules` — 事件通知模块:
      `epoll`、`kqueue`、`select`
      等。
  * `http` — 核心 HTTP 模块和通用代码
    * `modules` — 其他 HTTP 模块
    * `v2` — HTTP/2
  * `mail` — 邮件模块
  * `os` — 平台特定代码
    * `unix`
    * `win32`
  * `stream` — 流模块

<a id="include-files"></a>

### 包含文件

以下两个 `#include` 语句必须出现在
每个 Angie 文件的开头:

```c
#include <ngx_config.h>
#include <ngx_core.h>
```

除此之外,HTTP 代码应包含

```c
#include <ngx_http.h>
```

邮件代码应包含

```c
#include <ngx_mail.h>
```

流代码应包含

```c
#include <ngx_stream.h>
```

<a id="integers"></a>

### 整数

对于一般用途,Angie 代码使用两种整数类型,
`ngx_int_t` 和 `ngx_uint_t`,它们分别是
`intptr_t` 和 `uintptr_t`
的类型定义。

<a id="common-return-codes"></a>

### 常见返回码

Angie 中的大多数函数返回以下代码:

* `NGX_OK` — 操作成功。
* `NGX_ERROR` — 操作失败。
* `NGX_AGAIN` — 操作未完成;再次调用该函数。
* `NGX_DECLINED` — 操作被拒绝,例如,因为它在
  配置中被禁用。这永远不是错误。
* `NGX_BUSY` — 资源不可用。
* `NGX_DONE` — 操作完成或在其他地方继续。
  也用作替代成功代码。
* `NGX_ABORT` — 函数被中止。
  也用作替代错误代码。

<a id="error-handling"></a>

### 错误处理

`ngx_errno` 宏返回最后一个系统错误代码。
它在 POSIX 平台上映射到 `errno`,在 Windows 中映射到
`GetLastError()` 调用。
`ngx_socket_errno` 宏返回最后一个套接字错误
编号。
与 `ngx_errno` 宏一样,它在
POSIX 平台上映射到 `errno`。
它在 Windows 中映射到 `WSAGetLastError()` 调用。
连续多次访问 `ngx_errno` 或
`ngx_socket_errno` 的值可能会导致
性能问题。
如果错误值可能被多次使用,请将其存储在
`ngx_err_t` 类型的局部变量中。
要设置错误,请使用 `ngx_set_errno(errno)` 和
`ngx_set_socket_errno(errno)` 宏。

`ngx_errno` 和
`ngx_socket_errno` 的值可以传递给日志函数
`ngx_log_error()` 和 `ngx_log_debugX()`,
在这种情况下,系统错误文本会添加到日志消息中。

使用 `ngx_errno` 的示例:

```c
ngx_int_t
ngx_my_kill(ngx_pid_t pid, ngx_log_t *log, int signo)
{
    ngx_err_t  err;

    if (kill(pid, signo) == -1) {
        err = ngx_errno;

        ngx_log_error(NGX_LOG_ALERT, log, err, "kill(%P, %d) failed", pid, signo);

        if (err == NGX_ESRCH) {
            return 2;
        }

        return 1;
    }

    return 0;
}
```

<a id="strings"></a>

### 字符串

<a id="overview"></a>

#### 概述

对于 C 字符串,Angie 使用无符号字符类型指针
`u_char *`。

Angie 字符串类型 `ngx_str_t` 定义如下:

```c
typedef struct {
    size_t      len;
    u_char     *data;
} ngx_str_t;
```

`len` 字段保存字符串长度,
`data` 保存字符串数据。
`ngx_str_t` 中保存的字符串在 `len` 字节之后
可能以 null 结尾,也可能不以 null 结尾。
在大多数情况下不是。
但是,在代码的某些部分(例如,解析配置时),
`ngx_str_t` 对象已知以 null 结尾,这
简化了字符串比较,并使将字符串传递给
系统调用变得更容易。

Angie 中的字符串操作在
`src/core/ngx_string.h` 中声明。
其中一些是标准 C 函数的包装器:

* `ngx_strcmp()`
* `ngx_strncmp()`
* `ngx_strstr()`
* `ngx_strlen()`
* `ngx_strchr()`
* `ngx_memcmp()`
* `ngx_memset()`
* `ngx_memcpy()`
* `ngx_memmove()`

其他字符串函数是 Angie 特定的:

* `ngx_memzero()` — 用零填充内存。
* `ngx_explicit_memzero()` — 与
  `ngx_memzero()` 相同,但此调用永远不会被
  编译器的死存储消除优化删除。
  此函数可用于清除敏感数据,如密码和密钥。
* `ngx_cpymem()` — 与
  `ngx_memcpy()` 相同,但返回最终目标地址。
  这对于连续追加多个字符串很方便。
* `ngx_movemem()` — 与
  `ngx_memmove()` 相同,但返回最终目标地址。
* `ngx_strlchr()` — 在字符串中搜索字符,
  由两个指针分隔。

以下函数执行大小写转换和比较:

* `ngx_tolower()`
* `ngx_toupper()`
* `ngx_strlow()`
* `ngx_strcasecmp()`
* `ngx_strncasecmp()`

以下宏简化了字符串初始化:

* `ngx_string(text)` — 从 C 字符串字面量
  `text` 为 `ngx_str_t` 类型的静态初始化器
* `ngx_null_string` — `ngx_str_t` 类型的静态空字符串初始化器
* `ngx_str_set(str, text)` — 使用 C 字符串
  字面量 `text` 初始化 `ngx_str_t *` 类型的字符串
  `str`
* `ngx_str_null(str)` — 使用空字符串初始化
  `ngx_str_t *` 类型的字符串 `str`

<a id="formatting"></a>

#### 格式化

以下格式化函数支持 Angie 特定类型:

* `ngx_sprintf(buf, fmt, ...)`
* `ngx_snprintf(buf, max, fmt, ...)`
* `ngx_slprintf(buf, last, fmt, ...)`
* `ngx_vslprintf(buf, last, fmt, args)`
* `ngx_vsnprintf(buf, max, fmt, args)`

这些函数支持的格式化选项的完整列表在
`src/core/ngx_string.c` 中。其中一些是:

* `%O` — `off_t`
* `%T` — `time_t`
* `%z` — `ssize_t`
* `%i` — `ngx_int_t`
* `%p` — `void *`
* `%V` — `ngx_str_t *`
* `%s` — `u_char *` (以 null 结尾)
* `%*s` — `size_t + u_char *`

您可以在大多数类型前加上 `u` 以使其无符号。
要将输出转换为十六进制,请使用 `X` 或 `x` 。

<a id="numeric-conversion"></a>

### 数值转换

Angie 中实现了几个数值转换函数。
前四个函数各自将给定长度的字符串转换为指定类型的正整数。
它们在出错时返回 `NGX_ERROR`。

* `ngx_atoi(line, n)` — `ngx_int_t`
* `ngx_atosz(line, n)` — `ssize_t`
* `ngx_atoof(line, n)` — `off_t`
* `ngx_atotm(line, n)` — `time_t`

还有两个额外的数值转换函数。
与前四个一样,它们在出错时返回 `NGX_ERROR`。

* `ngx_atofp(line, n, point)` — 将给定长度的定点数
  转换为 `ngx_int_t` 类型的正整数。
  结果向左移动 `point` 个十进制
  位置。
  数字的字符串表示预期不超过
  `point` 个小数位。
  例如,:samp:ngx_atofp("10.5", 4, 2) 返回
  `1050`。
* `ngx_hextoi(line, n)` — 将正整数的十六进制表示
  转换为 `ngx_int_t`。

<a id="regular-expressions"></a>

### 正则表达式

Angie 中的正则表达式接口是
[PCRE](http://www.pcre.org) 库的包装器。
相应的头文件是 `src/core/ngx_regex.h`。

要使用正则表达式进行字符串匹配，首先需要
编译它，这通常在配置阶段完成。
请注意，由于 PCRE 支持是可选的，所有使用该接口的代码必须
由周围的 `NGX_PCRE` 宏保护：

```c
#if (NGX_PCRE)
ngx_regex_t          *re;
ngx_regex_compile_t   rc;

u_char                errstr[NGX_MAX_CONF_ERRSTR];

ngx_str_t  value = ngx_string("message (\\d\\d\\d).*Codeword is '(?<cw>\\w+)'");

ngx_memzero(&rc, sizeof(ngx_regex_compile_t));

rc.pattern = value;
rc.pool = cf->pool;
rc.err.len = NGX_MAX_CONF_ERRSTR;
rc.err.data = errstr;
/* rc.options 可以设置为 NGX_REGEX_CASELESS */

if (ngx_regex_compile(&rc) != NGX_OK) {
    ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc.err);
    return NGX_CONF_ERROR;
}

re = rc.regex;
#endif
```

成功编译后，`ngx_regex_compile_t` 结构中的 `captures` 和 `named_captures` 字段分别包含在正则表达式中找到的所有捕获和命名捕获的计数。

然后可以使用编译后的正则表达式来匹配字符串：

```c
ngx_int_t  n;
int        captures[(1 + rc.captures) * 3];

ngx_str_t input = ngx_string("This is message 123. Codeword is 'foobar'.");

n = ngx_regex_exec(re, &input, captures, (1 + rc.captures) * 3);
if (n >= 0) {
    /* string matches expression */

} else if (n == NGX_REGEX_NO_MATCHED) {
    /* no match was found */

} else {
    /* some error */
    ngx_log_error(NGX_LOG_ALERT, log, 0, ngx_regex_exec_n " failed: %i", n);
}
```

`ngx_regex_exec()` 的参数是编译后的正则
表达式 `re`、要匹配的字符串 `input`、
一个可选的整数数组来保存找到的任何 `captures`,
以及数组的 `size`。
`captures` 数组的大小必须是三的倍数,
如 [PCRE API](http://www.pcre.org/original/doc/html/pcreapi.html) 所要求的。
在示例中,大小是根据捕获总数加上
匹配字符串本身的一个计算得出的。

如果有匹配,可以按如下方式访问捕获:

```c
u_char     *p;
size_t      size;
ngx_str_t   name, value;

/* all captures */
for (i = 0; i < n * 2; i += 2) {
    value.data = input.data + captures[i];
    value.len = captures[i + 1] - captures[i];
}

/* accessing named captures */

size = rc.name_size;
p = rc.names;

for (i = 0; i < rc.named_captures; i++, p += size) {

    /* capture name */
    name.data = &p[2];
    name.len = ngx_strlen(name.data);

    n = 2 * ((p[0] << 8) + p[1]);

    /* captured value */
    value.data = &input.data[captures[n]];
    value.len = captures[n + 1] - captures[n];
}
```

`ngx_regex_exec_array()` 函数接受一个
`ngx_regex_elt_t` 元素数组(它们只是带有关联名称的编译正则
表达式)、要匹配的字符串和日志。
该函数将数组中的表达式应用于字符串,直到
找到匹配或没有更多表达式为止。
当有匹配时返回值为 `NGX_OK`,
否则为 `NGX_DECLINED`,或在出错时为 `NGX_ERROR`。

<a id="time"></a>

### 时间

`ngx_time_t` 结构用三个独立的类型表示时间：秒、毫秒和 GMT 偏移：

```c
typedef struct {
    time_t      sec;
    ngx_uint_t  msec;
    ngx_int_t   gmtoff;
} ngx_time_t;
```

`ngx_tm_t` 结构是 UNIX 平台上 `struct tm` 和 Windows 上 `SYSTEMTIME` 的别名。

要获取当前时间，通常只需访问一个可用的全局变量，这些变量以所需格式表示缓存的时间值。

可用的字符串表示形式有：

* `ngx_cached_err_log_time` — 用于错误日志条目：
  `"1970/09/28 12:00:00"`
* `ngx_cached_http_log_time` — 用于 HTTP 访问日志条目：
  `"28/Sep/1970:12:00:00 +0600"`
* `ngx_cached_syslog_time` — 用于 syslog 条目：
  `"Sep 28 12:00:00"`
* `ngx_cached_http_time` — 用于 HTTP 头：
  `"Mon, 28 Sep 1970 06:00:00 GMT"`
* `ngx_cached_http_log_iso8601` — ISO 8601 标准格式：
  `"1970-09-28T12:00:00+06:00"`

`ngx_time()` 和 `ngx_timeofday()` 宏返回当前时间值（以秒为单位），是访问缓存时间值的首选方式。

要显式获取时间，请使用 `ngx_gettimeofday()`，它会更新其参数（指向 `struct timeval` 的指针）。
当 Angie 从系统调用返回到事件循环时，时间总是会更新。
要立即更新时间，请调用 `ngx_time_update()`，或者如果在信号处理程序上下文中更新时间，请调用 `ngx_time_sigsafe_update()`。

以下函数将 `time_t` 转换为指定的分解时间表示形式。
每对中的第一个函数将 `time_t` 转换为 `ngx_tm_t`，第二个函数（带有 `_libc_` 中缀）转换为 `struct tm`：

* `ngx_gmtime(), ngx_libc_gmtime()` — 以 UTC 表示的时间
* `ngx_localtime(), ngx_libc_localtime()` — 相对于本地时区表示的时间

`ngx_http_time(buf, time)` 函数返回适合在 HTTP 头中使用的字符串表示形式（例如，`"Mon, 28 Sep 1970 06:00:00 GMT"`）。
`ngx_http_cookie_time(buf, time)` 函数返回适合 HTTP cookie 的字符串表示形式（`"Thu, 31-Dec-37 23:55:55 GMT"`）。

<a id="containers"></a>

## 容器

<a id="array"></a>

### 数组

Angie 数组类型 `ngx_array_t` 定义如下

```c
typedef struct {
    void        *elts;
    ngx_uint_t   nelts;
    size_t       size;
    ngx_uint_t   nalloc;
    ngx_pool_t  *pool;
} ngx_array_t;
```

数组的元素在 `elts` 字段中可用。
`nelts` 字段保存元素的数量。
`size` 字段保存单个元素的大小，并在数组初始化时设置。

使用 `ngx_array_create(pool, n, size)` 调用在内存池中创建数组，使用 `ngx_array_init(array, pool, n, size)` 调用初始化已分配的数组对象。

```c
ngx_array_t  *a, b;

/* 创建一个字符串数组，为 10 个元素预分配内存 */
a = ngx_array_create(pool, 10, sizeof(ngx_str_t));

/* 初始化 10 个元素的字符串数组 */
ngx_array_init(&b, pool, 10, sizeof(ngx_str_t));
```

使用以下函数向数组添加元素：

* `ngx_array_push(a)` 添加一个尾部元素并返回指向它的指针
* `ngx_array_push_n(a, n)` 添加 `n` 个尾部元素并返回指向第一个元素的指针

如果当前分配的内存量不足以容纳新元素，则会分配一个新的内存块并将现有元素复制到其中。
新内存块通常是现有内存块的两倍大。

```c
s = ngx_array_push(a);
ss = ngx_array_push_n(&b, 3);
```

<a id="list"></a>

### 列表

在 Angie 中，列表是一系列数组，针对插入可能大量的项目进行了优化。
`ngx_list_t` 列表类型定义如下：

```c
typedef struct {
    ngx_list_part_t  *last;
    ngx_list_part_t   part;
    size_t            size;
    ngx_uint_t        nalloc;
    ngx_pool_t       *pool;
} ngx_list_t;
```

实际项目存储在列表部分中，定义如下：

```c
typedef struct ngx_list_part_s  ngx_list_part_t;

struct ngx_list_part_s {
    void             *elts;
    ngx_uint_t        nelts;
    ngx_list_part_t  *next;
};
```

在使用之前，必须通过调用 `ngx_list_init(list, pool, n, size)` 初始化列表，或通过调用 `ngx_list_create(pool, n, size)` 创建列表。
这两个函数都将单个项目的大小和每个列表部分的项目数作为参数。
要向列表添加项目，请使用 `ngx_list_push(list)` 函数。
要遍历项目，请直接访问列表字段，如示例所示：

```c
ngx_str_t        *v;
ngx_uint_t        i;
ngx_list_t       *list;
ngx_list_part_t  *part;

list = ngx_list_create(pool, 100, sizeof(ngx_str_t));
if (list == NULL) { /* error */ }

/* 向列表添加项目 */

v = ngx_list_push(list);
if (v == NULL) { /* error */ }
ngx_str_set(v, "foo");

v = ngx_list_push(list);
if (v == NULL) { /* error */ }
ngx_str_set(v, "bar");

/* 遍历列表 */

part = &list->part;
v = part->elts;

for (i = 0; /* void */; i++) {

    if (i >= part->nelts) {
        if (part->next == NULL) {
            break;
        }

        part = part->next;
        v = part->elts;
        i = 0;
    }

    ngx_do_smth(&v[i]);
}
```

列表主要用于 HTTP 输入和输出头。

列表不支持项目删除。
但是，在需要时，可以在内部将项目标记为缺失，而无需实际从列表中删除。
例如，要将 HTTP 输出头（存储为 `ngx_table_elt_t` 对象）标记为缺失，请将 `ngx_table_elt_t` 中的 `hash` 字段设置为零。
在遍历头时，会显式跳过以这种方式标记的项目。

<a id="queue"></a>

### 队列

在 Angie 中，队列是一个侵入式双向链表，每个节点定义如下：

```c
typedef struct ngx_queue_s  ngx_queue_t;

struct ngx_queue_s {
    ngx_queue_t  *prev;
    ngx_queue_t  *next;
};
```

头队列节点不与任何数据链接。
在使用之前，使用 `ngx_queue_init(q)` 调用初始化列表头。
队列支持以下操作：

* `ngx_queue_insert_head(h, x)`、`ngx_queue_insert_tail(h, x)` — 插入新节点
* `ngx_queue_remove(x)` — 删除队列节点
* `ngx_queue_split(h, q, n)` — 在节点处拆分队列，在单独的队列中返回队列尾部
* `ngx_queue_add(h, n)` — 将第二个队列添加到第一个队列
* `ngx_queue_head(h)`、`ngx_queue_last(h)` — 获取第一个或最后一个队列节点
* `ngx_queue_sentinel(h)` — 获取队列哨兵对象以结束迭代
* `ngx_queue_data(q, type, link)` — 获取对队列节点数据结构开头的引用，考虑其中队列字段的偏移量

示例：

```c
typedef struct {
    ngx_str_t    value;
    ngx_queue_t  queue;
} ngx_foo_t;

ngx_foo_t    *f;
ngx_queue_t   values, *q;

ngx_queue_init(&values);

f = ngx_palloc(pool, sizeof(ngx_foo_t));
if (f == NULL) { /* error */ }
ngx_str_set(&f->value, "foo");

ngx_queue_insert_tail(&values, &f->queue);

/* 在此处插入更多节点 */

for (q = ngx_queue_head(&values);
     q != ngx_queue_sentinel(&values);
     q = ngx_queue_next(q))
{
    f = ngx_queue_data(q, ngx_foo_t, queue);

    ngx_do_smth(&f->value);
}
```

<a id="red-black-tree"></a>

### 红黑树

`src/core/ngx_rbtree.h` 头文件提供对红黑树的有效实现的访问。

```c
typedef struct {
    ngx_rbtree_t       rbtree;
    ngx_rbtree_node_t  sentinel;

    /* 此处为自定义的每棵树数据 */
} my_tree_t;

typedef struct {
    ngx_rbtree_node_t  rbnode;

    /* 自定义的每个节点数据 */
    foo_t              val;
} my_node_t;
```

要将树作为一个整体处理，您需要两个节点：根节点和哨兵节点。
通常，它们被添加到自定义结构中，允许您将数据组织到树中，其中叶子包含指向您的数据的链接或嵌入您的数据。

要初始化树：

```c
my_tree_t  root;

ngx_rbtree_init(&root.rbtree, &root.sentinel, insert_value_function);
```

要遍历树并插入新值，请使用 "`insert_value`" 函数。
例如，`ngx_str_rbtree_insert_value` 函数处理 `ngx_str_t` 类型。
其参数是指向插入的根节点的指针、要添加的新创建节点以及树哨兵。

```c
void ngx_str_rbtree_insert_value(ngx_rbtree_node_t *temp,
                                 ngx_rbtree_node_t *node,
                                 ngx_rbtree_node_t *sentinel)
```

遍历非常简单，可以用以下查找函数模式演示：

```c
my_node_t *
my_rbtree_lookup(ngx_rbtree_t *rbtree, foo_t *val, uint32_t hash)
{
    ngx_int_t           rc;
    my_node_t          *n;
    ngx_rbtree_node_t  *node, *sentinel;

    node = rbtree->root;
    sentinel = rbtree->sentinel;

    while (node != sentinel) {

        n = (my_node_t *) node;

        if (hash != node->key) {
            node = (hash < node->key) ? node->left : node->right;
            continue;
        }

        rc = compare(val, node->val);

        if (rc < 0) {
            node = node->left;
            continue;
        }

        if (rc > 0) {
            node = node->right;
            continue;
        }

        return n;
    }

    return NULL;
}
```

`compare()` 函数是一个经典的比较器函数，返回小于、等于或大于零的值。
为了加快查找速度并避免比较可能很大的用户对象，使用了整数哈希字段。

要向树添加节点，请分配一个新节点，对其进行初始化并调用 `ngx_rbtree_insert()`：

```c
my_node_t          *my_node;
ngx_rbtree_node_t  *node;

my_node = ngx_palloc(...);
init_custom_data(&my_node->val);

node = &my_node->rbnode;
node->key = create_key(my_node->val);

ngx_rbtree_insert(&root->rbtree, node);
```

要删除节点，请调用 `ngx_rbtree_delete()` 函数：

```c
ngx_rbtree_delete(&root->rbtree, node);
```

<a id="hash-1"></a>

### 哈希

哈希表函数在 `src/core/ngx_hash.h` 中声明。
支持精确匹配和通配符匹配。
后者需要额外的设置，并在下面的单独部分中描述。

在初始化哈希之前，您需要知道它将包含的元素数量，以便 Angie 可以最佳地构建它。
需要配置的两个参数是 `max_size` 和 `bucket_size`，详见单独的 [文档](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes)。
它们通常由用户配置。
哈希初始化设置使用 `ngx_hash_init_t` 类型存储，哈希本身是 `ngx_hash_t`：

```c
ngx_hash_t       foo_hash;
ngx_hash_init_t  hash;

hash.hash = &foo_hash;
hash.key = ngx_hash_key;
hash.max_size = 512;
hash.bucket_size = ngx_align(64, ngx_cacheline_size);
hash.name = "foo_hash";
hash.pool = cf->pool;
hash.temp_pool = cf->temp_pool;
```

`key` 是指向从字符串创建哈希整数键的函数的指针。
有两个通用的键创建函数：`ngx_hash_key(data, len)` 和 `ngx_hash_key_lc(data, len)`。
后者将字符串转换为全小写字符，因此传递的字符串必须是可写的。
如果不是这样，请将 `NGX_HASH_READONLY_KEY` 标志传递给函数，初始化键数组（见下文）。

哈希键存储在 `ngx_hash_keys_arrays_t` 中，并使用 `ngx_hash_keys_array_init(arr, type)` 初始化：
第二个参数（`type`）控制为哈希预分配的资源量，可以是 `NGX_HASH_SMALL` 或 `NGX_HASH_LARGE`。
如果您预计哈希将包含数千个元素，则后者是合适的。

```c
ngx_hash_keys_arrays_t  foo_keys;

foo_keys.pool = cf->pool;
foo_keys.temp_pool = cf->temp_pool;

ngx_hash_keys_array_init(&foo_keys, NGX_HASH_SMALL);
```

要将键插入哈希键数组，请使用 `ngx_hash_add_key(keys_array, key, value, flags)` 函数：

```c
ngx_str_t k1 = ngx_string("key1");
ngx_str_t k2 = ngx_string("key2");

ngx_hash_add_key(&foo_keys, &k1, &my_data_ptr_1, NGX_HASH_READONLY_KEY);
ngx_hash_add_key(&foo_keys, &k2, &my_data_ptr_2, NGX_HASH_READONLY_KEY);
```

要构建哈希表，请调用 `ngx_hash_init(hinit, key_names, nelts)` 函数：

```c
ngx_hash_init(&hash, foo_keys.keys.elts, foo_keys.keys.nelts);
```

如果 `max_size` 或 `bucket_size` 参数不够大，该函数将失败。

构建哈希后，使用 `ngx_hash_find(hash, key, name, len)` 函数查找元素：

```c
my_data_t   *data;
ngx_uint_t   key;

key = ngx_hash_key(k1.data, k1.len);

data = ngx_hash_find(&foo_hash, key, k1.data, k1.len);
if (data == NULL) {
    /* 未找到键 */
}
```

<a id="wildcard-matching"></a>

#### 通配符匹配

要创建使用通配符的哈希，请使用 `ngx_hash_combined_t` 类型。
它包括上述哈希类型，并有两个额外的键数组：`dns_wc_head` 和 `dns_wc_tail`。
基本属性的初始化类似于常规哈希：

```c
ngx_hash_init_t      hash
ngx_hash_combined_t  foo_hash;

hash.hash = &foo_hash.hash;
hash.key = ...;
```

可以使用 `NGX_HASH_WILDCARD_KEY` 标志添加通配符键：

```c
/* k1 = ".example.org"; */
/* k2 = "foo.*";        */
ngx_hash_add_key(&foo_keys, &k1, &data1, NGX_HASH_WILDCARD_KEY);
ngx_hash_add_key(&foo_keys, &k2, &data2, NGX_HASH_WILDCARD_KEY);
```

该函数识别通配符并将键添加到相应的数组中。
有关通配符语法和匹配算法的描述，请参阅 [Map](https://cn.angie.software//angie/docs/configuration/modules/http/http_map.md#http-map) 模块文档。

根据添加的键的内容，您可能需要初始化最多三个键数组：一个用于精确匹配（如上所述），另外两个用于启用从字符串的头部或尾部开始的匹配：

```c
if (foo_keys.dns_wc_head.nelts) {

    ngx_qsort(foo_keys.dns_wc_head.elts,
              (size_t) foo_keys.dns_wc_head.nelts,
              sizeof(ngx_hash_key_t),
              cmp_dns_wildcards);

    hash.hash = NULL;
    hash.temp_pool = pool;

    if (ngx_hash_wildcard_init(&hash, foo_keys.dns_wc_head.elts,
                               foo_keys.dns_wc_head.nelts)
        != NGX_OK)
    {
        return NGX_ERROR;
    }

    foo_hash.wc_head = (ngx_hash_wildcard_t *) hash.hash;
}
```

键数组需要排序，初始化结果必须添加到组合哈希中。
`dns_wc_tail` 数组的初始化方式类似。

组合哈希中的查找由 `ngx_hash_find_combined(chash, key, name, len)` 处理：

```c
/* key = "bar.example.org"; - 将匹配 ".example.org" */
/* key = "foo.example.com"; - 将匹配 "foo.*"        */

hkey = ngx_hash_key(key.data, key.len);
res = ngx_hash_find_combined(&foo_hash, hkey, key.data, key.len);
```

<a id="memory-management"></a>

## 内存管理

<a id="heap"></a>

### 堆

要从系统堆分配内存,请使用以下函数:

* `ngx_alloc(size, log)` — 从系统堆分配内存。
  这是 `malloc()` 的包装器,支持日志记录。
  分配错误和调试信息会记录到 `log`。
* `ngx_calloc(size, log)` — 从系统堆分配内存,
  类似于 `ngx_alloc()`,但在分配后将内存填充为零。
* `ngx_memalign(alignment, size, log)` — 从系统堆分配对齐的内存。
  在提供该函数的平台上,这是 `posix_memalign()` 的包装器。
  否则实现会回退到 `ngx_alloc()`,它提供最大对齐。
* `ngx_free(p)` — 释放已分配的内存。
  这是 `free()` 的包装器。

<a id="pooling"></a>

### 内存池

大多数 Angie 分配都在内存池中完成。
在 Angie 内存池中分配的内存会在内存池销毁时自动释放。
这提供了良好的分配性能并使内存控制变得容易。

内存池在内部以连续的内存块分配对象。
一旦一个块满了,就会分配一个新块并添加到内存池的内存块列表中。
当请求的分配太大而无法放入块中时,请求会转发到系统分配器,
返回的指针会存储在内存池中以便后续释放。

Angie 内存池的类型是 `ngx_pool_t`。
支持以下操作:

* `ngx_create_pool(size, log)` — 创建具有指定块大小的内存池。
  返回的内存池对象也在内存池中分配。
  `size` 应至少为 `NGX_MIN_POOL_SIZE`
  且是 `NGX_POOL_ALIGNMENT` 的倍数。
* `ngx_destroy_pool(pool)` — 释放所有内存池内存,包括内存池对象本身。
* `ngx_palloc(pool, size)` — 从指定的内存池分配对齐的内存。
* `ngx_pcalloc(pool, size)` — 从指定的内存池分配对齐的内存并用零填充。
* `ngx_pnalloc(pool, size)` — 从指定的内存池分配未对齐的内存。
  主要用于分配字符串。
* `ngx_pfree(pool, p)` — 释放先前在指定内存池中分配的内存。
  只有转发到系统分配器的分配请求才能被释放。

```c
u_char      *p;
ngx_str_t   *s;
ngx_pool_t  *pool;

pool = ngx_create_pool(1024, log);
if (pool == NULL) { /* error */ }

s = ngx_palloc(pool, sizeof(ngx_str_t));
if (s == NULL) { /* error */ }
ngx_str_set(s, "foo");

p = ngx_pnalloc(pool, 3);
if (p == NULL) { /* error */ }
ngx_memcpy(p, "foo", 3);
```

链接节点(`ngx_chain_t`)在 Angie 中被积极使用,
因此 Angie 内存池实现提供了一种重用它们的方法。
`ngx_pool_t` 的 `chain` 字段保存了一个先前分配的链接节点列表,可供重用。
要在内存池中高效分配链接节点,请使用
`ngx_alloc_chain_link(pool)` 函数。
此函数在内存池列表中查找空闲的链接节点,如果内存池列表为空则分配新的链接节点。
要释放链接节点,请调用 `ngx_free_chain(pool, cl)` 函数。

可以在内存池中注册清理处理程序。
清理处理程序是一个带参数的回调函数,在内存池销毁时调用。
内存池通常与特定的 Angie 对象(如 HTTP 请求)绑定,并在对象到达其生命周期结束时销毁。
注册内存池清理是释放资源、关闭文件描述符或对与主对象关联的共享数据进行最终调整的便捷方式。

要注册内存池清理,请调用
`ngx_pool_cleanup_add(pool, size)`,它返回一个
`ngx_pool_cleanup_t` 指针供调用者填充。
使用 `size` 参数为清理处理程序分配上下文。

```c
ngx_pool_cleanup_t  *cln;

cln = ngx_pool_cleanup_add(pool, 0);
if (cln == NULL) { /* error */ }

cln->handler = ngx_my_cleanup;
cln->data = "foo";

...

static void
ngx_my_cleanup(void *data)
{
    u_char  *msg = data;

    ngx_do_smth(msg);
}
```

<a id="shared-memory"></a>

### 共享内存

Angie 使用共享内存在进程之间共享公共数据。
`ngx_shared_memory_add(cf, name, size, tag)` 函数向周期添加一个新的共享内存条目 `ngx_shm_zone_t`。
该函数接收区域的 `name` 和 `size`。
每个共享区域必须有唯一的名称。
如果具有提供的 `name` 和 `tag` 的共享区域条目已存在,则重用现有的区域条目。
如果具有相同名称的现有条目具有不同的标签,该函数将失败并返回错误。
通常,模块结构的地址作为 `tag` 传递,这使得可以在一个 Angie 模块内按名称重用共享区域。

共享内存条目结构 `ngx_shm_zone_t` 具有以下字段:

* `init` — 初始化回调,在共享区域映射到实际内存后调用
* `data` — 数据上下文,用于将任意数据传递给 `init` 回调
* `noreuse` — 禁用从旧周期重用共享区域的标志
* `tag` — 共享区域标签
* `shm` — 类型为 `ngx_shm_t` 的平台特定对象,至少具有以下字段:
  * `addr` — 映射的共享内存地址,初始为 NULL
  * `size` — 共享内存大小
  * `name` — 共享内存名称
  * `log` — 共享内存日志
  * `exists` — 指示共享内存是否从主进程继承的标志(Windows 特定)

共享区域条目在配置解析后在 `ngx_init_cycle()` 中映射到实际内存。
在 POSIX 系统上,使用 `mmap()` 系统调用创建共享匿名映射。
在 Windows 上,使用 `CreateFileMapping()`/`MapViewOfFileEx()` 对。

为了在共享内存中分配,Angie 提供了 slab 池 `ngx_slab_pool_t` 类型。
用于分配内存的 slab 池会自动在每个 Angie 共享区域中创建。
该池位于共享区域的开头,可以通过表达式 `(ngx_slab_pool_t *) shm_zone->shm.addr` 访问。
要在共享区域中分配内存,请调用
`ngx_slab_alloc(pool, size)` 或
`ngx_slab_calloc(pool, size)`。
要释放内存,请调用 `ngx_slab_free(pool, p)`。

slab 池将所有共享区域划分为页面。
每个页面用于分配相同大小的对象。
指定的大小必须是 2 的幂,且大于最小大小 8 字节。
不符合的值会向上舍入。
每个页面的位掩码跟踪哪些块正在使用,哪些块可供分配。
对于大于半页(通常为 2048 字节)的大小,分配一次完成整个页面。

要保护共享内存中的数据免受并发访问,请使用 `ngx_slab_pool_t` 的 `mutex` 字段中可用的互斥锁。
互斥锁最常用于 slab 池在分配和释放内存时,但它也可用于保护在共享区域中分配的任何其他用户数据结构。
要锁定或解锁互斥锁,请分别调用
`ngx_shmtx_lock(&shpool->mutex)` 或
`ngx_shmtx_unlock(&shpool->mutex)`。

```c
ngx_str_t        name;
ngx_foo_ctx_t   *ctx;
ngx_shm_zone_t  *shm_zone;

ngx_str_set(&name, "foo");

/* allocate shared zone context */
ctx = ngx_pcalloc(cf->pool, sizeof(ngx_foo_ctx_t));
if (ctx == NULL) {
    /* error */
}

/* add an entry for 64k shared zone */
shm_zone = ngx_shared_memory_add(cf, &name, 65536, &ngx_foo_module);
if (shm_zone == NULL) {
    /* error */
}

/* register init callback and context */
shm_zone->init = ngx_foo_init_zone;
shm_zone->data = ctx;


...


static ngx_int_t
ngx_foo_init_zone(ngx_shm_zone_t *shm_zone, void *data)
{
    ngx_foo_ctx_t  *octx = data;

    size_t            len;
    ngx_foo_ctx_t    *ctx;
    ngx_slab_pool_t  *shpool;

    value = shm_zone->data;

    if (octx) {
        /* reusing a shared zone from old cycle */
        ctx->value = octx->value;
        return NGX_OK;
    }

    shpool = (ngx_slab_pool_t *) shm_zone->shm.addr;

    if (shm_zone->shm.exists) {
        /* initialize shared zone context in Windows Angie worker */
        ctx->value = shpool->data;
        return NGX_OK;
    }

    /* initialize shared zone */

    ctx->value = ngx_slab_alloc(shpool, sizeof(ngx_uint_t));
    if (ctx->value == NULL) {
        return NGX_ERROR;
    }

    shpool->data = ctx->value;

    return NGX_OK;
}
```

<a id="logging-1"></a>

### 日志

Angie 使用 `ngx_log_t` 对象进行日志记录。
Angie 日志记录器支持多种输出类型:

* stderr — 记录到标准错误(stderr)
* file — 记录到文件
* syslog — 记录到 syslog
* memory — 记录到内部内存存储以用于开发目的;可以稍后使用调试器访问内存

日志记录器实例可以是日志记录器链,通过 `next` 字段相互链接。
在这种情况下,每条消息都会写入链中的所有日志记录器。

对于每个日志记录器,严重性级别控制将哪些消息写入日志(仅记录分配了该级别或更高级别的事件)。
支持以下严重性级别:

* `NGX_LOG_EMERG`
* `NGX_LOG_ALERT`
* `NGX_LOG_CRIT`
* `NGX_LOG_ERR`
* `NGX_LOG_WARN`
* `NGX_LOG_NOTICE`
* `NGX_LOG_INFO`
* `NGX_LOG_DEBUG`

对于调试日志记录,还会检查调试掩码。
调试掩码包括:

* `NGX_LOG_DEBUG_CORE`
* `NGX_LOG_DEBUG_ALLOC`
* `NGX_LOG_DEBUG_MUTEX`
* `NGX_LOG_DEBUG_EVENT`
* `NGX_LOG_DEBUG_HTTP`
* `NGX_LOG_DEBUG_MAIL`
* `NGX_LOG_DEBUG_STREAM`

通常,日志记录器由现有的 Angie 代码从 `error_log` 指令创建,
并在周期、配置、客户端连接和其他对象的几乎每个阶段都可用。

Angie 提供以下日志记录宏:

* `ngx_log_error(level, log, err, fmt, ...)` — 错误日志记录
* `ngx_log_debug0(level, log, err, fmt)`,
  `ngx_log_debug1(level, log, err, fmt, arg1)` 等 — 调试日志记录,
  最多支持八个格式化参数

日志消息在栈上大小为 `NGX_MAX_ERROR_STR`(当前为 2048 字节)的缓冲区中格式化。
消息前面会加上严重性级别、进程 ID(PID)、连接 ID(存储在 :samp:`log->connection` 中)和系统错误文本。
对于非调试消息,还会调用 `log->handler` 以在日志消息前添加更多特定信息。
HTTP 模块将 `ngx_http_log_error()` 函数设置为日志处理程序,
以记录客户端和服务器地址、当前操作(存储在 `log->action` 中)、客户端请求行、服务器名称等。

```c
/* specify what is currently done */
log->action = "sending mp4 to client";

/* error and debug log */
ngx_log_error(NGX_LOG_INFO, c->log, 0, "client prematurely
              closed connection");

ngx_log_debug2(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0,
               "mp4 start:%ui, length:%ui", mp4->start, mp4->length);
```

上面的示例会产生如下日志条目:

```text
2016/09/16 22:08:52 [info] 17445#0: *1 client prematurely closed connection while
sending mp4 to client, client: 127.0.0.1, server: , request: "GET /file.mp4 HTTP/1.1"
2016/09/16 23:28:33 [debug] 22140#0: *1 mp4 start:0, length:10000
```

<a id="cycles"></a>

### 周期

周期对象存储从特定配置创建的 Angie 运行时上下文。
其类型为 `ngx_cycle_t`。
当前周期由 `ngx_cycle` 全局变量引用,
并在 Angie worker 启动时被继承。
每次重新加载 Angie 配置时,都会从新的 Angie 配置创建一个新周期;
旧周期通常在新周期成功创建后被删除。

周期由 `ngx_init_cycle()` 函数创建,
该函数将前一个周期作为其参数。
该函数定位前一个周期的配置文件并尽可能多地从前一个周期继承资源。
在 Angie 启动时会创建一个名为"init cycle"的占位符周期,
然后被从配置构建的实际周期替换。

周期的成员包括:

* `pool` — 周期池。
  为每个新周期创建。
* `log` — 周期日志。
  最初从旧周期继承,在读取配置后设置为指向 `new_log`。
* `new_log` — 周期日志,由配置创建。
  受根作用域 `error_log` 指令影响。
* `connections`, `connection_n` —
  类型为 `ngx_connection_t` 的连接数组,
  由事件模块在初始化每个 Angie worker 时创建。
  Angie 配置中的 `worker_connections` 指令设置连接数 `connection_n`。
* `free_connections`,
  `free_connection_n` — 当前可用连接的列表和数量。
  如果没有可用连接,Angie worker 将拒绝接受新客户端或连接到上游服务器。
* `files`, `files_n` — 用于将文件描述符映射到 Angie 连接的数组。
  此映射由具有 `NGX_USE_FD_EVENT` 标志的事件模块使用
  (当前为 `poll` 和 `devpoll`)。
* `conf_ctx` — 核心模块配置数组。
  配置在读取 Angie 配置文件时创建和填充。
* `modules`, `modules_n` — 类型为 `ngx_module_t` 的模块数组,
  包括当前配置加载的静态和动态模块。
* `listening` — 类型为 `ngx_listening_t` 的监听对象数组。
  监听对象通常由调用 `ngx_create_listening()` 函数的不同模块的
  `listen` 指令添加。
  监听套接字基于监听对象创建。
* `paths` — 类型为 `ngx_path_t` 的路径数组。
  路径由将要操作某些目录的模块调用 `ngx_add_path()` 函数添加。
  如果缺少这些目录,Angie 会在读取配置后创建它们。
  此外,可以为每个路径添加两个处理程序:
  * path loader — 在启动或重新加载 Angie 后 60 秒内仅执行一次。
    通常,加载器读取目录并将数据存储在 Angie 共享内存中。
    该处理程序从专用的 Angie 进程"cache loader"调用。
  * path manager — 定期执行。
    通常,管理器从目录中删除旧文件并更新 Angie 内存以反映更改。
    该处理程序从专用的"cache manager"进程调用。
* `open_files` — 类型为 `ngx_open_file_t` 的打开文件对象列表,
  通过调用 `ngx_conf_open_file()` 函数创建。
  目前,Angie 将这种打开文件用于日志记录。
  读取配置后,Angie 打开 `open_files` 列表中的所有文件,
  并将每个文件描述符存储在对象的 `fd` 字段中。
  文件以追加模式打开,如果缺失则创建。
  列表中的文件在 Angie worker 收到重新打开信号(最常见的是 `USR1`)时重新打开。
  在这种情况下,:samp:fd 字段中的描述符会更改为新值。
* `shared_memory` — 共享内存区域列表,
  每个通过调用 `ngx_shared_memory_add()` 函数添加。
  共享区域在所有 Angie 进程中映射到相同的地址范围,
  用于共享公共数据,例如 HTTP 缓存内存树。

<a id="buffer"></a>

### Buffer

对于输入/输出操作,Angie 提供了缓冲区类型
`ngx_buf_t`。
通常,它用于保存要写入目标或从源读取的数据。
缓冲区可以引用内存中的数据或文件中的数据,从技术上讲,缓冲区可以同时引用两者。
缓冲区的内存是单独分配的,与缓冲区结构
`ngx_buf_t` 无关。

`ngx_buf_t` 结构具有以下字段:

* `start`、`end` — 为缓冲区分配的内存块的边界。
* `pos`、`last` — 内存缓冲区的边界;通常是 `start` .. `end` 的子范围。
* `file_pos`、`file_last` — 文件缓冲区的边界,表示为从文件开头的偏移量。
* `tag` — 用于区分缓冲区的唯一值;由不同的 Angie 模块创建,通常用于缓冲区重用。
* `file` — 文件对象。
* `temporary` — 标志,指示缓冲区引用可写内存。
* `memory` — 标志,指示缓冲区引用只读内存。
* `in_file` — 标志,指示缓冲区引用文件中的数据。
* `flush` — 标志,指示需要刷新缓冲区之前的所有数据。
* `recycled` — 标志,指示缓冲区可以重用,需要尽快消费。
* `sync` — 标志,指示缓冲区不携带数据或特殊信号,如 `flush` 或 `last_buf`。
  默认情况下,Angie 将此类缓冲区视为错误条件,但此标志告诉 Angie 跳过错误检查。
* `last_buf` — 标志,指示缓冲区是输出中的最后一个。
* `last_in_chain` — 标志,指示请求或子请求中没有更多数据缓冲区。
* `shadow` — 对与当前缓冲区相关的另一个("影子")缓冲区的引用,通常意味着缓冲区使用来自影子的数据。
  当缓冲区被消费时,影子缓冲区通常也会被标记为已消费。
* `last_shadow` — 标志,指示缓冲区是引用特定影子缓冲区的最后一个。
* `temp_file` — 标志,指示缓冲区位于临时文件中。

对于输入和输出操作,缓冲区以链的形式链接。
链是类型为 `ngx_chain_t` 的链节点序列,定义如下:

```c
typedef struct ngx_chain_s  ngx_chain_t;

struct ngx_chain_s {
    ngx_buf_t    *buf;
    ngx_chain_t  *next;
};
```

每个链节点保存对其缓冲区的引用和对下一个链节点的引用。

使用缓冲区和链的示例:

```c
ngx_chain_t *
ngx_get_my_chain(ngx_pool_t *pool)
{
    ngx_buf_t    *b;
    ngx_chain_t  *out, *cl, **ll;

    /* first buf */
    cl = ngx_alloc_chain_link(pool);
    if (cl == NULL) { /* error */ }

    b = ngx_calloc_buf(pool);
    if (b == NULL) { /* error */ }

    b->start = (u_char *) "foo";
    b->pos = b->start;
    b->end = b->start + 3;
    b->last = b->end;
    b->memory = 1; /* read-only memory */

    cl->buf = b;
    out = cl;
    ll = &cl->next;

    /* second buf */
    cl = ngx_alloc_chain_link(pool);
    if (cl == NULL) { /* error */ }

    b = ngx_create_temp_buf(pool, 3);
    if (b == NULL) { /* error */ }

    b->last = ngx_cpymem(b->last, "foo", 3);

    cl->buf = b;
    cl->next = NULL;
    *ll = cl;

    return out;
}
```

<a id="networking"></a>

## 网络

<a id="connections"></a>

### 连接

连接类型 `ngx_connection_t` 是套接字描述符的包装器。
它包括以下字段:

* `fd` — 套接字描述符
* `data` — 任意连接上下文。
  通常,它是指向构建在连接之上的更高级别对象的指针,例如 HTTP 请求或 Stream 会话。
* `read`、`write` — 连接的读和写事件。
* `recv`、`send`、
  `recv_chain`、`send_chain` — 连接的 I/O 操作。
* `pool` — 连接池。
* `log` — 连接日志。
* `sockaddr`、`socklen`、
  `addr_text` — 二进制和文本形式的远程套接字地址。
* `local_sockaddr`、`local_socklen` — 二进制形式的本地套接字地址。
  最初,这些字段为空。
  使用 `ngx_connection_local_sockaddr()` 函数获取本地套接字地址。
* `proxy_protocol_addr`、`proxy_protocol_port`
  — PROXY protocol 客户端地址和端口,如果为连接启用了 PROXY protocol。
* `ssl` — 连接的 SSL 上下文。
* `reusable` — 标志,指示连接处于使其有资格重用的状态。
* `close` — 标志,指示连接正在被重用,需要关闭。

Angie 连接可以透明地封装 SSL 层。
在这种情况下,连接的 `ssl` 字段保存指向
`ngx_ssl_connection_t` 结构的指针,该结构保存连接的所有 SSL 相关数据,包括 `SSL_CTX` 和
`SSL`。
`recv`、`send`、
`recv_chain` 和 `send_chain` 处理程序也设置为支持 SSL 的函数。

Angie 配置中的 `worker_connections` 指令限制每个 Angie worker 的连接数。
所有连接结构在 worker 启动时预先创建,并存储在 cycle 对象的 `connections` 字段中。
要检索连接结构,使用
`ngx_get_connection(s, log)` 函数。
它将套接字描述符作为其 `s` 参数,该描述符需要包装在连接结构中。

由于每个 worker 的连接数有限,Angie 提供了一种获取当前正在使用的连接的方法。
要启用或禁用连接的重用,调用
`ngx_reusable_connection(c, reusable)` 函数。
调用 `ngx_reusable_connection(c, 1)` 在连接结构中设置
`reuse` 标志,并将连接插入到 cycle 的
`reusable_connections_queue` 中。
每当 `ngx_get_connection()` 发现 cycle 的 `free_connections` 列表中没有可用连接时,它会调用 `ngx_drain_connections()` 来释放特定数量的可重用连接。
对于每个这样的连接,设置 `close` 标志并调用其读处理程序,该处理程序应该通过调用
`ngx_close_connection(c)` 释放连接并使其可供重用。
要退出连接可以重用的状态,调用
`ngx_reusable_connection(c, 0)`。
HTTP 客户端连接是 Angie 中可重用连接的一个示例;它们被标记为可重用,直到从客户端接收到第一个请求字节。

<a id="events-1"></a>

## 事件

<a id="event"></a>

### 事件

Angie 中的事件对象 `ngx_event_t` 提供了一种机制,用于通知特定事件已发生。

`ngx_event_t` 中的字段包括:

* `data` — 事件处理程序中使用的任意事件上下文,通常作为指向与事件相关的连接的指针。
* `handler` — 事件发生时要调用的回调函数。
* `write` — 标志,指示写事件。
  缺少该标志表示读事件。
* `active` — 标志,指示事件已注册以接收 I/O 通知,通常来自通知机制,如
  `epoll`、`kqueue`、`poll`。
* `ready` — 标志,指示事件已收到 I/O 通知。
* `delayed` — 标志,指示由于速率限制而延迟 I/O。
* `timer` — 用于将事件插入定时器树的红黑树节点。
* `timer_set` — 标志,指示事件定时器已设置且尚未过期。
* `timedout` — 标志,指示事件定时器已过期。
* `eof` — 标志,指示读取数据时发生 EOF。
* `pending_eof` — 标志,指示套接字上挂起 EOF,即使可能在它之前有一些可用数据。
  该标志通过 `EPOLLRDHUP`
  `epoll` 事件或
  `EV_EOF` `kqueue` 标志传递。
* `error` — 标志,指示在读取(对于读事件)或写入(对于写事件)期间发生错误。
* `cancelable` — 定时器事件标志,指示在关闭 worker 时应忽略该事件。
  优雅的 worker 关闭会延迟,直到没有计划的不可取消定时器事件。
* `posted` — 标志,指示事件已发布到队列。
* `queue` — 用于将事件发布到队列的队列节点。

<a id="i-o-events"></a>

### I/O 事件

通过调用 `ngx_get_connection()` 函数获得的每个连接都附加了两个事件,:samp:c->read 和
`c->write`,用于接收套接字准备好读取或写入的通知。
所有此类事件都在边缘触发模式下运行,这意味着它们仅在套接字状态更改时触发通知。
例如,在套接字上执行部分读取不会使 Angie 在更多数据到达套接字之前传递重复的读通知。
即使底层 I/O 通知机制本质上是水平触发(`poll`、`select` 等),Angie 也会将通知转换为边缘触发。
为了使 Angie 事件通知在不同平台上的所有通知系统中保持一致,必须在处理 I/O 套接字通知或在该套接字上调用任何 I/O 函数后调用函数
`ngx_handle_read_event(rev, flags)` 和
`ngx_handle_write_event(wev, lowat)`。
通常,这些函数在每个读或写事件处理程序结束时调用一次。

<a id="timer-events"></a>

### 定时器事件

可以将事件设置为在超时到期时发送通知。
事件使用的定时器从某个未指定的点开始计算毫秒数,截断为 `ngx_msec_t` 类型。
其当前值可以从 `ngx_current_msec` 变量获得。

函数 `ngx_add_timer(ev, timer)` 为事件设置超时,:samp:ngx_del_timer(ev) 删除先前设置的超时。
全局超时红黑树 `ngx_event_timer_rbtree` 存储当前设置的所有超时。
树中的键类型为 `ngx_msec_t`,是事件发生的时间。
树结构支持快速插入和删除操作,以及访问最近的超时,Angie 使用它来确定等待 I/O 事件的时间以及使超时事件过期。

<a id="posted-events"></a>

### 发布的事件

事件可以被发布,这意味着其处理程序将在当前事件循环迭代中的某个时刻稍后调用。
发布事件是简化代码和避免栈溢出的良好做法。
发布的事件保存在发布队列中。
`ngx_post_event(ev, q)` 宏将事件
`ev` 发布到发布队列 `q`。
`ngx_delete_posted_event(ev)` 宏从其当前发布的队列中删除事件
`ev`。
通常,事件被发布到 `ngx_posted_events` 队列,该队列在事件循环的后期处理 — 在所有 I/O 和定时器事件都已处理之后。
调用函数 `ngx_event_process_posted()` 来处理事件队列。
它调用事件处理程序,直到队列为空。
这意味着发布的事件处理程序可以发布更多事件,以便在当前事件循环迭代中处理。

示例:

```c
void
ngx_my_connection_read(ngx_connection_t *c)
{
    ngx_event_t  *rev;

    rev = c->read;

    ngx_add_timer(rev, 1000);

    rev->handler = ngx_my_read_handler;

    ngx_my_read(rev);
}


void
ngx_my_read_handler(ngx_event_t *rev)
{
    ssize_t            n;
    ngx_connection_t  *c;
    u_char             buf[256];

    if (rev->timedout) { /* timeout expired */ }

    c = rev->data;

    while (rev->ready) {
        n = c->recv(c, buf, sizeof(buf));

        if (n == NGX_AGAIN) {
            break;
        }

        if (n == NGX_ERROR) { /* error */ }

        /* process buf */
    }

    if (ngx_handle_read_event(rev, 0) != NGX_OK) { /* error */ }
}
```

<a id="event-loop"></a>

### 事件循环

除了 Angie 主进程外,所有 Angie 进程都执行 I/O,因此都有事件循环。
(Angie 主进程大部分时间都花在 `sigsuspend()` 调用中等待信号到达。)
Angie 事件循环在
`ngx_process_events_and_timers()` 函数中实现,该函数会重复调用,直到进程退出。

事件循环具有以下阶段:

* 通过调用
  `ngx_event_find_timer()` 查找最接近过期的超时。
  此函数查找定时器树中最左边的节点,并返回节点过期前的毫秒数。
* 通过调用特定于事件通知机制的处理程序来处理 I/O 事件,该处理程序由 Angie 配置选择。
  此处理程序至少等待一个 I/O 事件发生,但仅等到下一个超时到期。
  当发生读或写事件时,设置 `ready` 标志并调用事件的处理程序。
  对于 Linux,通常使用 `ngx_epoll_process_events()` 处理程序,它调用 `epoll_wait()` 等待 I/O 事件。
* 通过调用 `ngx_event_expire_timers()` 使定时器过期。
  从最左边的元素到右边迭代定时器树,直到找到未过期的超时。
  对于每个过期的节点,设置 `timedout` 事件标志,重置 `timer_set` 标志,并调用事件处理程序。
* 通过调用 `ngx_event_process_posted()` 处理发布的事件。
  该函数重复从发布的事件队列中删除第一个元素并调用该元素的处理程序,直到队列为空。

所有 Angie 进程也处理信号。
信号处理程序仅设置全局变量,这些变量在
`ngx_process_events_and_timers()` 调用后检查。

<a id="processes"></a>

### 进程

Angie 中有几种类型的进程。
进程的类型保存在 `ngx_process`
全局变量中，可以是以下值之一：

* `NGX_PROCESS_MASTER` — master 进程，读取
  NGINX 配置，创建 cycle，并启动和控制子进程。
  它不执行任何 I/O，仅响应信号。
  其 cycle 函数是 `ngx_master_process_cycle()`。
* `NGX_PROCESS_WORKER` — worker 进程，处理客户端
  连接。
  它由 master 进程启动，并响应其信号和 channel
  命令。
  其 cycle 函数是 `ngx_worker_process_cycle()`。
  可以有多个 worker 进程，由
  `worker_processes` 指令配置。
* `NGX_PROCESS_SINGLE` — single 进程，仅存在于
  `master_process off` 模式下，是该模式下运行的唯一进程。
  它创建 cycle（像 master 进程一样）并处理客户端连接
  （像 worker 进程一样）。
  其 cycle 函数是 `ngx_single_process_cycle()`。
* `NGX_PROCESS_HELPER` — helper 进程，目前
  有两种类型：cache manager 和 cache loader。
  两者的 cycle 函数都是
  `ngx_cache_manager_process_cycle()`。

Angie 进程处理以下信号：

* `NGX_SHUTDOWN_SIGNAL`（在大多数系统上是 :samp:`SIGQUIT`）— 优雅关闭。
  收到此信号后，master 进程向所有
  子进程发送关闭信号。
  当没有子进程剩余时，master 销毁 cycle 池并退出。
  当 worker 进程收到此信号时，它关闭所有监听套接字并
  等待直到没有不可取消的事件被调度，然后销毁
  cycle 池并退出。
  当 cache manager 或 cache loader 进程收到此信号时，它
  立即退出。
  当进程收到此信号时，`ngx_quit` 变量被设置为 `1`，
  并在处理后立即重置。
  当 worker 进程处于关闭状态时，`ngx_exiting` 变量被设置为 `1`。
* `NGX_TERMINATE_SIGNAL`（在大多数系统上是 :samp:`SIGTERM`）— 终止。
  收到此信号后，master 进程向所有
  子进程发送终止信号。
  如果子进程在 1 秒内未退出，master 进程发送
  `SIGKILL` 信号来杀死它。
  当没有子进程剩余时，master 进程销毁 cycle 池并
  退出。
  当 worker 进程、cache manager 进程或 cache loader 进程
  收到此信号时，它销毁 cycle 池并退出。
  收到此信号时，变量 `ngx_terminate` 被设置为 `1`。
* `NGX_NOACCEPT_SIGNAL`（在大多数系统上是 :samp:`SIGWINCH`）— 关闭所有 worker 和 helper 进程。
  收到此信号后，master 进程关闭其子进程。
  如果先前启动的新 Angie 二进制文件退出，旧
  master 的子进程将再次启动。
  当 worker 进程收到此信号时，它在由 `debug_points` 指令设置的调试模式下关闭。
* `NGX_RECONFIGURE_SIGNAL`（在大多数系统上是 :samp:`SIGHUP`）— 重新配置。
  收到此信号后，master 进程重新读取配置并
  基于它创建一个新的 cycle。
  如果新 cycle 创建成功，旧 cycle 被删除并启动新的
  子进程。
  同时，旧的子进程接收
  `NGX_SHUTDOWN_SIGNAL` 信号。
  在 single-process 模式下，Angie 创建一个新 cycle，但保留旧的 cycle，
  直到不再有客户端与其绑定的活动连接。
  worker 和 helper 进程忽略此信号。
* `NGX_REOPEN_SIGNAL`（在大多数系统上是 :samp:`SIGUSR1`）— 重新打开文件。
  master 进程将此信号发送给 worker，worker 重新打开所有
  与 cycle 相关的 `open_files`。
* `NGX_CHANGEBIN_SIGNAL`（在大多数系统上是 :samp:`SIGUSR2`）— 更改 Angie 二进制文件。
  master 进程启动一个新的 Angie 二进制文件并传入所有监听
  套接字的列表。
  在 `"NGINX"` 环境变量中传递的文本格式列表，
  由用分号分隔的描述符编号组成。
  新的 Angie 二进制文件读取 `"NGINX"` 变量并将
  套接字添加到其 init cycle。
  其他进程忽略此信号。

虽然所有 Angie worker 进程都能够接收并正确处理 POSIX
信号，但 master 进程不使用标准 `kill()`
系统调用来向 worker 和 helper 传递信号。
相反，Angie 使用进程间套接字对，允许在所有 Angie 进程之间发送消息。
但是，目前消息仅从 master 发送到其子进程。
消息携带标准信号。

<a id="threading"></a>

### 线程

可以将原本会阻塞 Angie worker 进程的任务卸载到单独的线程中。
例如，Angie 可以配置为使用线程执行
[文件 I/O](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#aio)。
另一个用例是没有异步接口的库，
因此无法正常与 Angie 一起使用。
请记住，线程接口是现有异步方法处理客户端连接的辅助工具，
绝不是替代品。

为了处理同步，提供了以下对
`pthreads` 原语的包装：

* `typedef pthread_mutex_t  ngx_thread_mutex_t;`
  * `ngx_int_t
    ngx_thread_mutex_create(ngx_thread_mutex_t *mtx, ngx_log_t *log);`
  * `ngx_int_t
    ngx_thread_mutex_destroy(ngx_thread_mutex_t *mtx, ngx_log_t *log);`
  * `ngx_int_t
    ngx_thread_mutex_lock(ngx_thread_mutex_t *mtx, ngx_log_t *log);`
  * `ngx_int_t
    ngx_thread_mutex_unlock(ngx_thread_mutex_t *mtx, ngx_log_t *log);`
* `typedef pthread_cond_t  ngx_thread_cond_t;`
  * `ngx_int_t
    ngx_thread_cond_create(ngx_thread_cond_t *cond, ngx_log_t *log);`
  * `ngx_int_t
    ngx_thread_cond_destroy(ngx_thread_cond_t *cond, ngx_log_t *log);`
  * `ngx_int_t
    ngx_thread_cond_signal(ngx_thread_cond_t *cond, ngx_log_t *log);`
  * `ngx_int_t
    ngx_thread_cond_wait(ngx_thread_cond_t *cond, ngx_thread_mutex_t *mtx,
    ngx_log_t *log);`

Angie 实现了 [thread_pool](https://cn.angie.software//angie/docs/configuration/modules/core.md#thread-pool) 策略，
而不是为每个任务创建一个新线程。
可以为不同的目的配置多个线程池
（例如，在不同的磁盘集上执行 I/O）。
每个线程池在启动时创建，包含有限数量的线程，
这些线程处理任务队列。
当任务完成时，会调用预定义的完成处理程序。

`src/core/ngx_thread_pool.h` 头文件包含
相关定义：

```c
struct ngx_thread_task_s {
    ngx_thread_task_t   *next;
    ngx_uint_t           id;
    void                *ctx;
    void               (*handler)(void *data, ngx_log_t *log);
    ngx_event_t          event;
};

typedef struct ngx_thread_pool_s  ngx_thread_pool_t;

ngx_thread_pool_t *ngx_thread_pool_add(ngx_conf_t *cf, ngx_str_t *name);
ngx_thread_pool_t *ngx_thread_pool_get(ngx_cycle_t *cycle, ngx_str_t *name);

ngx_thread_task_t *ngx_thread_task_alloc(ngx_pool_t *pool, size_t size);
ngx_int_t ngx_thread_task_post(ngx_thread_pool_t *tp, ngx_thread_task_t *task);
```

在配置时，希望使用线程的模块必须通过调用
`ngx_thread_pool_add(cf, name)` 获得对线程池的引用，
该函数要么创建一个具有给定 `name` 的新线程池，
要么返回对该名称的池的引用（如果它已经存在）。

要在运行时将 `task` 添加到指定线程池
`tp` 的队列中，使用
`ngx_thread_task_post(tp, task)` 函数。

要在线程中执行函数，传递参数并设置完成
处理程序，使用 `ngx_thread_task_t` 结构：

```c
typedef struct {
    int    foo;
} my_thread_ctx_t;


static void
my_thread_func(void *data, ngx_log_t *log)
{
    my_thread_ctx_t *ctx = data;

    /* this function is executed in a separate thread */
}


static void
my_thread_completion(ngx_event_t *ev)
{
    my_thread_ctx_t *ctx = ev->data;

    /* executed in Angie event loop */
}


ngx_int_t
my_task_offload(my_conf_t *conf)
{
    my_thread_ctx_t    *ctx;
    ngx_thread_task_t  *task;

    task = ngx_thread_task_alloc(conf->pool, sizeof(my_thread_ctx_t));
    if (task == NULL) {
        return NGX_ERROR;
    }

    ctx = task->ctx;

    ctx->foo = 42;

    task->handler = my_thread_func;
    task->event.handler = my_thread_completion;
    task->event.data = ctx;

    if (ngx_thread_task_post(conf->thread_pool, task) != NGX_OK) {
        return NGX_ERROR;
    }

    return NGX_OK;
}
```

<a id="modules-1"></a>

## 模块

<a id="adding-new-modules"></a>

### 添加新模块

每个独立的 Angie 模块都位于一个单独的目录中，该目录至少包含两个文件：
`config` 和一个包含模块源代码的文件。
`config` 文件包含 Angie 集成模块所需的所有信息，例如：

```bash
ngx_module_type=CORE
ngx_module_name=ngx_foo_module
ngx_module_srcs="$ngx_addon_dir/ngx_foo_module.c"

. auto/module

ngx_addon_name=$ngx_module_name
```

`config` 文件是一个 POSIX shell 脚本，可以设置
和访问以下变量：

* `ngx_module_type` — 要构建的模块类型。
  可能的值是 `CORE`、`HTTP`、
  `HTTP_FILTER`、`HTTP_INIT_FILTER`、
  `HTTP_AUX_FILTER`、`MAIL`、
  `STREAM` 或 `MISC`。
* `ngx_module_name` — 模块名称。
  要从一组源文件构建多个模块，请指定一个
  以空格分隔的名称列表。
  第一个名称表示动态模块的输出二进制文件的名称。
  列表中的名称必须与源代码中使用的名称匹配。
* `ngx_addon_name` — 模块的名称，显示在
  configure 脚本的控制台输出中。
* `ngx_module_srcs` — 用于编译模块的源
  文件的空格分隔列表。
  `$ngx_addon_dir` 变量可用于表示模块目录的路径。
* `ngx_module_incs` — 构建模块所需的包含路径
* `ngx_module_deps` — 模块依赖项的空格分隔列表。
  通常，它是头文件的列表。
* `ngx_module_libs` — 要与模块链接的库的空格分隔列表。
  例如，使用 `ngx_module_libs=-lpthread` 来链接
  `libpthread` 库。
  以下宏可用于链接与 Angie 相同的库：
  `LIBXSLT`、`LIBGD`、`GEOIP`、
  `PCRE`、`OPENSSL`、`MD5`、
  `SHA1`、`ZLIB` 和 `PERL`。
* `ngx_module_link` — 由构建系统设置为
  `DYNAMIC`（用于动态模块）或 :samp:`ADDON`
  （用于静态模块）的变量，用于根据链接类型确定要执行的不同操作。
* `ngx_module_order` — 模块的加载顺序；
  对 `HTTP_FILTER` 和
  `HTTP_AUX_FILTER` 模块类型很有用。
  此选项的格式是一个以空格分隔的模块列表。
  列表中当前模块名称之后的所有模块在
  全局模块列表中排在它之后，这设置了模块初始化的顺序。
  对于过滤器模块，较晚的初始化意味着较早的执行。

  以下模块通常用作参考。
  `ngx_http_copy_filter_module` 为其他过滤器模块读取数据，
  并放置在列表的底部附近，因此它是最先执行的模块之一。
  `ngx_http_write_filter_module` 将数据写入客户端套接字，
  并放置在列表的顶部附近，是最后执行的模块。

  默认情况下，过滤器模块放置在模块列表中
  `ngx_http_copy_filter` 之前，因此过滤器处理程序在复制过滤器处理程序之后执行。
  对于其他模块类型，默认值是空字符串。

要将模块静态编译到 Angie 中，使用
`--add-module=/path/to/module` 参数传递给 configure
脚本。
要将模块编译为稍后动态加载到 Angie 中，使用
`--add-dynamic-module=/path/to/module` 参数。

<a id="core-modules"></a>

### 核心模块

模块是 Angie 的构建块,其大部分功能都是作为模块实现的。
模块源文件必须包含一个 `ngx_module_t` 类型的全局变量,其定义如下:

```c
struct ngx_module_s {

    /* 省略私有部分 */

    void                 *ctx;
    ngx_command_t        *commands;
    ngx_uint_t            type;

    ngx_int_t           (*init_master)(ngx_log_t *log);

    ngx_int_t           (*init_module)(ngx_cycle_t *cycle);

    ngx_int_t           (*init_process)(ngx_cycle_t *cycle);
    ngx_int_t           (*init_thread)(ngx_cycle_t *cycle);
    void                (*exit_thread)(ngx_cycle_t *cycle);
    void                (*exit_process)(ngx_cycle_t *cycle);

    void                (*exit_master)(ngx_cycle_t *cycle);

    /* 省略未来扩展的存根 */
};
```

省略的私有部分包括模块版本和签名,使用预定义的宏 `NGX_MODULE_V1` 填充。

每个模块在 `ctx` 字段中保存其私有数据,
识别在 `commands` 数组中指定的配置指令,并可在 Angie 生命周期的特定阶段被调用。
模块生命周期包含以下事件:

* 配置指令处理程序在配置文件中出现时被调用,在主进程的上下文中。
* 配置成功解析后,在主进程的上下文中调用 `init_module` 处理程序。
  每次加载配置时,都会在主进程中调用 `init_module` 处理程序。
* 主进程创建一个或多个工作进程,并在每个工作进程中调用 `init_process` 处理程序。
* 当工作进程从主进程接收到关闭或终止命令时,它调用 `exit_process` 处理程序。
* 主进程在退出前调用 `exit_master` 处理程序。

由于线程在 Angie 中仅用作具有自己 API 的辅助 I/O 设施,因此 `init_thread` 和 `exit_thread` 处理程序目前不会被调用。
也没有 `init_master` 处理程序,因为这会是不必要的开销。

模块 `type` 准确定义了 `ctx` 字段中存储的内容。
其值为以下类型之一:

* `NGX_CORE_MODULE`
* `NGX_EVENT_MODULE`
* `NGX_HTTP_MODULE`
* `NGX_MAIL_MODULE`
* `NGX_STREAM_MODULE`

`NGX_CORE_MODULE` 是最基本的,因此也是最通用和最低级的模块类型。
其他模块类型在其之上实现,并提供更便捷的方式来处理相应的领域,如处理事件或 HTTP 请求。

核心模块集包括 `ngx_core_module`、
`ngx_errlog_module`、`ngx_regex_module`、
`ngx_thread_pool_module` 和
`ngx_openssl_module` 模块。
HTTP 模块、stream 模块、mail 模块和 event 模块也是核心模块。
核心模块的上下文定义为:

```c
typedef struct {
    ngx_str_t             name;
    void               *(*create_conf)(ngx_cycle_t *cycle);
    char               *(*init_conf)(ngx_cycle_t *cycle, void *conf);
} ngx_core_module_t;
```

其中 `name` 是模块名称字符串,
`create_conf` 和 `init_conf` 是指向创建和初始化模块配置的函数的指针。
对于核心模块,Angie 在解析新配置之前调用 `create_conf`,在所有配置成功解析后调用 `init_conf`。
典型的 `create_conf` 函数为配置分配内存并设置默认值。

例如，一个名为 `ngx_foo_module` 的简单模块可能如下所示：

```c
/*
 * Copyright (C) Author.
 */


#include <ngx_config.h>
#include <ngx_core.h>


typedef struct {
    ngx_flag_t  enable;
} ngx_foo_conf_t;


static void *ngx_foo_create_conf(ngx_cycle_t *cycle);
static char *ngx_foo_init_conf(ngx_cycle_t *cycle, void *conf);

static char *ngx_foo_enable(ngx_conf_t *cf, void *post, void *data);
static ngx_conf_post_t  ngx_foo_enable_post = { ngx_foo_enable };


static ngx_command_t  ngx_foo_commands[] = {

    { ngx_string("foo_enabled"),
      NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_FLAG,
      ngx_conf_set_flag_slot,
      0,
      offsetof(ngx_foo_conf_t, enable),
      &ngx_foo_enable_post },

      ngx_null_command
};


static ngx_core_module_t  ngx_foo_module_ctx = {
    ngx_string("foo"),
    ngx_foo_create_conf,
    ngx_foo_init_conf
};


ngx_module_t  ngx_foo_module = {
    NGX_MODULE_V1,
    &ngx_foo_module_ctx,                   /* module context */
    ngx_foo_commands,                      /* module directives */
    NGX_CORE_MODULE,                       /* module type */
    NULL,                                  /* init master */
    NULL,                                  /* init module */
    NULL,                                  /* init process */
    NULL,                                  /* init thread */
    NULL,                                  /* exit thread */
    NULL,                                  /* exit process */
    NULL,                                  /* exit master */
    NGX_MODULE_V1_PADDING
};


static void *
ngx_foo_create_conf(ngx_cycle_t *cycle)
{
    ngx_foo_conf_t  *fcf;

    fcf = ngx_pcalloc(cycle->pool, sizeof(ngx_foo_conf_t));
    if (fcf == NULL) {
        return NULL;
    }

    fcf->enable = NGX_CONF_UNSET;

    return fcf;
}


static char *
ngx_foo_init_conf(ngx_cycle_t *cycle, void *conf)
{
    ngx_foo_conf_t *fcf = conf;

    ngx_conf_init_value(fcf->enable, 0);

    return NGX_CONF_OK;
}


static char *
ngx_foo_enable(ngx_conf_t *cf, void *post, void *data)
{
    ngx_flag_t  *fp = data;

    if (*fp == 0) {
        return NGX_CONF_OK;
    }

    ngx_log_error(NGX_LOG_NOTICE, cf->log, 0, "Foo Module is enabled");

    return NGX_CONF_OK;
}
```

<a id="configuration-directives"></a>

### 配置指令

`ngx_command_t` 类型定义单个配置指令。
每个支持配置的模块都提供一个此类结构的数组,描述如何处理参数以及调用哪些处理程序:

```c
typedef struct ngx_command_s  ngx_command_t;

struct ngx_command_s {
    ngx_str_t             name;
    ngx_uint_t            type;
    char               *(*set)(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
    ngx_uint_t            conf;
    ngx_uint_t            offset;
    void                 *post;
};
```

使用特殊值 `ngx_null_command` 终止数组。
`name` 是指令在配置文件中出现的名称,例如 "worker_processes" 或 "listen"。
`type` 是标志的位字段,指定指令接受的参数数量、其类型以及它出现的上下文。
标志包括:

* `NGX_CONF_NOARGS` — 指令不接受参数。
* `NGX_CONF_1MORE` — 指令接受一个或多个参数。
* `NGX_CONF_2MORE` — 指令接受两个或多个参数。
* `NGX_CONF_TAKE1` .. `NGX_CONF_TAKE7` —
  指令恰好接受指定数量的参数。
* `NGX_CONF_TAKE12`、`NGX_CONF_TAKE13`、
  `NGX_CONF_TAKE23`、`NGX_CONF_TAKE123`、
  `NGX_CONF_TAKE1234` — 指令可以接受不同数量的参数。
  选项限于指定的数字。
  例如,:samp:NGX_CONF_TAKE12 表示它接受一个或两个参数。

指令类型的标志:

* `NGX_CONF_BLOCK` — 指令是一个块,即它可以在其开闭大括号内包含其他指令,甚至实现自己的解析器来处理内部内容。
* `NGX_CONF_FLAG` — 指令接受布尔值,
  `on` 或 `off`。

指令上下文定义它可以出现在配置中的位置:

* `NGX_MAIN_CONF` — 在顶级上下文中。
* `NGX_HTTP_MAIN_CONF` — 在 `http` 块中。
* `NGX_HTTP_SRV_CONF` — 在 `http` 块内的 `server` 块中。
* `NGX_HTTP_LOC_CONF` — 在 `http` 块内的 `location` 块中。
* `NGX_HTTP_UPS_CONF` — 在 `http` 块内的 `upstream` 块中。
* `NGX_HTTP_SIF_CONF` — 在 `http` 块的 `server` 块内的 `if` 块中。
* `NGX_HTTP_LIF_CONF` — 在 `http` 块的 `location` 块内的 `if` 块中。
* `NGX_HTTP_LMT_CONF` — 在 `http` 块内的 `limit_except` 块中。
* `NGX_STREAM_MAIN_CONF` — 在 `stream` 块中。
* `NGX_STREAM_SRV_CONF` — 在 `stream` 块内的 `server` 块中。
* `NGX_STREAM_UPS_CONF` — 在 `stream` 块内的 `upstream` 块中。
* `NGX_MAIL_MAIN_CONF` — 在 `mail` 块中。
* `NGX_MAIL_SRV_CONF` — 在 `mail` 块内的 `server` 块中。
* `NGX_EVENT_CONF` — 在 `events` 块中。
* `NGX_DIRECT_CONF` — 由不创建上下文层次结构且只有单个全局配置的模块使用。
  此配置作为 `conf` 参数传递给处理程序。

配置解析器使用这些标志为放错位置的指令抛出错误,并使用适当的配置指针调用指令处理程序,以便相同的指令在不同位置可以将其值存储在不同的位置。

`set` 字段定义一个处理程序,用于处理指令并将解析的值存储到相应的配置中。
有许多函数执行常见的转换:

* `ngx_conf_set_flag_slot` — 将字面字符串 `on` 和 `off` 转换为值为 1 或 0 的 `ngx_flag_t` 值。
* `ngx_conf_set_str_slot` — 将字符串存储为 `ngx_str_t` 类型的值。
* `ngx_conf_set_str_array_slot` — 将值追加到字符串 `ngx_str_t` 的数组 `ngx_array_t` 中。
  如果数组不存在则创建它。
* `ngx_conf_set_keyval_slot` — 将键值对追加到键值对 `ngx_keyval_t` 的数组 `ngx_array_t` 中。
  第一个字符串成为键,第二个成为值。
  如果数组不存在则创建它。
* `ngx_conf_set_num_slot` — 将指令的参数转换为 `ngx_int_t` 值。
* `ngx_conf_set_size_slot` — 将 [大小](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax) 转换为以字节表示的 `size_t` 值。
* `ngx_conf_set_off_slot` — 将 [偏移量](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax) 转换为以字节表示的 `off_t` 值。
* `ngx_conf_set_msec_slot` — 将 [时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax) 转换为以毫秒表示的 `ngx_msec_t` 值。
* `ngx_conf_set_sec_slot` — 将 [时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax) 转换为以秒表示的 `time_t` 值。
* `ngx_conf_set_bufs_slot` — 将提供的两个参数转换为包含缓冲区数量和 [大小](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax) 的 `ngx_bufs_t` 对象。
* `ngx_conf_set_enum_slot` — 将提供的参数转换为 `ngx_uint_t` 值。
  在 `post` 字段中传递的以 null 结尾的 `ngx_conf_enum_t` 数组定义可接受的字符串和相应的整数值。
* `ngx_conf_set_bitmask_slot` — 将提供的参数转换为 `ngx_uint_t` 值。
  每个参数的掩码值进行 OR 运算产生结果。
  在 `post` 字段中传递的以 null 结尾的 `ngx_conf_bitmask_t` 数组定义可接受的字符串和相应的掩码值。
* `ngx_conf_set_path_slot` — 将提供的参数转换为 `ngx_path_t` 值并执行所有必要的初始化。
  有关详细信息,请参阅 [proxy_temp_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-temp-path) 指令的文档。
* `ngx_conf_set_access_slot` — 将提供的参数转换为文件权限掩码。
  有关详细信息,请参阅 [proxy_store_access](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-store-access) 指令的文档。

`conf` 字段定义将哪个配置结构传递给指令处理程序。
核心模块只有全局配置并设置 `NGX_DIRECT_CONF` 标志来访问它。
HTTP、Stream 或 Mail 等模块创建配置层次结构。
例如,为 `server`、`location` 和 `if` 作用域创建模块的配置。

* `NGX_HTTP_MAIN_CONF_OFFSET` — `http` 块的配置。
* `NGX_HTTP_SRV_CONF_OFFSET` — `http` 块内 `server` 块的配置。
* `NGX_HTTP_LOC_CONF_OFFSET` — `http` 块内 `location` 块的配置。
* `NGX_STREAM_MAIN_CONF_OFFSET` — `stream` 块的配置。
* `NGX_STREAM_SRV_CONF_OFFSET` — `stream` 块内 `server` 块的配置。
* `NGX_MAIL_MAIN_CONF_OFFSET` — `mail` 块的配置。
* `NGX_MAIL_SRV_CONF_OFFSET` — `mail` 块内 `server` 块的配置。

`offset` 字段定义模块配置结构中保存此特定指令值的字段的偏移量。
典型用法是使用 `offsetof()` 宏。

`post` 字段有两个用途:它可用于定义在主处理程序完成后调用的处理程序,或将额外数据传递给主处理程序。
在第一种情况下,需要使用指向处理程序的指针初始化 `ngx_conf_post_t` 结构,例如:

```c
static char *ngx_do_foo(ngx_conf_t *cf, void *post, void *data);
static ngx_conf_post_t  ngx_foo_post = { ngx_do_foo };
```

`post` 参数是 `ngx_conf_post_t` 对象本身,:samp:data 是指向值的指针,由主处理程序使用适当的类型从参数转换而来。

<a id="http"></a>

## HTTP

<a id="http-connection"></a>

### 连接

每个 HTTP 客户端连接都会经历以下阶段：

* `ngx_event_accept()` 接受客户端 TCP 连接。
  此处理程序在监听套接字上收到读通知时被调用。
  在此阶段会创建一个新的 `ngx_connection_t` 对象
  来封装新接受的客户端套接字。
  每个 Angie 监听器都提供一个处理程序来传递新的连接对象。
  对于 HTTP 连接，它是 `ngx_http_init_connection(c)`。
* `ngx_http_init_connection()` 执行 HTTP 连接的早期初始化。
  在此阶段会为连接创建一个 `ngx_http_connection_t` 对象，
  并将其引用存储在连接的 `data` 字段中。
  稍后它将被 HTTP 请求对象替换。
  PROXY 协议解析器和 SSL 握手也在此阶段启动。
* `ngx_http_wait_request_handler()` 读事件处理程序
  在客户端套接字上有数据可用时被调用。
  在此阶段会创建一个 HTTP 请求对象 `ngx_http_request_t`
  并设置到连接的 `data` 字段。
* `ngx_http_process_request_line()` 读事件处理程序
  读取客户端请求行。
  该处理程序由 `ngx_http_wait_request_handler()` 设置。
  数据被读入连接的 `buffer`。
  缓冲区的大小最初由 [client_header_buffer_size](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-header-buffer-size) 指令设置。
  整个客户端头部应该能够放入该缓冲区。
  如果初始大小不够，则会分配一个更大的缓冲区，
  其容量由 [large_client_header_buffers](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#large-client-header-buffers) 指令设置。
* `ngx_http_process_request_headers()` 读事件处理程序，
  在 `ngx_http_process_request_line()` 之后设置，
  用于读取客户端请求头。
* `ngx_http_core_run_phases()` 在请求头完全读取和解析后被调用。
  此函数运行从 `NGX_HTTP_POST_READ_PHASE` 到
  `NGX_HTTP_CONTENT_PHASE` 的请求阶段。
  最后一个阶段旨在生成响应并沿过滤器链传递。
  响应不一定在此阶段发送到客户端。
  它可能保持缓冲状态并在最终化阶段发送。
* `ngx_http_finalize_request()` 通常在请求生成所有输出
  或产生错误时被调用。
  在后一种情况下，会查找适当的错误页面并将其用作响应。
  如果此时响应尚未完全发送到客户端，
  则会激活 HTTP 写入器 `ngx_http_writer()` 来完成发送未完成的数据。
* `ngx_http_finalize_connection()` 在完整响应已发送到客户端
  且请求可以被销毁时被调用。
  如果启用了客户端连接保持活动功能，
  则会调用 `ngx_http_set_keepalive()`，它会销毁当前请求
  并等待连接上的下一个请求。
  否则，`ngx_http_close_request()` 会同时销毁请求和连接。

<a id="request"></a>

### 请求

对于每个客户端 HTTP 请求，都会创建 `ngx_http_request_t` 对象。
此对象的一些字段包括：

* `connection` — 指向 `ngx_connection_t` 客户端连接对象的指针。
  多个请求可以同时引用同一个连接对象 -
  一个主请求及其子请求。
  请求被删除后，可以在同一连接上创建新请求。

  请注意，对于 HTTP 连接，`ngx_connection_t` 的
  `data` 字段会指回请求。
  这样的请求称为活动请求，与绑定到连接的其他请求相对。
  活动请求用于处理客户端连接事件，并被允许将其响应输出到客户端。
  通常，每个请求在某个时刻都会变为活动状态，以便它可以发送其输出。
* `ctx` — HTTP 模块上下文数组。
  每个类型为 `NGX_HTTP_MODULE` 的模块都可以在请求中存储任何值
  （通常是指向结构的指针）。
  该值存储在 `ctx` 数组中模块的 `ctx_index` 位置。
  以下宏提供了获取和设置请求上下文的便捷方式：
  * `ngx_http_get_module_ctx(r, module)` — 返回
    `module` 的上下文
  * `ngx_http_set_ctx(r, c, module)` — 将 `c` 设置为
    `module` 的上下文
* `main_conf`、`srv_conf`、
  `loc_conf` — 当前请求配置的数组。
  配置存储在模块的 `ctx_index` 位置。
* `read_event_handler`、`write_event_handler` -
  请求的读和写事件处理程序。
  通常，HTTP 连接的读和写事件处理程序都设置为 `ngx_http_request_handler()`。
  此函数为当前活动请求调用 `read_event_handler` 和
  `write_event_handler` 处理程序。
* `cache` — 用于缓存上游响应的请求缓存对象。
* `upstream` — 用于代理的请求上游对象。
* `pool` — 请求池。
  请求对象本身在此池中分配，该池在请求被删除时销毁。
  对于需要在整个客户端连接生命周期内可用的分配，
  请改用 `ngx_connection_t` 的池。
* `header_in` — 读入客户端 HTTP 请求头的缓冲区。
* `headers_in`、`headers_out` — 输入和输出 HTTP 头对象。
  两个对象都包含类型为 `ngx_list_t` 的 `headers` 字段，
  用于保存原始头列表。
  除此之外，特定的头可以作为单独的字段进行获取和设置，
  例如 `content_length_n`、`status` 等。
* `request_body` — 客户端请求体对象。
* `start_sec`、`start_msec` — 请求创建时的时间点，
  用于跟踪请求持续时间。
* `method`、`method_name` — 客户端 HTTP 请求方法的数字和文本表示。
  方法的数字值在 `src/http/ngx_http_request.h` 中定义，
  使用宏 `NGX_HTTP_GET`、`NGX_HTTP_HEAD`、
  `NGX_HTTP_POST` 等。
* `http_protocol` — 客户端 HTTP 协议版本的原始文本形式
  （"HTTP/1.0"、"HTTP/1.1" 等）。
* `http_version` — 客户端 HTTP 协议版本的数字形式
  （`NGX_HTTP_VERSION_10`、`NGX_HTTP_VERSION_11` 等）。
* `http_major`、`http_minor` — 客户端 HTTP 协议版本的数字形式，
  分为主版本号和次版本号。
* `request_line`、`unparsed_uri` — 原始客户端请求中的请求行和 URI。
* `uri`、`args`、`exten` —
  当前请求的 URI、参数和文件扩展名。
  这里的 URI 值可能与客户端发送的原始 URI 不同，
  因为进行了规范化。
  在整个请求处理过程中，这些值可能会随着内部重定向的执行而改变。
* `main` — 指向主请求对象的指针。
  此对象是为处理客户端 HTTP 请求而创建的，与子请求相对，
  子请求是为在主请求中执行特定子任务而创建的。
* `parent` — 指向子请求的父请求的指针。
* `postponed` — 输出缓冲区和子请求的列表，
  按照它们被发送和创建的顺序排列。
  该列表由 postpone 过滤器使用，以便在部分输出由子请求创建时
  提供一致的请求输出。
* `post_subrequest` — 指向处理程序及其上下文的指针，
  在子请求完成时调用。
  对主请求未使用。
* `posted_requests` — 要启动或恢复的请求列表，
  通过调用请求的 `write_event_handler` 来完成。
  通常，此处理程序保存请求的主函数，
  该函数首先运行请求阶段，然后生成输出。

  请求通常通过 `ngx_http_post_request(r, NULL)` 调用来发布。
  它总是被发布到主请求的 `posted_requests` 列表。
  函数 `ngx_http_run_posted_requests(c)` 运行所有
  在传递的连接的活动请求的主请求中发布的请求。
  所有事件处理程序都会调用 `ngx_http_run_posted_requests`，
  这可能导致新的发布请求。
  通常，它在调用请求的读或写处理程序后被调用。
* `phase_handler` — 当前请求阶段的索引。
* `ncaptures`、`captures`、
  `captures_data` — 请求最后一次正则表达式匹配产生的正则捕获。
  正则匹配可能在请求处理期间的多个地方发生：
  map 查找、通过 SNI 或 HTTP Host 进行服务器查找、rewrite、proxy_redirect 等。
  查找产生的捕获存储在上述字段中。
  字段 `ncaptures` 保存捕获的数量，
  `captures` 保存捕获的边界，
  `captures_data` 保存与正则表达式匹配的字符串，
  用于提取捕获。
  每次新的正则匹配后，请求捕获都会重置以保存新值。
* `count` — 请求引用计数器。
  该字段仅对主请求有意义。
  增加计数器通过简单的 `r->main->count++` 完成。
  要减少计数器，调用 `ngx_http_finalize_request(r, rc)`。
  创建子请求和运行请求体读取过程都会增加计数器。
* `subrequests` — 当前子请求嵌套级别。
  每个子请求继承其父级的嵌套级别，减一。
  如果该值达到零，则会生成错误。
  主请求的值由 `NGX_HTTP_MAX_SUBREQUESTS` 常量定义。
* `uri_changes` — 请求剩余的 URI 更改次数。
  请求可以更改其 URI 的总次数受 `NGX_HTTP_MAX_URI_CHANGES` 常量限制。
  每次更改时，该值都会递减，直到达到零，此时会生成错误。
  重写和内部重定向到普通或命名位置都被视为 URI 更改。
* `blocked` — 请求上持有的阻塞计数器。
  当此值非零时，请求无法被最终化。
  目前，此值因待处理的 AIO 操作（POSIX AIO 和线程操作）
  和活动缓存锁而增加。
* `buffered` — 位掩码，显示哪些模块缓冲了请求产生的输出。
  许多过滤器可以缓冲输出；例如，sub_filter 可能因部分字符串匹配而缓冲数据，
  copy 过滤器可能因缺少空闲输出缓冲区而缓冲数据，等等。
  只要此值非零，请求就不会被最终化，等待刷新。
* `header_only` — 标志，指示输出不需要正文。
  例如，此标志用于 HTTP HEAD 请求。
* `keepalive` — 标志，指示是否支持客户端连接保持活动。
  该值从 HTTP 版本和 "Connection" 头的值推断。
* `header_sent` — 标志，指示请求已发送输出头。
* `internal` — 标志，指示当前请求是内部的。
  要进入内部状态，请求必须经过内部重定向或是子请求。
  内部请求被允许进入内部位置。
* `allow_ranges` — 标志，指示可以根据 HTTP Range 头的请求
  向客户端发送部分响应。
* `subrequest_ranges` — 标志，指示在处理子请求时
  可以发送部分响应。
* `single_range` — 标志，指示只能向客户端发送单个连续范围的输出数据。
  此标志通常在发送数据流时设置，例如从代理服务器，
  并且整个响应在单个缓冲区中不可用。
* `main_filter_need_in_memory`、
  `filter_need_in_memory` — 标志，
  请求在内存缓冲区而不是文件中生成输出。
  这是对 copy 过滤器的信号，即使启用了 sendfile，
  也要从文件缓冲区读取数据。
  这两个标志之间的区别在于设置它们的过滤器模块的位置。
  在过滤器链中 postpone 过滤器之前调用的过滤器设置
  `filter_need_in_memory`，请求只有当前请求的输出
  进入内存缓冲区。
  在过滤器链中稍后调用的过滤器设置
  `main_filter_need_in_memory`，请求主请求和所有子请求
  在发送输出时将文件读入内存。
* `filter_need_temporary` — 标志，请求在临时缓冲区中生成请求输出，
  但不在只读内存缓冲区或文件缓冲区中。
  这由可能直接在发送缓冲区中更改输出的过滤器使用。

<a id="http-module-configuration"></a>

### HTTP 模块配置

每个 HTTP 模块可以有三种类型的配置：

* 主配置 — 应用于整个 `http` 块。
  作为模块的全局设置。
* 服务器配置 — 应用于单个 `server` 块。
  作为模块的服务器特定设置。
* 位置配置 — 应用于单个 `location`、
  `if` 或 `limit_except` 块。
  作为模块的位置特定设置。

配置结构在 Angie 配置阶段通过调用分配结构、初始化结构和合并结构的函数来创建。
以下示例展示了如何为模块创建简单的位置配置。
该配置有一个设置 `foo`，类型为无符号整数。

```c
typedef struct {
    ngx_uint_t  foo;
} ngx_http_foo_loc_conf_t;


static ngx_http_module_t  ngx_http_foo_module_ctx = {
    NULL,                                  /* preconfiguration */
    NULL,                                  /* postconfiguration */

    NULL,                                  /* create main configuration */
    NULL,                                  /* init main configuration */

    NULL,                                  /* create server configuration */
    NULL,                                  /* merge server configuration */

    ngx_http_foo_create_loc_conf,          /* create location configuration */
    ngx_http_foo_merge_loc_conf            /* merge location configuration */
};


static void *
ngx_http_foo_create_loc_conf(ngx_conf_t *cf)
{
    ngx_http_foo_loc_conf_t  *conf;

    conf = ngx_pcalloc(cf->pool, sizeof(ngx_http_foo_loc_conf_t));
    if (conf == NULL) {
        return NULL;
    }

    conf->foo = NGX_CONF_UNSET_UINT;

    return conf;
}


static char *
ngx_http_foo_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
{
    ngx_http_foo_loc_conf_t *prev = parent;
    ngx_http_foo_loc_conf_t *conf = child;

    ngx_conf_merge_uint_value(conf->foo, prev->foo, 1);
}
```

如示例所示，`ngx_http_foo_create_loc_conf()` 函数创建一个新的配置结构，
`ngx_http_foo_merge_loc_conf()` 将配置与更高级别的配置合并。
实际上,服务器和位置配置不仅存在于服务器和位置级别，
还会在它们之上的所有级别创建。
具体来说，服务器配置也会在主级别创建，
位置配置会在主级别、服务器级别和位置级别创建。
这些配置使得可以在 Angie 配置文件的任何级别指定服务器和位置特定的设置。
最终配置会向下合并。
提供了许多宏，如 `NGX_CONF_UNSET` 和 `NGX_CONF_UNSET_UINT`，
用于指示缺失的设置并在合并期间忽略它。
标准的 Angie 合并宏，如 `ngx_conf_merge_value()` 和
`ngx_conf_merge_uint_value()`，提供了一种便捷的方式来合并设置，
并在所有配置都未提供显式值时设置默认值。
有关不同类型的完整宏列表，请参见 `src/core/ngx_conf_file.h`。

以下宏可用于在配置时访问 HTTP 模块的配置。
它们都将 `ngx_conf_t` 引用作为第一个参数。

* `ngx_http_conf_get_module_main_conf(cf, module)`
* `ngx_http_conf_get_module_srv_conf(cf, module)`
* `ngx_http_conf_get_module_loc_conf(cf, module)`

以下示例获取标准 [核心 HTTP 模块](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#http-core) 的位置配置指针，
并替换存储在结构的 `handler` 字段中的位置内容处理器。

```c
static ngx_int_t ngx_http_foo_handler(ngx_http_request_t *r);


static ngx_command_t  ngx_http_foo_commands[] = {

    { ngx_string("foo"),
      NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
      ngx_http_foo,
      0,
      0,
      NULL },

      ngx_null_command
};


static char *
ngx_http_foo(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
    ngx_http_core_loc_conf_t  *clcf;

    clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
    clcf->handler = ngx_http_bar_handler;

    return NGX_CONF_OK;
}
```

以下宏可用于在运行时访问 HTTP 模块的配置。

* `ngx_http_get_module_main_conf(r, module)`
* `ngx_http_get_module_srv_conf(r, module)`
* `ngx_http_get_module_loc_conf(r, module)`

这些宏接收对 HTTP 请求 `ngx_http_request_t` 的引用。
请求的主配置永远不会改变。
服务器配置可能会在为请求选择虚拟服务器后从默认值改变。
为处理请求而选择的位置配置可能会因重写操作或内部重定向而多次改变。
以下示例展示了如何在运行时访问模块的 HTTP 配置。

```c
static ngx_int_t
ngx_http_foo_handler(ngx_http_request_t *r)
{
    ngx_http_foo_loc_conf_t  *flcf;

    flcf = ngx_http_get_module_loc_conf(r, ngx_http_foo_module);

    ...
}
```

<a id="phases"></a>

### 阶段

每个 HTTP 请求都会经历一系列阶段。
在每个阶段，对请求执行不同类型的处理。
模块特定的处理器可以在大多数阶段注册，
许多标准 Angie 模块将其阶段处理器注册为在请求处理的特定阶段被调用的方式。
阶段按顺序处理，一旦请求到达该阶段，就会调用阶段处理器。
以下是 Angie HTTP 阶段的列表。

* `NGX_HTTP_POST_READ_PHASE` — 第一个阶段。
  [RealIP](https://cn.angie.software//angie/docs/configuration/modules/http/http_realip.md#http-realip) 模块在此阶段注册其处理器，
  以便在调用任何其他模块之前替换客户端地址。
* `NGX_HTTP_SERVER_REWRITE_PHASE` — 处理在 `server` 块中定义的重写指令
  （但在 `location` 块之外）的阶段。
  [Rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#http-rewrite) 模块在此阶段安装其处理器。
* `NGX_HTTP_FIND_CONFIG_PHASE` — 根据请求 URI 选择位置的特殊阶段。
  在此阶段之前，相关虚拟服务器的默认位置被分配给请求，
  任何请求位置配置的模块都会接收默认服务器位置的配置。
  此阶段为请求分配新位置。
  此阶段不能注册额外的处理器。
* `NGX_HTTP_REWRITE_PHASE` — 与 `NGX_HTTP_SERVER_REWRITE_PHASE` 相同，
  但用于在前一阶段选择的位置中定义的重写规则。
* `NGX_HTTP_POST_REWRITE_PHASE` — 如果请求的 URI 在重写期间发生更改，
  则将请求重定向到新位置的特殊阶段。
  这是通过请求再次经过 `NGX_HTTP_FIND_CONFIG_PHASE` 来实现的。
  此阶段不能注册额外的处理器。
* `NGX_HTTP_PREACCESS_PHASE` — 用于不同类型处理器的通用阶段，
  与访问控制无关。
  标准 Angie 模块 [Limit Conn](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_conn.md#http-limit-conn) 和 [Limit Req](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_req.md#http-limit-req)
  在此阶段注册其处理器。
* `NGX_HTTP_ACCESS_PHASE` — 验证客户端是否有权发出请求的阶段。
  标准 Angie 模块如 [Access](https://cn.angie.software//angie/docs/configuration/modules/http/http_access.md#http-access) 和 [Auth Basic](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_basic.md#http-auth-basic)
  在此阶段注册其处理器。
  默认情况下，客户端必须通过此阶段注册的所有处理器的授权检查，
  请求才能继续到下一阶段。
  [satisfy](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#satisfy) 指令可用于允许在任何阶段处理器授权客户端时继续处理。
* `NGX_HTTP_POST_ACCESS_PHASE` — 处理 [satisfy](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#satisfy) 指令的特殊阶段。
  如果某些访问阶段处理器拒绝访问且没有明确允许，则请求被最终化。
  此阶段不能注册额外的处理器。
* `NGX_HTTP_PRECONTENT_PHASE` — 在生成内容之前调用处理器的阶段。
  标准模块如 [try_files](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#try-files) 和 [Mirror](https://cn.angie.software//angie/docs/configuration/modules/http/http_mirror.md#http-mirror)
  在此阶段注册其处理器。
* `NGX_HTTP_CONTENT_PHASE` — 通常生成响应的阶段。
  多个标准 Angie 模块在此阶段注册其处理器，
  包括 [Index](https://cn.angie.software//angie/docs/configuration/modules/http/http_index.md#http-index)。
  它们按顺序调用，直到其中一个产生输出。
  也可以按位置设置内容处理器。
  如果 [HTTP 模块](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#http-core) 模块的位置配置设置了 `handler`，
  它将作为内容处理器被调用，并且忽略此阶段安装的处理器。
* `NGX_HTTP_LOG_PHASE` — 执行请求日志记录的阶段。
  目前，只有 [Log](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#http-log) 模块在此阶段注册其处理器以进行访问日志记录。
  日志阶段处理器在请求处理的最后被调用，就在释放请求之前。

以下是预访问阶段处理器的示例。

```c
static ngx_http_module_t  ngx_http_foo_module_ctx = {
    NULL,                                  /* preconfiguration */
    ngx_http_foo_init,                     /* postconfiguration */

    NULL,                                  /* create main configuration */
    NULL,                                  /* init main configuration */

    NULL,                                  /* create server configuration */
    NULL,                                  /* merge server configuration */

    NULL,                                  /* create location configuration */
    NULL                                   /* merge location configuration */
};


static ngx_int_t
ngx_http_foo_handler(ngx_http_request_t *r)
{
    ngx_table_elt_t  *ua;

    ua = r->headers_in.user_agent;

    if (ua == NULL) {
        return NGX_DECLINED;
    }

    /* reject requests with "User-Agent: foo" */
    if (ua->value.len == 3 && ngx_strncmp(ua->value.data, "foo", 3) == 0) {
        return NGX_HTTP_FORBIDDEN;
    }

    return NGX_DECLINED;
}


static ngx_int_t
ngx_http_foo_init(ngx_conf_t *cf)
{
    ngx_http_handler_pt        *h;
    ngx_http_core_main_conf_t  *cmcf;

    cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);

    h = ngx_array_push(&cmcf->phases[NGX_HTTP_PREACCESS_PHASE].handlers);
    if (h == NULL) {
        return NGX_ERROR;
    }

    *h = ngx_http_foo_handler;

    return NGX_OK;
}
```

阶段处理器应返回特定的代码：

* `NGX_OK` — 继续到下一阶段。
* `NGX_DECLINED` — 继续到当前阶段的下一个处理器。
  如果当前处理器是当前阶段的最后一个，则移至下一阶段。
* `NGX_AGAIN`、`NGX_DONE` — 暂停阶段处理，
  直到某个未来事件，例如异步 I/O 操作或只是延迟。
  假定稍后通过调用 `ngx_http_core_run_phases()` 恢复阶段处理。
* 阶段处理器返回的任何其他值都被视为请求最终化代码，
  特别是 HTTP 响应代码。
  请求以提供的代码最终化。

对于某些阶段，返回代码的处理方式略有不同。
在内容阶段，除 `NGX_DECLINED` 之外的任何返回代码都被视为最终化代码。
位置内容处理器的任何返回代码都被视为最终化代码。
在访问阶段，在 [satisfy any](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#satisfy) 模式下，
返回除 `NGX_OK`、`NGX_DECLINED`、`NGX_AGAIN`、
`NGX_DONE` 之外的代码被视为拒绝。
如果没有后续访问处理器允许或使用不同代码拒绝访问，
则拒绝代码将成为最终化代码。

<a id="examples"></a>

### 示例

[nginx-dev-examples](https://github.com/nginx/nginx-dev-examples)
仓库提供了适用于 Angie 的 nginx 模块示例。

<a id="code-style"></a>

## 代码风格

<a id="general-rules"></a>

### 通用规则

* 最大文本宽度为 80 个字符
* 缩进为 4 个空格
* 不使用制表符，不使用尾随空格
* 同一行上的列表元素用空格分隔
* 十六进制字面量为小写
* 文件名、函数和类型名称以及全局变量具有 `ngx_` 前缀或更具体的前缀，
  如 `ngx_http_` 和 `ngx_mail_`

```c
size_t
ngx_utf8_length(u_char *p, size_t n)
{
    u_char  c, *last;
    size_t  len;

    last = p + n;

    for (len = 0; p < last; len++) {

        c = *p;

        if (c < 0x80) {
            p++;
            continue;
        }

        if (ngx_utf8_decode(&p, last - p) > 0x10ffff) {
            /* invalid UTF-8 */
            return n;
        }
    }

    return len;
}
```

<a id="files"></a>

### 文件

典型的源文件可能包含以下部分，用两个空行分隔：

* 版权声明
* 包含文件
* 预处理器定义
* 类型定义
* 函数原型
* 变量定义
* 函数定义

版权声明如下所示：

```c
/*
 * Copyright (C) Author Name
 * Copyright (C) Organization, Inc.
 */
```

如果文件被大幅修改，应更新作者列表，新作者添加到顶部。

始终首先包含 `ngx_config.h` 和 `ngx_core.h` 文件，
然后是 `ngx_http.h`、`ngx_stream.h` 或 `ngx_mail.h` 之一。
然后是可选的外部头文件：

```c
#include <ngx_config.h>
#include <ngx_core.h>
#include <ngx_http.h>

#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxslt/xslt.h>

#if (NGX_HAVE_EXSLT)
#include <libexslt/exslt.h>
#endif
```

头文件应包含所谓的"头文件保护"：

```c
#ifndef _NGX_PROCESS_CYCLE_H_INCLUDED_
#define _NGX_PROCESS_CYCLE_H_INCLUDED_
...
#endif /* _NGX_PROCESS_CYCLE_H_INCLUDED_ */
```

<a id="comments"></a>

### 注释

* 不使用 `//` 注释
* 文本使用英语，首选美式拼写
* 多行注释格式如下：
  ```c
  /*
   * The red-black tree code is based on the algorithm described in
   * the "Introduction to Algorithms" by Cormen, Leiserson and Rivest.
   */
  ```

  ```c
  /* find the server configuration for the address:port */
  ```

<a id="preprocessor"></a>

### 预处理器

宏名称以 `ngx_` 或 `NGX_` 前缀开头（或更具体的前缀）。
常量的宏名称为大写。
参数化宏和初始化器宏为小写。
宏名称和值之间至少用两个空格分隔：

```c
#define NGX_CONF_BUFFER  4096

#define ngx_buf_in_memory(b)  (b->temporary || b->memory || b->mmap)

#define ngx_buf_size(b)                                                      \
    (ngx_buf_in_memory(b) ? (off_t) (b->last - b->pos):                      \
                            (b->file_last - b->file_pos))

#define ngx_null_string  { 0, NULL }
```

条件在括号内，否定在外部：

```c
#if (NGX_HAVE_KQUEUE)
...
#elif ((NGX_HAVE_DEVPOLL && !(NGX_TEST_BUILD_DEVPOLL)) \
       || (NGX_HAVE_EVENTPORT && !(NGX_TEST_BUILD_EVENTPORT)))
...
#elif (NGX_HAVE_EPOLL && !(NGX_TEST_BUILD_EPOLL))
...
#elif (NGX_HAVE_POLL)
...
#else /* select */
...
#endif /* NGX_HAVE_KQUEUE */
```

<a id="types-1"></a>

### 类型

类型名称以 `_t` 后缀结尾。
定义的类型名称至少用两个空格分隔：

```c
typedef ngx_uint_t  ngx_rbtree_key_t;
```

结构类型使用 `typedef` 定义。
在结构内部，成员类型和名称对齐：

```c
typedef struct {
    size_t      len;
    u_char     *data;
} ngx_str_t;
```

在文件中的不同结构之间保持相同的对齐。
指向自身的结构的名称以
`_s` 结尾。
相邻的结构定义用两个空行分隔：

```c
typedef struct ngx_list_part_s  ngx_list_part_t;

struct ngx_list_part_s {
    void             *elts;
    ngx_uint_t        nelts;
    ngx_list_part_t  *next;
};


typedef struct {
    ngx_list_part_t  *last;
    ngx_list_part_t   part;
    size_t            size;
    ngx_uint_t        nalloc;
    ngx_pool_t       *pool;
} ngx_list_t;
```

每个结构成员在单独的行上声明：

```c
typedef struct {
    ngx_uint_t        hash;
    ngx_str_t         key;
    ngx_str_t         value;
    u_char           *lowcase_key;
} ngx_table_elt_t;
```

结构内部的函数指针具有以
`_pt` 结尾的定义类型：

```c
typedef ssize_t (*ngx_recv_pt)(ngx_connection_t *c, u_char *buf, size_t size);
typedef ssize_t (*ngx_recv_chain_pt)(ngx_connection_t *c, ngx_chain_t *in,
    off_t limit);
typedef ssize_t (*ngx_send_pt)(ngx_connection_t *c, u_char *buf, size_t size);
typedef ngx_chain_t *(*ngx_send_chain_pt)(ngx_connection_t *c, ngx_chain_t *in,
    off_t limit);

typedef struct {
    ngx_recv_pt        recv;
    ngx_recv_chain_pt  recv_chain;
    ngx_recv_pt        udp_recv;
    ngx_send_pt        send;
    ngx_send_pt        udp_send;
    ngx_send_chain_pt  udp_send_chain;
    ngx_send_chain_pt  send_chain;
    ngx_uint_t         flags;
} ngx_os_io_t;
```

枚举类型以 `_e` 结尾：

```c
typedef enum {
    ngx_http_fastcgi_st_version = 0,
    ngx_http_fastcgi_st_type,
    ...
    ngx_http_fastcgi_st_padding
} ngx_http_fastcgi_state_e;
```

<a id="variables-2"></a>

### 变量

变量声明按基本类型的长度排序，然后按字母顺序排序。
类型名称和变量名称对齐。
类型和名称"列"用两个空格分隔。
大型数组放在声明块的末尾：

```c
u_char                      *rv, *p;
ngx_conf_t                  *cf;
ngx_uint_t                   i, j, k;
unsigned int                 len;
struct sockaddr             *sa;
const unsigned char         *data;
ngx_peer_connection_t       *pc;
ngx_http_core_srv_conf_t   **cscfp;
ngx_http_upstream_srv_conf_t *us, *uscf;
u_char                       text[NGX_SOCKADDR_STRLEN];
```

静态和全局变量可以在声明时初始化：

```c
static ngx_str_t  ngx_http_memcached_key = ngx_string("memcached_key");
```

```c
static ngx_uint_t  mday[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
```

```c
static uint32_t  ngx_crc32_table16[] = {
    0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
    ...
    0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, 0xbdbdf21c
};
```

有一些常用的类型/名称组合：

```c
u_char                        *rv;
ngx_int_t                      rc;
ngx_conf_t                    *cf;
ngx_connection_t              *c;
ngx_http_request_t            *r;
ngx_peer_connection_t         *pc;
ngx_http_upstream_srv_conf_t  *us, *uscf;
```

<a id="functions"></a>

### 函数

所有函数（即使是静态函数）都应有原型。
原型包含参数名称。
长原型在续行上使用单个缩进换行：

```c
static char *ngx_http_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static ngx_int_t ngx_http_init_phases(ngx_conf_t *cf,
    ngx_http_core_main_conf_t *cmcf);

static char *ngx_http_merge_servers(ngx_conf_t *cf,
    ngx_http_core_main_conf_t *cmcf, ngx_http_module_t *module,
    ngx_uint_t ctx_index);
```

定义中的函数名称从新行开始。
函数体的左右花括号在单独的行上。
函数体缩进。
函数之间有两个空行：

```c
static ngx_int_t
ngx_http_find_virtual_server(ngx_http_request_t *r, u_char *host, size_t len)
{
    ...
}


static ngx_int_t
ngx_http_add_addresses(ngx_conf_t *cf, ngx_http_core_srv_conf_t *cscf,
    ngx_http_conf_port_t *port, ngx_http_listen_opt_t *lsopt)
{
    ...
}
```

函数名称和左括号之间没有空格。
长函数调用换行，使续行从第一个函数参数的位置开始。
如果这不可能，则格式化第一个续行，使其在第 79 列结束：

```c
ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
               "http header: \"%V: %V\"",
               &h->key, &h->value);

hc->busy = ngx_palloc(r->connection->pool,
                  cscf->large_client_header_buffers.num * sizeof(ngx_buf_t *));
```

应使用 `ngx_inline` 宏而不是
`inline`：

```c
static ngx_inline void ngx_cpuid(uint32_t i, uint32_t *buf);
```

<a id="expressions"></a>

### 表达式

二元运算符（除 `.` 和 `->` 外）
应与其操作数用一个空格分隔。
一元运算符和下标与其操作数之间没有空格：

```c
width = width * 10 + (*fmt++ - '0');
```

```c
ch = (u_char) ((decoded << 4) + (ch - '0'));
```

```c
r->exten.data = &r->uri.data[i + 1];
```

类型转换与被转换的表达式用一个空格分隔。
类型转换内的星号与类型名称用空格分隔：

```c
len = ngx_sock_ntop((struct sockaddr *) sin6, p, len, 1);
```

如果表达式不适合单行，则换行。
首选的换行点是二元运算符。
续行与表达式的开头对齐：

```c
if (status == NGX_HTTP_MOVED_PERMANENTLY
    || status == NGX_HTTP_MOVED_TEMPORARILY
    || status == NGX_HTTP_SEE_OTHER
    || status == NGX_HTTP_TEMPORARY_REDIRECT
    || status == NGX_HTTP_PERMANENT_REDIRECT)
{
    ...
}
```

```c
p->temp_file->warn = "an upstream response is buffered "
                     "to a temporary file";
```

作为最后的手段，可以换行表达式，使续行在第 79 列结束：

```c
hinit->hash = ngx_pcalloc(hinit->pool, sizeof(ngx_hash_wildcard_t)
                                     + size * sizeof(ngx_hash_elt_t *));
```

上述规则也适用于子表达式，
其中每个子表达式都有自己的缩进级别：

```c
if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING)
     || c->stale_updating) && !r->background
    && u->conf->cache_background_update)
{
    ...
}
```

有时在类型转换后换行表达式很方便。
在这种情况下，续行缩进：

```c
node = (ngx_rbtree_node_t *)
           ((u_char *) lr - offsetof(ngx_rbtree_node_t, color));
```

指针显式与
`NULL`（而不是 :samp:`0`）比较：

```c
if (ptr != NULL) {
    ...
}
```

<a id="conditionals-and-loops"></a>

### 条件和循环

`if` 关键字与条件用一个空格分隔。
左花括号位于同一行，或者如果条件占用多行，则位于单独的行上。
右花括号位于单独的行上，可选地后跟
`else if` / `else`。
通常，在 `else if` / `else` 部分之前有一个空行：

```c
if (node->left == sentinel) {
    temp = node->right;
    subst = node;

} else if (node->right == sentinel) {
    temp = node->left;
    subst = node;

} else {
    subst = ngx_rbtree_min(node->right, sentinel);

    if (subst->left != sentinel) {
        temp = subst->left;

    } else {
        temp = subst->right;
    }
}
```

类似的格式规则适用于 `do` 和
`while` 循环：

```c
while (p < last && *p == ' ') {
    p++;
}
```

```c
do {
    ctx->node = rn;
    ctx = ctx->next;
} while (ctx);
```

`switch` 关键字与条件用一个空格分隔。
左花括号位于同一行。
右花括号位于单独的行上。
`case` 关键字与 `switch` 对齐：

```c
switch (ch) {
case '!':
    looked = 2;
    state = ssi_comment0_state;
    break;

case '<':
    copy_end = p;
    break;

default:
    copy_end = p;
    looked = 0;
    state = ssi_start_state;
    break;
}
```

大多数 `for` 循环格式如下：

```c
for (i = 0; i < ccf->env.nelts; i++) {
    ...
}
```

```c
for (q = ngx_queue_head(locations);
     q != ngx_queue_sentinel(locations);
     q = ngx_queue_next(q))
{
    ...
}
```

如果省略 `for` 语句的某些部分，
则用 `/* void */` 注释表示：

```c
for (i = 0; /* void */ ; i++) {
    ...
}
```

空循环体也用 `/* void */` 注释表示，
该注释可以放在同一行上：

```c
for (cl = *busy; cl->next; cl = cl->next) { /* void */ }
```

无限循环如下所示：

```c
for ( ;; ) {
    ...
}
```

<a id="labels"></a>

### 标签

标签周围有空行，并在前一级别缩进：

```c
    if (i == 0) {
        u->err = "host not found";
        goto failed;
    }

    u->addrs = ngx_pcalloc(pool, i * sizeof(ngx_addr_t));
    if (u->addrs == NULL) {
        goto failed;
    }

    u->naddrs = i;

    ...

    return NGX_OK;

failed:

    freeaddrinfo(res);
    return NGX_ERROR;
```

<a id="debugging-memory-issues"></a>

## 调试内存问题

要调试内存问题，如缓冲区溢出或释放后使用错误，可以使用
[AddressSanitizer](https://en.wikipedia.org/wiki/AddressSanitizer)
(ASan)，某些现代编译器支持该工具。
要在 `gcc` 和 `clang` 中启用 ASan，
请使用 `-fsanitize=address` 编译器和链接器选项。
在构建 Angie 时，可以通过将该选项添加到
`configure` 脚本的 `--with-cc-opt` 和 `--with-ld-opt` 参数来完成。

由于 Angie 中的大多数分配都是从 Angie 内部
[池](#pool) 进行的，启用 ASan 可能并不总是足以调试
内存问题。
内部池从系统分配一大块内存，并从中切割较小的分配。
但是，可以通过将
`NGX_DEBUG_PALLOC` 宏设置为 `1` 来禁用此机制。
在这种情况下，分配直接传递给系统分配器，使其完全控制缓冲区边界。

以下配置行总结了上述信息。
建议在开发第三方模块和在不同平台上测试 Angie 时使用。

```bash
auto/configure --with-cc-opt='-fsanitize=address -DNGX_DEBUG_PALLOC=1'
               --with-ld-opt=-fsanitize=address
```

<a id="common-pitfalls"></a>

## 常见陷阱

<a id="writing-a-c-module"></a>

### 编写 C 模块

最常见的陷阱是在可以避免的情况下尝试编写完整的 C 模块。
在大多数情况下，您的任务可以通过创建适当的配置来完成。
如果编写模块不可避免，请尝试使其尽可能小而简单。
例如，模块可以只导出一些
[变量](#http_variables)。

在开始编写模块之前，请考虑以下问题：

* 是否可以使用已经
  [可用的模块](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules) 实现所需的功能？
* 是否可以使用内置的脚本语言解决问题，
  例如 [Perl](https://cn.angie.software//angie/docs/configuration/modules/http/http_perl.md#http-perl) 或 [NJS](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)？

<a id="c-strings"></a>

### C 字符串

Angie 中最常用的字符串类型
[ngx_str_t](#string_overview) 不是 C 风格的
以零结尾的字符串。
您不能将数据传递给标准 C 库函数，
例如 `strlen()` 或 `strstr()`。
相反，应使用接受 `ngx_str_t` 或指向数据和长度的指针的 Angie [对应函数](#string_overview)。
但是，有一种情况 `ngx_str_t` 持有
指向以零结尾的字符串的指针：作为配置文件解析结果的字符串是以零结尾的。

<a id="global-variables"></a>

### 全局变量

避免在模块中使用全局变量。
使用全局变量很可能是一个错误。
任何全局数据都应绑定到 [配置周期](#cycle)
并从相应的 [内存池](#pool) 分配。
这允许 Angie 执行优雅的配置重新加载。
尝试使用全局变量可能会破坏此功能，
因为不可能同时拥有两个配置并摆脱它们。
有时需要全局变量。
在这种情况下，需要特别注意正确管理重新配置。
另外，检查您的代码使用的库是否具有可能在重新加载时损坏的隐式全局状态。

<a id="manual-memory-management"></a>

### 手动内存管理

不要使用容易出错的 malloc/free 方法，
而是学习如何使用 Angie [池](#pool)。
池被创建并绑定到对象 -
[配置](#http_conf)、
[周期](#cycle)、
连接 <#http_connection> 或
[HTTP 请求](#http_request)。
当对象被销毁时，关联的池也被销毁。
因此，在处理对象时，可以从相应的池中分配所需的数量，
而不必担心释放内存，即使在出现错误的情况下也是如此。

<a id="dev-threads"></a>

### 线程

建议避免在 Angie 中使用线程，因为这肯定会破坏事物：大多数 Angie 函数不是线程安全的。
预期线程只执行系统调用和线程安全的库函数。
如果您需要运行与客户端请求处理无关的代码，
正确的方法是在 `init_process` 模块处理器中安排一个定时器，
并在定时器处理器中执行所需的操作。
在内部，Angie 使用 [线程](#dev_threads) 来
提升 IO 相关操作，但这是一个特殊情况，有很多限制。

<a id="blocking-libraries"></a>

### 阻塞库

一个常见的错误是使用内部阻塞的库。
大多数库本质上是同步和阻塞的。
换句话说，它们一次执行一个操作，并浪费时间等待来自其他对等方的响应。
因此，当使用此类库处理请求时，整个 Angie worker 被阻塞，从而破坏性能。
仅使用提供异步接口且不阻塞整个进程的库。

<a id="http-requests-to-external-services"></a>

### 向外部服务发送 HTTP 请求

模块通常需要对某些外部服务执行 HTTP 调用。
一个常见的错误是使用某些外部库(例如 libcurl)
来执行 HTTP 请求。
为了完成 Angie 本身就能完成的任务,
引入大量外部(可能是 [阻塞的](#using_libraries)!)代码
是完全没有必要的。

当需要外部请求时,有两种基本使用场景:

* 在处理客户端请求的上下文中(例如,在内容处理程序中)
* 在 worker 进程的上下文中(例如,定时器处理程序)

在第一种情况下,最好使用
[子请求 API](#http_subrequests)。
您不是直接访问外部服务,而是在
Angie 配置中声明一个 location,
并将子请求定向到此 location。
此 location 不限于
[代理](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass)
请求,还可以包含其他 Angie 指令。
这种方法的一个例子是
[Auth Request](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_request.md#http-auth-request) 中实现的
[auth_request](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_request.md#id3) 指令。

对于第二种情况,可以使用 Angie 中可用的基本 HTTP 客户端功能。
例如,
[OCSP 模块](https://github.com/nginx/nginx/blob/master/src/event/ngx_event_openssl_stapling.c)
实现了简单的 HTTP 客户端。


# https://cn.angie.software/angie/docs/development.md

<!-- review: finished -->

<a id="development"></a>

# 开发

Angie 是一个开源项目,
欢迎所有贡献者。

<a id="source-code"></a>

## 源代码

您可以从我们的公共仓库克隆 Angie 源代码:
[Mercurial](https://hg.angie.software/angie),
[Git](https://git.angie.software/web-server/angie)。

<a id="coding-style"></a>

## 编码风格

您的更改应与 Angie 其余代码保持一致;
[编码约定](https://cn.angie.software//angie/docs/developer_guide.md#developer-guide) 是一个很好的起点。

<a id="commit-messages"></a>

### 提交消息

从历史上看,提交日志使用英语维护。

以一行总结所做的工作开始。
它可以有一个前缀,提交日志将其用于受影响的代码部分。
总结最多可以有 67 个字符,
后面可以跟一个空行和更多详细信息。

一个好的消息会说明是什么导致了更改、对此做了什么,
以及现在的情况如何:

```none
API: bad things removed, good things added.

As explained elsewhere[1], the original API was bad because stuff;
this change was introduced to improve that aspect locally.

Levels of goodness have been implemented to mitigate the badness;
this is now the preferred way to work.  Also, the badness is gone.

[1] https://example.com
```

可能会被忽略的细节:

- 总结以句号结尾,并以大写字母开头。
- 如果使用前缀,则后面跟小写字母。
- 双空格分隔单行内的句子。

<a id="final-checks"></a>

## 最终检查

- 尽最大努力验证更改在  *所有* 目标平台上都能正常工作。
- 对于每个平台,运行测试套件以确保没有回归:
  ```sh
  $ cd tests
  $ prove .
  ```

  详细信息请参阅 `tests/README` 文件。
- 确保您对 [法律条款](https://cn.angie.software//legal/index.md#legal) 感到满意。

<a id="submitting-contributions"></a>

## 提交贡献

要提交补丁,请在我们的
[GitHub 镜像](https://github.com/webserver-llc/angie/) 上创建拉取请求。

如有问题和建议,请通过
[GitHub Issues](https://github.com/webserver-llc/angie/issues) 联系开发人员。


# https://cn.angie.software/angie/doc-license.md

# 许可组件存在声明

本站发布的 Angie 软件产品 [文档](https://cn.angie.software//angie/docs/index.md) 是 Web Server, LLC 的知识产权；该文档是通过修改（修订）Nginx 软件产品文档而创建的。未经更改而使用的 Angie 软件产品文档的某些部分是根据 [http://nginx.org/LICENSE](http://nginx.org/LICENSE) 提供的许可证授权的；此类文档部分的使用必须符合该许可证的条款。


# https://cn.angie.software/angie/docs/installation/docker.md

<!-- review: finished -->

<a id="docker-images"></a>

# Angie Docker 镜像

要在 [Docker](https://docs.docker.com/engine/reference/commandline/cli/) 容器中运行 Angie,
请使用我们注册表中的镜像:`docker.angie.software`。
这些镜像基于我们的 [二进制软件包](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)
和几个操作系统的官方基础镜像构建。

#### NOTE
另请注意 [Docker](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker) 模块,
该模块基于 Docker 容器标签实现上游服务器组的动态更新。

<a id="minimal-images"></a>

## 最小化镜像

- `angie:minimal`:
  基于 Alpine 3.22 的  版本。
- `angie:<VERSION>-minimal`:
  基于 Alpine 3.22 的指定版本。

这些镜像仅包含 `angie` 软件包。

<a id="docker-templated"></a>

## 模板化镜像

- `angie:templated`:
  基于 Alpine 3.22 的  版本。
- `angie:<VERSION>-templated`:
  基于 Alpine 3.22 的指定版本。

这些镜像设置了以下环境变量:

```docker
ENV ANGIE_BINARY="angie"
ENV ANGIE_CONFIG_TEMPLATE="/etc/angie/angie.conf.t"
ENV ANGIE_ERROR_LOG_SEVERITY="notice"
ENV ANGIE_FEATURE_RELOAD="on"
ENV ANGIE_FEATURE_TEMPLATE="on"
ENV ANGIE_LOAD_MODULES=""
ENV ANGIE_PID_FILE="/run/angie/angie.pid"
ENV ANGIE_WORKER_CONNECTIONS="65536"
ENV ANGIE_WORKER_RLIMIT_NOFILE="65536"
```

这些变量可用于自定义容器行为:

- `ANGIE_BINARY`:
  允许运行 [调试版本](https://cn.angie.software//angie/docs/troubleshooting.md#debug-logging)。
- `ANGIE_ERROR_LOG_SEVERITY`:
  设置主 [错误日志](https://cn.angie.software//angie/docs/configuration/processing.md#logging) 文件中条目的严重级别。
- `ANGIE_LOAD_MODULES`:
  加载一个或多个可用模块(镜像中包含所有模块)。
  指定以逗号分隔的模块列表,不含空格。
- `ANGIE_PID_FILE`:
  设置进程标识符 (PID) 文件的替代位置。
- `ANGIE_FEATURE_TEMPLATE`:
  在容器启动时使用 [gomplate](https://docs.gomplate.ca/) 工具生成
  [Angie 配置](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)。使用的参数:
  `--input-dir /etc/angie/templates` 和
  `--output-dir /etc/angie`。
- `ANGIE_FEATURE_RELOAD`:
  启用对 `SIGHUP`、`SIGQUIT` 和 `SIGTERM`
  信号的处理。

这些镜像包含以下
[软件包](https://cn.angie.software//angie/docs/installation/external-modules/index.md#install-thirdpartymodules)
(如果它们已针对构建镜像所用的 [Angie 版本](https://cn.angie.software//angie/docs/oss_changes.md#oss-changes) 发布):

### 软件包列表

- `angie-console-light`
- `angie-module-auth-jwt`
- `angie-module-auth-ldap`
- `angie-module-auth-pam`
- `angie-module-auth-spnego`
- `angie-module-auth-totp`
- `angie-module-brotli`
- `angie-module-cache-purge`
- `angie-module-cgi`
- `angie-module-combined-upstreams`
- `angie-module-dav-ext`
- `angie-module-dynamic-limit-req`
- `angie-module-echo`
- `angie-module-enhanced-memcached`
- `angie-module-eval`
- `angie-module-geoip2`
- `angie-module-headers-more`
- `angie-module-http-auth-radius`
- `angie-module-image-filter`
- `angie-module-keyval`
- `angie-module-lua`
- `angie-module-modsecurity`
- `angie-module-ndk`
- `angie-module-njs`
- `angie-module-opentracing`
- `angie-module-otel`
- `angie-module-perl`
- `angie-module-postgres`
- `angie-module-redis2`
- `angie-module-rtmp`
- `angie-module-set-misc`
- `angie-module-subs`
- `angie-module-testcookie`
- `angie-module-unbrotli`
- `angie-module-upload`
- `angie-module-vod`
- `angie-module-vts`
- `angie-module-wasm`
- `angie-module-wasmtime`
- `angie-module-xslt`
- `angie-module-zip`
- `angie-module-zstd`

<a id="examples-1"></a>

### 示例

模板化镜像中使用的配置大致按以下方式应用变量:

```none
...
{{- if has $modules "zstd"}}
# package: angie-module-zstd
load_module modules/ngx_http_zstd_filter_module.so;
load_module modules/ngx_http_zstd_static_module.so;
{{end}}

user  angie;
worker_processes  auto;
worker_rlimit_nofile {{.Env.ANGIE_WORKER_RLIMIT_NOFILE}};

error_log  /var/log/angie/error.log {{.Env.ANGIE_ERROR_LOG_SEVERITY}};
pid        {{.Env.ANGIE_PID_FILE}};

events {
    worker_connections  {{.Env.ANGIE_WORKER_CONNECTIONS}};
}

http {
    include       /etc/angie/mime.types;
    default_type  application/octet-stream;

    log_format  main  ...
```

运行具有 shell 访问权限的容器:

```console
$ docker run -it --pull always --rm --entrypoint=sh \
  docker.angie.software/angie:templated
```

使用自定义连接参数和模块运行 Angie
(命令 **angie -T** 将输出完整配置):

```console
$ docker run -it --rm -e ANGIE_WORKER_CONNECTIONS=4 \
  -e ANGIE_LOAD_MODULES="auth-jwt,vod" \
  docker.angie.software/angie:templated angie -T
```

启动具有指定名称和附加模块的容器:

```console
$ docker run -it --rm --name angie-test \
  -e ANGIE_WORKER_CONNECTIONS=4 \
  -e ANGIE_LOAD_MODULES="auth-jwt,vod" \
  docker.angie.software/angie:templated
```

重新加载正在运行的容器的配置:

```console
$ docker kill -s HUP angie-test
```

<a id="images-with-extra-modules"></a>

## 包含额外模块的镜像

- `angie:latest`:
  基于 Alpine 3.22 的  版本。
- `angie:<VERSION>`,
  `angie:<VERSION>-alpine`:
  基于 Alpine 3.22 的指定版本。
- `angie:<VERSION>-debian`:
  基于 Debian 13 的指定版本。
- `angie:<VERSION>-rocky`:
  基于 Rocky Linux 9 的指定版本。
- `angie:<VERSION>-ubuntu`:
  基于 Ubuntu 24.04 LTS 的指定版本。

这些镜像包含以下
[软件包](https://cn.angie.software//angie/docs/installation/external-modules/index.md#install-thirdpartymodules)
(如果它们已针对构建镜像所用的 [Angie 版本](https://cn.angie.software//angie/docs/oss_changes.md#oss-changes) 发布):

### 软件包列表

- `angie-console-light`
- `angie-module-auth-jwt`
- `angie-module-auth-ldap`
- `angie-module-auth-pam`
- `angie-module-auth-spnego`
- `angie-module-auth-totp`
- `angie-module-brotli`
- `angie-module-cache-purge`
- `angie-module-cgi`
- `angie-module-combined-upstreams`
- `angie-module-dav-ext`
- `angie-module-dynamic-limit-req`
- `angie-module-echo`
- `angie-module-enhanced-memcached`
- `angie-module-eval`
- `angie-module-geoip2`
- `angie-module-headers-more`
- `angie-module-http-auth-radius`
- `angie-module-image-filter`
- `angie-module-keyval`
- `angie-module-lua`
- `angie-module-modsecurity`
- `angie-module-ndk`
- `angie-module-njs`
- `angie-module-opentracing`
- `angie-module-otel`
- `angie-module-perl`
- `angie-module-postgres`
- `angie-module-redis2`
- `angie-module-rtmp`
- `angie-module-set-misc`
- `angie-module-subs`
- `angie-module-testcookie`
- `angie-module-unbrotli`
- `angie-module-upload`
- `angie-module-vod`
- `angie-module-vts`
- `angie-module-wasm`
- `angie-module-wasmtime`
- `angie-module-xslt`
- `angie-module-zip`
- `angie-module-zstd`

<a id="running"></a>

## 运行

要在端口 8080 上启动带有 Angie 的容器,
提供对静态文件目录 `/var/www/` 的只读访问
以及位于当前工作目录中的配置文件 `angie.conf`:

```console
$ docker run --rm --name angie -v /var/www:/usr/share/angie/html:ro \
    -v $(pwd)/angie.conf:/etc/angie/angie.conf:ro -p 8080:80 -d docker.angie.software/angie:latest

$ curl -I localhost:8080

    HTTP/1.1 200 OK
    Server: Angie/|version|
    Date: |sampledatelong| 10:42:54 GMT
    Content-Type: text/html
    Content-Length: 543
    Last-Modified: |sampledatelong| 09:12:23 GMT
    Connection: keep-alive
    ETag: "64c3ccc7-21f"
    Accept-Ranges: bytes
```

此类配置适用于本地开发和配置。

<a id="building-custom-images"></a>

## 构建自定义镜像

您也可以基于支持的发行版构建自己的镜像,
从 [软件包](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)
或 [源代码](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 添加 Angie 层。
相应的 `Dockerfile` 文件示例:

```dockerfile
FROM debian:13

LABEL org.opencontainers.image.authors="Release Engineering Team <devops@tech.wbsrv.ru>"

ARG DEBIAN_FRONTEND=noninteractive

RUN set -x \
     && apt-get update \
     && apt-get install --no-install-recommends --no-install-suggests -y \
          ca-certificates curl \
     && curl -o /etc/apt/trusted.gpg.d/angie-signing.gpg \
          https://angie.software/keys/angie-signing.gpg \
     && echo "deb https://download.angie.software/angie/$(. /etc/os-release && echo "$ID/$VERSION_ID $VERSION_CODENAME") main" \
          > /etc/apt/sources.list.d/angie.list \
     && apt-get update \
     && apt-get install --no-install-recommends --no-install-suggests -y \
          angie angie-module-geoip2 angie-module-njs \
     && rm -Rf /var/lib/apt/lists \
          /etc/apt/sources.list.d/angie.list \
          /etc/apt/trusted.gpg.d/angie-signing.gpg \
     && ln -sf /dev/stdout /var/log/angie/access.log \
     && ln -sf /dev/stderr /var/log/angie/error.log

EXPOSE 80

CMD ["angie", "-g", "daemon off;"]
```

```dockerfile
FROM alpine:3.22

LABEL org.opencontainers.image.authors="Release Engineering Team <devops@tech.wbsrv.ru>"

RUN set -x \
     && apk add --no-cache ca-certificates curl \
     && curl -o /etc/apk/keys/angie-signing.rsa https://angie.software/keys/angie-signing.rsa \
     && echo "https://download.angie.software/angie/alpine/v$(egrep -o \
          '[0-9]+\.[0-9]+' /etc/alpine-release)/main" >> /etc/apk/repositories \
     && apk add --no-cache angie angie-module-geoip2 angie-module-njs \
     && rm /etc/apk/keys/angie-signing.rsa \
     && ln -sf /dev/stdout /var/log/angie/access.log \
     && ln -sf /dev/stderr /var/log/angie/error.log

EXPOSE 80

CMD ["angie", "-g", "daemon off;"]
```

要在包含此类 `Dockerfile` 的目录中构建 `myangie` 镜像
并按上述方式启动容器:

```console
$ docker build -t myangie .
$ docker run --rm --name myangie -v /var/www:/usr/share/angie/html:ro \
    -v $(pwd)/angie.conf:/etc/angie/angie.conf:ro -p 8080:80 -d myangie
```


# https://cn.angie.software/angie/docs.md

<a id="about"></a>

# 关于 Angie

Angie
/[andʒi](https://en.wikipedia.org/wiki/International_Phonetic_Alphabet)/
是一个高效、强大且可扩展的 Web 服务器，
从 nginx 分支而来：

* 由原始团队的前开发人员构思，
  旨在超越早期愿景，
  作为 [直接替代品](https://cn.angie.software//angie/docs/configuration/migration.md#migration)，
  无需对模块设置或配置进行重大更改。
* 包含
  [nginx |nginxversion|](https://nginx.org/en/CHANGES)
  的大部分功能
  以及许多 [新特性](#index-features-oss)。

我们为多种
[系统和架构](https://cn.angie.software//angie/docs/installation/index.md#install-packages)
构建二进制包，
以及
[Docker 镜像](https://cn.angie.software//angie/docs/installation/docker.md#docker-images)。
源代码在我们的
[公共仓库](https://cn.angie.software//angie/docs/development.md#development)
中开放，
采用
[类 BSD 许可证](https://cn.angie.software//angie/license-angie.md#license-angie)。

此外，具有 [附加功能](#index-features-pro)
的商业版本以 Angie PRO 的名义销售。

可选择现成的 Angie 软件包、
Docker 镜像和源代码构建选项。

启动和运行时控制；
配置、模块、指令和变量。

解决 Angie 的技术问题，
可用的反馈渠道。

为想要为项目做出贡献的
开发人员提供的信息。

<a id="current-version"></a>

## 当前版本

**Angie |angie_version|** 和 **Angie PRO |angie_pro_version|** 于 **|angie_release_date|** 发布。
新版本每季度发布一次；
在此期间，我们会发布紧急修复和重要更新。

另请参阅
[Angie](https://cn.angie.software//angie/docs/oss_changes.md#oss-changes)
和
[Angie PRO](https://cn.angie.software//angie/docs/pro_changes.md#pro-changes)
的完整版本历史。

<a id="index-features-oss"></a>

## 特性

相对于 nginx 的核心优势，
在 Angie 的免费开源版本中可用：

- 支持客户端连接的 [HTTP/3](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#http-v3)，
  以及 [代理服务器](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http-version) 连接，
  能够在两端独立使用不同的协议版本
  （HTTP/1.x、HTTP/2、HTTP/3）。
- 自动 HTTPS 通过内置的 [ACME](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 协议支持提供 TLS 证书。
- 简化配置：`location` 指令
  可以一次定义多个匹配表达式，从而实现
  具有共享设置的块的 [组合](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#combined-locations)。
- 通过 RESTful [API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 接口以 JSON 格式
  公开有关 Web 服务器、
  其 [配置](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api-config-files)
  以及代理服务器、客户端连接、
  共享内存区域等的 [指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics)
  的基本信息。
- 以 [Prometheus](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#id3) 格式导出统计信息，
  支持 [可自定义模板](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#prometheus-template)。
- 通过
  [Console Light](https://cn.angie.software//angie/docs/configuration/monitoring.md#monitoring) 可视化监控工具
  在浏览器中监控服务器。
  查看在线演示：[https://console.angie.software/](https://console.angie.software/)
- 基于
  [Docker 容器](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker) （或类似工具如 Podman）的事件和标签
  动态更新上游组，无需
  服务器重载。
- 将 [proxy_cache_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-path) 中的共享内存区域刷新到磁盘
  可在重启和更新之间保留缓存索引内容，
  从而消除缓存加载延迟并使服务器更快上线。
- [会话绑定](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky) 模式，将一个会话内的所有请求
  定向到同一代理服务器。
- 使用 [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 指令的 `slow_start` 选项
  在故障后平滑地重新启用上游服务器。
- 按比特率成比例地 [限制 MP4 文件传输速率](https://cn.angie.software//angie/docs/configuration/modules/http/http_mp4.md#mp4-limit-rate)，
  从而减少带宽负载。
- 通过 `stream` 下的 [mqtt_preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#s-mqtt-preread) 指令
  扩展 MQTT 协议的授权和均衡功能。
- 通过 `stream` 下的 [rdp_preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#s-rdp-preread) 指令
  使用 RDP 协议的会话 cookie 为均衡决策提供信息。
- 使用
  [TongSuo](https://github.com/Tongsuo-Project/Tongsuo)
  TLS 库时的 NTLS [服务器](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-ntls) 和 [客户端](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-ntls) 支持，
  在 [构建时](https://cn.angie.software//angie/docs/installation/sourcebuild.md#install-source-features) 启用。
- 为许多流行的第三方模块预构建的
  [二进制包](https://cn.angie.software//angie/docs/installation/external-modules/index.md#install-thirdpartymodules)。

---

<a id="index-features-pro"></a>

商业 Angie PRO 在
[公开可用功能](#index-features-oss) 的基础上增加了以下内容：

- 通过 RESTful 动态配置
  [API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config) 管理代理服务器；
  可视化监控控制台 [Console Light](https://cn.angie.software//angie/docs/configuration/monitoring.md#monitoring)
  也可用于在浏览器中管理服务器。
- 通过发送定期 [探测请求](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe)
  主动检查代理服务器的状态。
- 基于代理服务器的 [平均响应时间](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-least-time)
  进行负载均衡，支持 [可自定义的平滑因子](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-response-time-factor)。
- [基于反馈](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-feedback) 的负载均衡，
  根据变量值选择对等节点；
  假设它来自对等节点本身，
  报告其 CPU 负载或其他指标。
- 请求等待队列，
  使用 `upstream` 块中的 [queue](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-queue) 指令配置。
- 附加绑定模式 [sticky learn](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky)，
  支持在共享内存或外部存储中检测和存储客户端会话，
  从而允许在集群中加入多个均衡器。
- 在 HTTP 模块的 `upstream` 块中使用 [backup_switch](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-backup-switch) 指令
  允许备份服务器
  在主服务器再次可访问时继续处理请求。
- 条件性地 [将客户端连接绑定](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-bind-conn)
  到代理服务器连接，这也支持代理 NTLM。
- 代理模块中的缓存分片，支持根据响应的属性
  在 [位置](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache) 之间分配缓存。
- 错误页面和 `Server` 头字段中的服务器签名
  可以使用 [server_tokens](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-tokens) 指令隐藏或覆盖。


# https://cn.angie.software/angie/docs/installation/external-modules/dynamic-limit-req.md

<!-- review: finished -->

<a id="external-dynamic-limit-req"></a>

# Dynamic Limit Req

该模块在请求超出速率限制时动态封禁 IP 地址，并在指定时间后自动解封。

<a id="loading-the-module-7"></a>

## 加载模块

在 `main{}` 上下文中加载模块：

```nginx
load_module modules/ngx_http_dynamic_limit_req_module.so;
```

<a id="configuration-example-84"></a>

## 配置示例

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

    dynamic_limit_req_zone $binary_remote_addr zone=one:10m rate=100r/s redis=127.0.0.1 block_second=300;
    dynamic_limit_req_zone $binary_remote_addr zone=two:10m rate=50r/s redis=127.0.0.1 block_second=600;
    dynamic_limit_req_zone $binary_remote_addr zone=sms:5m rate=5r/m redis=127.0.0.1 block_second=1800;

    server {
        listen       80;
        server_name  localhost;

        location / {
            if ($http_x_forwarded_for) {
                return 400;
            }

            root   html;
            index  index.html index.htm;

            dynamic_limit_req zone=one burst=100 nodelay;
            dynamic_limit_req_status 403;
        }

        error_page   403 500 502 503 504  /50x.html;

        location = /50x.html {
            root   html;
        }
    }

    server {
        listen       80;
        server_name  localhost2;

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

            set $flag 0;
            if ($document_uri ~* "regist") {
                set $flag "${flag}1";
            }
            if ($request_method = POST) {
                set $flag "${flag}2";
            }
            if ($flag = "012") {
                dynamic_limit_req zone=sms burst=3 nodelay;
                dynamic_limit_req_status 403;
            }

            if ($document_uri ~* "getSmsVerifyCode.do") {
                dynamic_limit_req zone=sms burst=5 nodelay;
                dynamic_limit_req_status 444;
            }

            dynamic_limit_req zone=two burst=50 nodelay;
            dynamic_limit_req_status 403;
        }

        error_page   403 502 503 504  /50x.html;

        location = /50x.html {
            root   html;
        }
    }
}
```

<a id="additional-information-8"></a>

## 更多信息

详细文档和源代码可在以下链接获取：
[https://github.com/limithit/ngx_dynamic_limit_req_module](https://github.com/limithit/ngx_dynamic_limit_req_module)


# https://cn.angie.software/angie/docs/installation/external-modules/echo.md

<!-- review: finished -->

<a id="external-echo"></a>

# Echo

该模块添加了 `echo`、`sleep`、`time`、`exec` 以及其他 shell 风格的函数。

<a id="installation-8"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-echo`
- Angie PRO：`angie-pro-module-echo`

<a id="loading-the-module-8"></a>

## 加载模块

要使用该模块，必须在 `main{}` 上下文中加载它：

```nginx
load_module modules/ngx_http_echo_module.so;
```

<a id="configuration-example-85"></a>

## 配置示例

```nginx
server {
    listen       80;
    server_name  localhost;

    location /echo {
        echo_before_body '这些行是由';
        echo_before_body 'echo_before_body 指令插入的';
        echo_after_body '这些行是由';
        echo_after_body 'echo_after_body 指令添加的';
        proxy_pass $scheme://127.0.0.1:$server_port$request_uri/more;
    }

    location /echo/more {
        set $val 'value';
        echo '======== 后端响应开始 =========';
        echo '后端响应主体';
        echo "val 被设置为 $val";
        echo '======== 后端响应结束 ===========';
    }

    location /echo_with_sleep {
        echo hello;
        echo_flush;
        echo_sleep   2.5;
        echo world;
    }

    location /dup {
        echo_duplicate 3 "--";
        echo_duplicate 1 " END ";
        echo_duplicate 3 "--";
        echo;
    }

    location /subr {
        echo_reset_timer;
        echo_location /sub1;
        echo_location /sub2;
        echo "took $echo_timer_elapsed sec for total.";
    }

    location /subr_async {
        echo_reset_timer;
        echo_location_async /sub1;
        echo_location_async /sub2;
        echo "took $echo_timer_elapsed sec for total.";
    }

    location /sub1 {
        echo_sleep 2;
        echo hello;
    }

    location /sub2 {
        echo_sleep 1;
        echo world;
    }
}
```

<a id="demonstration"></a>

## 演示

让我们发起几个请求来演示该模块的功能。

```console
$ curl localhost/echo

  这些行是由
  echo_before_body 指令插入的
  ======== 后端响应开始 =========
  后端响应主体
  val 被设置为 value
  ======== 后端响应结束 ===========
  这些行是由
  echo_after_body 指令添加的
```

```console
$ curl localhost/echo_with_sleep

  hello
  world
```

字符串 "hello" 和 "world" 将以 2.5 秒的间隔出现。

```console
$ curl localhost/dup
------ END ------
```

```console
$ time curl localhost/subr

  hello
  world
  took 3.004 sec for total.

  real    0m3.027s
  user    0m0.015s
  sys     0m0.007s
```

```console
$ time curl localhost/subr_async

  hello
  world
  took 0.000 sec for total.

  real    0m2.023s
  user    0m0.001s
  sys     0m0.020s
```

<a id="additional-information-9"></a>

## 附加信息

详细文档和源代码可在以下位置获取：
[https://github.com/openresty/echo-nginx-module](https://github.com/openresty/echo-nginx-module).


# https://cn.angie.software/angie/docs/installation/external-modules/enhanced-memcached.md

<!-- review: finished -->

<a id="external-enhanced-memcached"></a>

# 增强型 Memcached

此模块扩展了内置 [Memcached](https://cn.angie.software//angie/docs/configuration/modules/http/http_memcached.md#http-memcached) 模块的功能,允许您在 memcached 服务器上添加和删除键值数据。

<a id="installation-9"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-enhanced-memcached`
- Angie PRO:`angie-pro-module-enhanced-memcached`

<a id="loading-the-module-9"></a>

## 加载模块

在 `main{}` 上下文中加载模块:

```nginx
load_module modules/ngx_http_enhanced_memcached_module.so;
```

<a id="configuration-example-86"></a>

## 配置示例

```nginx
upstream memcached_upstream {
    server 127.0.0.1:11211;
}

server {
    listen 80;
    server_name localhost;

    location / {
        set $enhanced_memcached_key "$request_uri";
        enhanced_memcached_allow_put on;
        enhanced_memcached_allow_delete on;
        enhanced_memcached_pass memcached_upstream;
    }

    location /stats {
        enhanced_memcached_stats on;
        enhanced_memcached_pass memcached_upstream;
        access_log off;
    }

    location /flush {
        enhanced_memcached_flush on;
        enhanced_memcached_pass memcached_upstream;
    }
}
```

<a id="request-examples"></a>

## 请求示例

添加键 `key1`,值为 `key1 value`:

```console
$ curl -X PUT -d 'key1 value' http://127.0.0.1/key1
STORED
```

检索 `key1` 的值:

```console
$ curl http://127.0.0.1/key1
key1 value
```

删除键为 `key1` 的数据:

```console
$ curl -X DELETE http://127.0.0.1/key1
DELETED
```

输出 memcached 统计信息:

```console
$ curl http://127.0.0.1/stats
```

清除所有数据:

```console
$ curl http://127.0.0.1/flush
```

<a id="additional-information-10"></a>

## 其他信息

详细文档和源代码可在以下位置获取:
[https://github.com/bpaquet/ngx_http_enhanced_memcached_module](https://github.com/bpaquet/ngx_http_enhanced_memcached_module)


# https://cn.angie.software/support/enterprise.md

# 企业技术支持

企业技术支持为关键基础设施组件提供高水平的服务。企业技术支持服务包含标准技术支持的所有功能，此外还包括：

- 保证初始响应时间——最长2小时；
- 24/7全天候支持。

完整的服务条款可以在 [`这里`](https://cn.angie.software//support/Angie_enterprise.pdf) 找到。

## 标准技术支持与企业技术支持条款对比

|                          | 标准   | 企业   |
|--------------------------|------|------|
| 基于单独的技术支持协议提供            |      |      |
| 通过电子邮件和在线表单提供支持请求        |      |      |
| 通过电话提供支持请求               |      |      |
| 支持时间：工作日莫斯科时间10:00至20:00 |      |      |
| 支持时间：24/7全天候             |      |      |
| 请求的初始响应时间：最长2小时          |      |      |

## 企业技术支持提供的服务

- 解决软件功能问题。
- 就软件使用提供咨询并对文档进行说明。
- 就软件运行期间的HTTP和TCP协议操作提供咨询。
- 就修改用户操作系统设置以提升软件性能提供咨询。
- 就软件与用户安装的其他解决方案之间的交互优化机会提供咨询。
- 为满足用户个性化需求提供配置文件定制支持。
- 在技术支持服务期限内提供更新。


# https://cn.angie.software/legal/eula.md

<a id="eula-custom"></a>

# End-User License Agreement

#### NOTE
The legally binding End-User License Agreement is published in
Russian. The Russian original is the authoritative version; this page
provides an English-language reference. Please consult the Russian
original or contact [info@wbsrv.ru](mailto:info@wbsrv.ru) for assistance.

The current End-User License Agreement (EULA) governs the use of Angie
Software products distributed by Web Server, LLC (the Rights Holder)
either directly to End Users or via the Rights Holder's Partners,
including as part of integrated hardware-software solutions.

To review the current and previous versions of the EULA, refer to the
Russian-language source on the Angie website.


# https://cn.angie.software/angie/docs/installation/external-modules/eval.md

<!-- review: finished -->

<a id="external-eval"></a>

# Eval

该模块允许将子请求响应体保存到变量中。

<a id="installation-10"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-eval`
- Angie PRO：`angie-pro-module-eval`

<a id="loading-the-module-10"></a>

## 加载模块

在 `main{}` 上下文中加载模块：

```nginx
load_module modules/ngx_http_eval_module.so;
```

<a id="example-configuration-1"></a>

## 配置示例

```nginx
server {
    listen 80;
    server_name localhost;

    location / {
        eval_subrequest_in_memory off;
        eval_override_content_type text/plain;
        eval_buffer_size 4k;
        eval $res {
            rewrite ^(/eval_.*/)(.*)$  /$2 break;
            proxy_pass http://127.0.0.1:8081;
        }

        if ($res ~ "access denied") {
            return 403 $res\n;
        }

        proxy_pass http://127.0.0.1:8082;
    }
}

server {
    listen 8081;

    if ($arg_user != 'Legal') {
        return 403 "access denied";
    }
    return 200 OK;
}

server {
    listen 8082;

    location / {
        root /usr/share/angie/html;
    }
}
```

<a id="additional-information-11"></a>

## 其他信息

详细文档和源代码可在以下位置获取：
[https://github.com/openresty/nginx-eval-module](https://github.com/openresty/nginx-eval-module)


# https://cn.angie.software/news/events.md

# 活动

## [Angie Web服务器一年后：新机遇与未来规划](https://cn.angie.software//news/events/veb-server-angie-god-spustya-novie-vozmozhnosti.md)

*27.11.2023*

Angie开发负责人Valentin Bartenyev将在HighLoad 2023大会上回顾项目第一年的发展历程。

![替代文本](../../_images/news/veb-server-angie-god-spustya-novie-vozmozhnosti.jpeg)


# https://cn.angie.software/angie/docs/installation/external-modules.md

<!-- review: finished -->
<!-- Legacy links -->

<a id="install-thirdpartymodules"></a>

# 第三方模块

除了我们自己为 [Angie](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-dynamicmodules-oss) 和 [Angie PRO](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-dynamicmodules-pro) 开发的动态模块外，
我们还在仓库中收集并发布了一些流行的 nginx 兼容第三方模块的软件包，
这些模块由我们公司之外的开发者开发。

<a id="installation-and-configuration-1"></a>

## 安装和配置

第三方模块软件包的安装方式与我们自己的软件包相同，都是从我们的仓库安装：

- [Angie](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)
- [Angie PRO](https://cn.angie.software//angie/docs/installation/pro_packages.md#pro-packages)

要在 [配置](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile) 中使用已安装的模块，
请在 `main` 上下文中使用 [load_module](https://cn.angie.software//angie/docs/configuration/modules/core.md#load-module) 指令加载它：

```nginx
load_module modules/<module_name>.so;
```

#### NOTE
我们不审查这些模块的源代码，
也不对安装它们的后果负责；
这些软件包的编译完全基于大量用户请求，
 *仅仅* 为了用户的便利。

<a id="list-of-modules"></a>

## 模块列表

| 模块                                                                                                                                                                                                                                                                                                                 | 版本                       | 软件包                                                                      | 描述                                                                                                                                      |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------|--------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| [Auth JWT](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)                                                                                                                                                                                                      | 0.9.0                    | `angie-module-auth-jwt`  `angie-pro-module-auth-jwt`                     | 为客户端添加 JWT 身份验证。                                                                                                                        |
| [Auth LDAP](https://cn.angie.software//angie/docs/installation/external-modules/auth-ldap.md#external-ldap)                                                                                                                                                                                                        | 241200e                  | `angie-module-auth-ldap`  `angie-pro-module-auth-ldap`                   | 添加对多服务器 LDAP 身份验证的支持。                                                                                                                   |
| [Auth PAM](https://cn.angie.software//angie/docs/installation/external-modules/auth-pam.md#external-auth-pam)                                                                                                                                                                                                      | v1.5.5                   | `angie-module-auth-pam`  `angie-pro-module-auth-pam`                     | 添加对 PAM 身份验证的支持。                                                                                                                        |
| [Auth SPNEGO](https://cn.angie.software//angie/docs/installation/external-modules/auth-spnego.md#external-auth-spnego)                                                                                                                                                                                             | v1.1.3                   | `angie-module-auth-spnego`  `angie-pro-module-auth-spnego`               | 添加对 SPNEGO 和 GSSAPI 的支持。                                                                                                                |
| [Auth TOTP](https://cn.angie.software//angie/docs/installation/external-modules/auth-totp.md#external-auth-totp)                                                                                                                                                                                                   | 1.1.0                    | `angie-module-auth-totp`  `angie-pro-module-auth-totp`                   | 添加基于 TOTP 的一次性密码身份验证。                                                                                                                   |
| [Brotli](https://cn.angie.software//angie/docs/installation/external-modules/brotli.md#external-brotli)                                                                                                                                                                                                            | v1.0.0rc                 | `angie-module-brotli`  `angie-pro-module-brotli`                         | 为响应添加静态和动态 Brotli 压缩。                                                                                                                   |
| [Cache Purge](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge)                                                                                                                                                                                             | 2.5.3                    | `angie-module-cache-purge`  `angie-pro-module-cache-purge`               | 允许从 FastCGI、proxy、SCGI 和 uWSGI 缓存中清除内容。                                                                                                 |
| [CGI](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)                                                                                                                                                                                                                     | v0.13                    | `angie-module-cgi`  `angie-pro-module-cgi`                               | 添加对 CGI 的支持。                                                                                                                            |
| [Combined Upstreams](https://cn.angie.software//angie/docs/installation/external-modules/combined-upstreams.md#external-combined-upstreams)                                                                                                                                                                        | 2.3.1                    | `angie-module-combined-upstreams`  `angie-pro-module-combined-upstreams` | 允许将多个服务器组合并为一个。                                                                                                                         |
| [DAV Ext](https://cn.angie.software//angie/docs/installation/external-modules/dav-ext.md#external-dav-ext)                                                                                                                                                                                                         | v3.0.0                   | `angie-module-dav-ext`  `angie-pro-module-dav-ext`                       | 通过 PROPFIND 和 OPTIONS 方法扩展 WebDAV 支持。                                                                                                   |
| [Dynamic Limit Req](https://cn.angie.software//angie/docs/installation/external-modules/dynamic-limit-req.md#external-dynamic-limit-req)                                                                                                                                                                           | 1.9.3                    | `angie-module-dynamic-limit-req`  `angie-pro-module-dynamic-limit-req`   | 用于动态阻止 IP 地址并定期解除阻止。                                                                                                                    |
| [Echo](https://cn.angie.software//angie/docs/installation/external-modules/echo.md#external-echo)                                                                                                                                                                                                                  | v0.63                    | `angie-module-echo`  `angie-pro-module-echo`                             | 允许在配置文件中调用 `echo`、`sleep`、`time`、`exec`<br/>和其他 shell 命令。                                                                               |
| [Enhanced Memcached](https://cn.angie.software//angie/docs/installation/external-modules/enhanced-memcached.md#external-enhanced-memcached)                                                                                                                                                                        | v0.3                     | `angie-module-enhanced-memcached`  `angie-pro-module-enhanced-memcached` | 扩展内置 [Memcached](https://cn.angie.software//angie/docs/configuration/modules/http/http_memcached.md#http-memcached) 模块的功能。              |
| [Eval](https://cn.angie.software//angie/docs/installation/external-modules/eval.md#external-eval)                                                                                                                                                                                                                  | 2016.06.10               | `angie-module-eval`  `angie-pro-module-eval`                             | 允许将子请求的响应体保存到变量中。                                                                                                                       |
| [GeoIP2](https://cn.angie.software//angie/docs/installation/external-modules/geoip2.md#external-geoip2)                                                                                                                                                                                                            | 3.4                      | `angie-module-geoip2`  `angie-pro-module-geoip2`                         | 在 MaxMind GeoIP2 数据库中添加地理位置搜索。                                                                                                          |
| [Headers More](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)                                                                                                                                                                                          | v0.39                    | `angie-module-headers-more`  `angie-pro-module-headers-more`             | 允许设置和清除请求和响应头。                                                                                                                          |
| [HTTP Auth Radius](https://cn.angie.software//angie/docs/installation/external-modules/http-auth-radius.md#external-http-auth-radius)                                                                                                                                                                              | 458af16                  | `angie-module-http-auth-radius`  `angie-pro-module-http-auth-radius`     | 添加对 Radius 的支持。                                                                                                                         |
| [JWT](https://cn.angie.software//angie/docs/installation/external-modules/jwt.md#external-jwt)                                                                                                                                                                                                                     | v3.4.3                   | `angie-module-jwt`  `angie-pro-module-jwt`                               | [Auth JWT](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt) 的轻量级替代方案。                 |
| [Keyval](https://cn.angie.software//angie/docs/installation/external-modules/keyval.md#external-keyval)                                                                                                                                                                                                            | 0.3.0                    | `angie-module-keyval`  `angie-pro-module-keyval`                         | 允许使用来自键值对的值的变量。                                                                                                                         |
| [Lua](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua)：<br/>[http_lua_module](https://github.com/openresty/lua-nginx-module)、<br/>[stream_lua_module](https://github.com/openresty/stream-lua-nginx-module)                                                                | 0.10.28 / v0.0.16        | `angie-module-lua`  `angie-pro-module-lua`                               | 分别允许在 Angie 配置的 `http` 和 `stream` 上下文中<br/>使用 Lua 语言。                                                                                   |
| [ModSecurity](https://cn.angie.software//angie/docs/installation/external-modules/modsecurity.md#external-modsec)                                                                                                                                                                                                  | v1.0.4                   | `angie-module-modsecurity`  `angie-pro-module-modsecurity`               | 添加用于使用 ModSecurity 规则的连接器。                                                                                                              |
| [NJS](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)：<br/>[http_js](https://cn.angie.software//angie/docs/installation/external-modules/http_js.md#http-js)、<br/>[stream_js](https://cn.angie.software//angie/docs/installation/external-modules/stream_js.md#stream-js) | 0.9.1                    | `angie-module-njs`  `angie-pro-module-njs`                               | 分别允许在 Angie 配置的 `http` 和 `stream` 上下文中<br/>使用 njs（JavaScript 语言的子集）。<br/><br/>还提供名为 `...-njs-light` 的轻量级版本软件包；<br/>但是，它与常规版本不兼容，不能同时使用。 |
| [NDK](https://cn.angie.software//angie/docs/installation/external-modules/ndk.md#external-ndk)                                                                                                                                                                                                                     | v0.3.4                   | `angie-module-ndk`  `angie-pro-module-ndk`                               | 添加 Nginx 开发工具包（NDK）用于开发新模块。                                                                                                             |
| [OpenTracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)                                                                                                                                                                                             | v0.41.0                  | `angie-module-opentracing`  `angie-pro-module-opentracing`               | 在 Angie 中添加分布式 OpenTracing 请求跟踪；<br/>包含用于将数据导出到 Zipkin 和 DataDog 的插件。                                                                   |
| [OpenTelemetry](https://cn.angie.software//angie/docs/installation/external-modules/otel.md#external-otel)                                                                                                                                                                                                         | v0.1.2                   | `angie-module-otel`  `angie-pro-module-otel`                             | 允许将遥测数据发送到 OpenTelemetry 收集器。                                                                                                           |
| [PostgreSQL](https://cn.angie.software//angie/docs/installation/external-modules/postgres.md#external-postgres)                                                                                                                                                                                                    | 1.0rc7                   | `angie-module-postgres`  `angie-pro-module-postgres`                     | 包含对 PostgreSQL 数据库的直接支持。                                                                                                                |
| [Redis2](https://cn.angie.software//angie/docs/installation/external-modules/redis2.md#external-redis2)                                                                                                                                                                                                            | v0.15                    | `angie-module-redis2`  `angie-pro-module-redis2`                         | 包含对 HTTP 上游的 Redis 2.0 支持。                                                                                                              |
| [RTMP](https://cn.angie.software//angie/docs/installation/external-modules/rtmp.md#external-rtmp)                                                                                                                                                                                                                  | v1.2.2                   | `angie-module-rtmp`  `angie-pro-module-rtmp`                             | 包含对用于流媒体和点播广播的 RTMP 支持。                                                                                                                 |
| [Set Misc](https://cn.angie.software//angie/docs/installation/external-modules/set-misc.md#external-set-misc)                                                                                                                                                                                                      | v0.33                    | `angie-module-set-misc`  `angie-pro-module-set-misc`                     | 向 [Rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#http-rewrite) 模块添加各种 set_xxx 指令。           |
| [Subs](https://cn.angie.software//angie/docs/installation/external-modules/subs.md#external-subs)                                                                                                                                                                                                                  | e12e965                  | `angie-module-subs`  `angie-pro-module-subs`                             | 允许使用正则表达式替换 HTTP 响应体中的字符串。                                                                                                              |
| [TestCookie](https://cn.angie.software//angie/docs/installation/external-modules/testcookie.md#external-testcookie)                                                                                                                                                                                                | 64137c2                  | `angie-module-testcookie`  `angie-pro-module-testcookie`                 | 使用基于 cookie 的"质询-响应"机制帮助对抗机器人。                                                                                                          |
| [UnBrotli](https://cn.angie.software//angie/docs/installation/external-modules/unbrotli.md#external-unbrotli)                                                                                                                                                                                                      | 60bed63                  | `angie-module-unbrotli`  `angie-pro-module-unbrotli`                     | 为不支持 Brotli 编码的客户端解压 `Content-Encoding: br` 的响应。                                                                                        |
| [Upload](https://cn.angie.software//angie/docs/installation/external-modules/upload.md#external-upload)                                                                                                                                                                                                            | 2.3.0                    | `angie-module-upload`  `angie-pro-module-upload`                         | 为来自客户端的文件上传添加 `multipart/form-data` （RFC 1867）编码，<br/>包括断点续传功能。                                                                         |
| [VOD](https://cn.angie.software//angie/docs/installation/external-modules/vod.md#external-vod)                                                                                                                                                                                                                     | 1.33                     | `angie-module-vod`  `angie-pro-module-vod`                               | 允许重新打包 MP4 文件以通过 HLS、HDS、MSS 和 DASH 进行流式传输。                                                                                             |
| [VTS](https://cn.angie.software//angie/docs/installation/external-modules/vts.md#external-vts)：<br/>[module-vts](https://github.com/vozlt/nginx-module-vts)、<br/>[module-sts](https://github.com/vozlt/nginx-module-sts)、<br/>[module-stream-sts](https://github.com/vozlt/nginx-module-stream-sts)                | v0.2.4 / v0.1.1 / v0.1.1 | `angie-module-vts`  `angie-pro-module-vts`                               | 包含上述三个用于流量监控的模块。                                                                                                                        |
| [ZIP](https://cn.angie.software//angie/docs/installation/external-modules/zip.md#external-zip)                                                                                                                                                                                                                     | 1.3.0                    | `angie-module-zip`  `angie-pro-module-zip`                               | 包含动态 ZIP 归档打包。                                                                                                                          |
| [Zstd](https://cn.angie.software//angie/docs/installation/external-modules/zstd.md#external-zstd)                                                                                                                                                                                                                  | f4ba115                  | `angie-module-zstd`  `angie-pro-module-zstd`                             | 包含 Zstandard 压缩。                                                                                                                        |


# https://cn.angie.software/genindex.md



# https://cn.angie.software/angie/docs/installation/external-modules/geoip2.md

<!-- review: finished -->

<a id="external-geoip2"></a>

# GeoIP2

GeoIP2 模块通过客户端的 IP 地址(默认)或特定变量的值在 MaxMind GeoIP2 数据库中实现查找。它同时支持 IPv4 和 IPv6。

<a id="installation-11"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie: `angie-module-geoip2`
- Angie PRO: `angie-pro-module-geoip2`

<a id="loading-the-module-11"></a>

## 加载模块

要使用该模块,必须在 `main{}` 上下文中加载它:

```nginx
load_module modules/ngx_http_geoip2_module.so;    # 用于 http{} 块
load_module modules/ngx_stream_geoip2_module.so;  # 用于 stream{} 上下文
```

在下面的配置示例中,除了模块本身的指令外,还使用了 [echo](https://cn.angie.software//angie/docs/installation/external-modules/echo.md#external-echo) 模块的指令:

```nginx
load_module modules/ngx_http_echo_module.so;
```

<a id="configuration-example-87"></a>

## 配置示例

```nginx
http {
    geoip2 /var/lib/GeoIP/GeoLite2-Country.mmdb {
        auto_reload 1h;
        $geoip2_country_code default=RU source=$http_x_forwarded_for country iso_code;
        $geoip2_country_name source=$http_x_forwarded_for country names ru;
    }

    log_format with_geoip '$server_port $remote_addr - $remote_user [$time_local] "$request" '
                           '$status $body_bytes_sent "$http_referer" '
                           '"$http_user_agent" "$http_x_forwarded_for" "$http_host" '
                           'country="$geoip2_country_code"';

    map $geoip2_country_code $denied {
        PL "1";
        QA "1";
    }

    server {
        listen 80;
        root /usr/share/angie/html;
        index index.html index.htm;
        access_log /var/log/angie/geoip_access.log with_geoip;

        if ($denied) {
            return 403;
        }

        location / {
            echo "ip = $http_x_forwarded_for";
            echo "code = $geoip2_country_code";
            echo "name = $geoip2_country_name";
        }
    }
}
```

<a id="request-execution-examples-1"></a>

## 请求执行示例

```console
$ curl -H'X-Forwarded-For: 51.68.138.153' http://127.0.0.1

<html>
<head><title>403 Forbidden</title></head>
<body>
<center><h1>403 Forbidden</h1></center>
<hr><center>Angie/|angie_version|</center>
</body>
</html>
```

```console
$ curl -H'X-Forwarded-For: 8.8.8.8' http://127.0.0.1

ip = 8.8.8.8
code = US
name = United States
```

```console
$ curl -H'X-Forwarded-For: 77.88.44.242' http://127.0.0.1

ip = 77.88.44.242
code = RU
name = Russia
```

<a id="additional-information-12"></a>

## 其他信息

详细文档和源代码可在以下位置获取:
[https://github.com/leev/ngx_http_geoip2_module](https://github.com/leev/ngx_http_geoip2_module)


# https://cn.angie.software/angie/docs/configuration/modules/google_perftools.md

<!-- review: finished -->

<a id="google-perftools"></a>

# Google PerfTools 模块

使用 [Google Performance Tools](https://github.com/gperftools/gperftools) 对 Angie 工作进程进行性能分析。该模块面向 Angie 开发人员，通过提供有关内存使用、CPU 负载和其他性能指标的详细信息，帮助他们分析和优化服务器性能。

在 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，默认不构建此模块；需要使用 `--with-google_perftools_module` [构建参数](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用。

#### NOTE
此模块需要 [gperftools](https://github.com/gperftools/gperftools) 库。

<a id="configuration-example-2"></a>

## 配置示例

```nginx
google_perftools_profiles /var/log/angie/perftools;
```

性能分析文件将存储在类似 `/var/log/angie/perftools.<工作进程 PID>` 的文件中。

<a id="directives-2"></a>

## 指令

<a id="index-0"></a>

<a id="google-perftools-profiles"></a>

### google_perftools_profiles

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `google_perftools_profiles` 文件前缀;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | —                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                                |

设置文件名前缀，用于存储 Angie 工作进程的性能分析信息。工作进程 ID 会附加在文件名末尾的点号之后，例如：`/var/log/angie/perftools.1234`。


# https://cn.angie.software/angie/docs/configuration/grafana.md

<!-- review: finished -->

<a id="grafana"></a>

# 配置 Grafana 仪表板

要在 Grafana 中配置 [Angie 的仪表板](https://grafana.com/grafana/dashboards/20719-angie-dashboard/)，请按照以下步骤操作：

1. 使用 [Prometheus](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#http-prometheus) 模块，
   添加以下 [include](https://cn.angie.software//angie/docs/configuration/modules/core.md#include) 指令到 [配置文件](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile) 的 `http` 块中：
   ```nginx
   http {
       include prometheus_all.conf;

       # ...
   }
   ```

   以及在一个使用指定 IP 地址和端口组合的单独 `server` 块中的 `location` 内添加相应的 [prometheus](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#id3) 指令，例如：
   ```nginx
   server {

       listen 192.168.1.100:80;

       location =/p8s {
           prometheus all;
       }

       # ...

   }
   ```

   它们在 `location` 指定的端点以 Prometheus 格式导出 Angie 指标。
2. 将以下配置添加到 Prometheus 中，
   指定在前面步骤中设置的 `server` 的 IP 地址和端口：
   ```yaml
   scrape_configs:
     - job_name: "angie"
       scrape_interval: 15s
       metrics_path: "/p8s"
       static_configs:
         - targets: ["192.168.1.100:80"]
   ```

   它每 15 秒收集一次指标，
   使用在上一步中配置的 `/p8s` 路径。

   #### NOTE
   确保全局 `scrape_interval` 的值不大于此处的值。
3. 将 [Angie 的仪表板](https://grafana.com/grafana/dashboards/20719-angie-dashboard/) 导入到 Grafana 中。


# https://cn.angie.software/news/gruppa-rubytech-i-angie-objedinaiut-resursi.md

# Rubytech集团与俄罗斯Web服务器开发商Angie整合资源与专业技术，共同推进产品开发

*22.08.2024*

俄罗斯高负载系统软件开发商Angie（Web Server有限责任公司）已加入Rubytech集团。

![Alternative text](../../_images/news/gruppa-rubytech-i-angie-objedinaiut-resursi.webp)![Alternative text](../../_images/news/gruppa-rubytech-i-angie-objedinaiut-resursi.webp)

 *俄罗斯高负载系统软件开发商Angie（Web Server有限责任公司）已加入Rubytech集团。这一战略合作伙伴关系将扩大和丰富集团的产品组合，同时为开发商提供稳定的产品开发前景，以满足企业领域最迫切的需求。*

自2022年以来，Angie一直在开发其旗舰产品——基于世界知名的nginx（一个开源产品）分支开发的Web服务器。短短几年内，Angie的产品在集群软件解决方案领域建立了强大的声誉，并在俄罗斯市场上赢得了领导者地位。公司的产品已被列入国产软件登记册。

通过此次合作，集团的客户将有机会使用Angie的高性能和可扩展产品来构建和发展自己的IT基础设施，同时由Rubytech的专家、工程师和系统架构师团队提供实施和可靠的技术支持。而Angie的开发团队将继续开发现有产品组合，并为当前客户和合作伙伴保持一贯的解决方案和服务支持水平。Angie的两款旗舰产品——Angie PRO Web服务器和Kubernetes云环境解决方案Angie Ingress Controller（ANIC），以及Angie Web服务器的开源版本都将获得更集中的开发资源。

 *"通过与Rubytech的合作，我们的商业能力将得到集团销售团队多年经验和实践的加强。这不仅使我们能够支持和发展自己的合作伙伴销售渠道，还能达到质的新高度。*

 *这将使我们作为开发商能够快速且自信地将新解决方案推向市场——Angie Application Delivery Controller（Angie ADC）流量平衡系统，它将替代Citrix ADC/Netscaler、Radware和F5 BIG-IP等西方软件产品，"* Angie（Web Server有限责任公司）总经理\*\*Zaur Abasmirzoev\*\*如是评论。

 *"在做出合作决定时，我们主要看重Angie开发团队的独特专业技术，他们是世界级Web服务器nginx的创始团队。*

 *我相信产品、商业和管理经验的整合将使双方受益。Angie的开发人员将有机会显著扩大业务规模并实现可持续增长和发展：推出新产品并使其在企业客户中备受欢迎。而Rubytech集团将能够为客户提供更广泛的技术和解决方案栈，用于构建、发展和扩展IT基础设施。*

 *我相信这种联盟将是一项成功且互惠互利的投资，有助于在长期战略框架内发展集团业务，"* Rubytech集团首席执行官\*\*Igor Vedekhin\*\*分享了对未来的计划。


# https://cn.angie.software/angie/docs/installation/external-modules/headers-more.md

<!-- review: finished -->

<a id="external-headers-more"></a>

# Headers-More

headers-more 模块允许您添加、设置或删除任何传出或传入的头。

<a id="installation-12"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-headers-more`
- Angie PRO:`angie-pro-module-headers-more`

<a id="loading-the-module-12"></a>

## 加载模块

要使用该模块,必须在 `main{}` 上下文中加载它:

```nginx
load_module modules/ngx_http_headers_more_filter_module.so;
```

在下面的配置示例中,除了该模块自己的指令外,还使用了 echo 模块的指令。
加载 echo 模块:

```nginx
load_module modules/ngx_http_echo_module.so;
```

<a id="configuration-example-88"></a>

## 配置示例

```nginx
http {
    server {
        listen 80;

        root  /usr/share/angie/html;
        index index.html index.htm;

        location /clear {
            more_clear_headers 'Content-Type';
            proxy_pass http://127.0.0.1:8081;
        }

        location /settype {
            more_set_headers 'Content-Type: text/plain';
            proxy_pass http://127.0.0.1:8081;
        }

        location /changetype {
            more_set_headers -t 'text/plain text/css' 'Content-Type: text/newtype';
            proxy_pass http://127.0.0.1:8081;
        }

        location /newheader {
            more_set_headers -t 'text/plain text/css' 'New-Header: foo';
            proxy_pass http://127.0.0.1:8081;
        }

        location /404 {
            more_set_headers -s '400 404 500 503' 'Upstream-Status: $upstream_status';
            proxy_pass http://127.0.0.1:8081;
        }

        location /input {
            set $my_host 'my.host';
            more_set_input_headers 'Host: $my_host';
            more_set_input_headers -t 'text/plain' 'X-Foo: bar';

            echo "Host: $host";
            echo "X-foo: $http_x_foo";
        }
    }

    server {
        listen 8081;
        default_type text/css;

        location / {
            return 200 "OK\n";
        }

        location /404 {
            return 404 "Done\n";
        }
    }
}
```

<a id="additional-information-13"></a>

## 其他信息

详细文档和源代码可在以下位置获取:
[https://github.com/openresty/headers-more-nginx-module/](https://github.com/openresty/headers-more-nginx-module/)


# https://cn.angie.software/angie/docs/installation/external-modules/http-auth-radius.md

<!-- review: finished -->

<a id="external-http-auth-radius"></a>

# HTTP Auth RADIUS

此模块使用 RADIUS 协议提供 HTTP 身份验证。

<a id="installation-13"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-http-auth-radius`
- Angie PRO：`angie-pro-module-http-auth-radius`

<a id="loading-the-module-13"></a>

## 加载模块

在 `main{}` 上下文中加载模块：

```nginx
load_module modules/ngx_http_auth_radius_module.so;
```

<a id="configuration-example-89"></a>

## 配置示例

```nginx
http {

    radius_server "radius_server1" {
        auth_timeout 5;
        resend_limit 3;
        url "127.0.0.1:1812";
        share_secret "secret";
    }

    server {
        listen 80;
        server_name localhost;

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

            # RADIUS 服务器配置
            # 第三个参数定义身份验证方法：
            # PAP CHAP MSCHAP MSCHAP2 EAPMD5

            auth_radius_server "radius_server1" "PAP";

            # 参数值：
            # Restricted、"Close Content"、off

            auth_radius "Restricted";
        }
    }
}
```

<a id="additional-information-14"></a>

## 其他信息

详细文档和源代码可在以下位置获取：
[https://github.com/ten0s/ngx_http_auth_radius_module/](https://github.com/ten0s/ngx_http_auth_radius_module/)


# https://cn.angie.software/angie/docs/configuration/modules/http.md

<a id="http-core"></a>

# HTTP 模块

核心 HTTP 模块实现了 HTTP 服务器的基本功能：包括定义服务器块、配置用于请求路由的位置、提供静态文件和控制访问、配置重定向、支持 keep-alive 连接以及管理请求和响应标头。

本节中的其他模块扩展了此功能，允许您针对各种场景和需求灵活配置和优化 HTTP 服务器。

<a id="directives-55"></a>

## 指令

<a id="index-0"></a>

<a id="absolute-redirect"></a>

### absolute_redirect

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `absolute_redirect` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `absolute_redirect on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

如果禁用,Angie 发出的重定向将是相对的。

另请参阅 [server_name_in_redirect](#server-name-in-redirect) 和 [port_in_redirect](#port-in-redirect) 指令。

<a id="index-1"></a>

<a id="aio"></a>

### aio

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `aio` `on` | `off` | `threads` [=pool];   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | `aio off;`                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                    |

在 FreeBSD 和 Linux 上启用或禁用异步文件 I/O (AIO) 的使用:

```nginx
location /video/ {
  aio            on;
  output_buffers 1 64k;
}
```

在 FreeBSD 上,从 FreeBSD 4.3 开始可以使用 AIO。在 FreeBSD 11.0 之前,AIO 可以静态链接到内核中:

```nginx
options VFS_AIO
```

或作为内核可加载模块动态加载:

```nginx
kldload aio
```

在 Linux 上,从内核版本 2.6.22 开始可以使用 AIO。此外,还需要启用 [directio](#directio),否则读取将会阻塞:

```nginx
location /video/ {
  aio            on;
  directio       512;
  output_buffers 1 128k;
}
```

在 Linux 上,:ref:directio 只能用于读取按 512 字节边界对齐的块(对于 XFS 为 4K)。文件的未对齐末尾以阻塞模式读取。对于字节范围请求和非从文件开头开始的 FLV 请求也是如此:在文件开头和末尾读取未对齐的数据将会阻塞。

当在 Linux 上同时启用 AIO 和 [sendfile](#sendfile) 时,对于大于或等于 [directio](#directio) 指令中指定大小的文件使用 AIO,而对于较小的文件或禁用 [directio](#directio) 时使用 [sendfile](#sendfile):

```nginx
location /video/ {
  sendfile       on;
  aio            on;
  directio       8m;
}
```

最后,可以使用多线程读取和 [发送](#sendfile) 文件,而不会阻塞工作进程:

```nginx
location /video/ {
  sendfile       on;
  aio            threads;
}
```

读取和发送文件操作被卸载到指定 [池](https://cn.angie.software//angie/docs/configuration/modules/core.md#thread-pool) 的线程。如果省略池名称,则使用名为 "default" 的池。池名称也可以使用变量设置:

```nginx
aio threads=pool$disk;
```

使用 `aio on` 需要使用 `--with-file-aio` 配置参数进行构建。使用 `aio threads` 需要使用 `--with-threads` 参数进行构建。

目前,多线程仅与 [epoll](https://cn.angie.software//angie/docs/configuration/processing.md#epoll)、[kqueue](https://cn.angie.software//angie/docs/configuration/processing.md#kqueue) 和 [eventport](https://cn.angie.software//angie/docs/configuration/processing.md#eventport) 方法兼容。多线程发送文件仅在 Linux 上受支持。

另请参阅 [sendfile](#sendfile) 指令。

<a id="index-2"></a>

<a id="aio-write"></a>

### aio_write

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `aio_write` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `aio_write off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

如果启用了 [aio](#aio),指定是否将其用于写入文件。目前,这仅在使用 `aio threads` 时有效,并且仅限于写入包含从代理服务器接收的数据的临时文件。

<a id="index-3"></a>

<a id="alias"></a>

### alias

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `alias` path;   |
|--------------------------------------------------------------------------------------|-----------------|
| 默认值                                                                                  | —               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location        |

为指定的位置定义替换路径。例如,使用以下配置:

```nginx
location /i/ {
  alias /data/w3/images/;
}
```

对于 `/i/top.gif` 的请求,将发送文件 /data/w3/images/top.gif。

path 值可以包含变量,但不包括 [$document_root](#v-document-root) 和 [$realpath_root](#v-realpath-root)。

如果在使用正则表达式定义的位置内使用 `alias`,则该正则表达式应包含捕获组,并且 `alias` 应引用这些捕获组,例如:

```nginx
location ~ ^/users/(.+\.(?:gif|jpe?g|png))$ {
  alias /data/w3/images/$1;
}
```

当位置匹配指令值的最后部分时:

```nginx
location /images/ {
  alias /data/w3/images/;
}
```

最好使用 [root](#root) 指令:

```nginx
location /images/ {
  root /data/w3;
}
```

<a id="index-4"></a>

<a id="auth-delay"></a>

### auth_delay

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `auth_delay` time;     |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | `auth_delay 0s;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

延迟处理返回 401 响应代码的未授权请求,以防止在通过 [密码](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_basic.md#http-auth-basic) 或 [子请求结果](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_request.md#http-auth-request) 限制访问时的时序攻击。

<a id="index-5"></a>

<a id="auto-redirect"></a>

### auto_redirect

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `auto_redirect` [`on` | `off` | `default`];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | `auto_redirect default;`                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                        |

控制当前缀位置以斜杠结尾时的 [重定向](#location-redirect) 行为:

```nginx
location /prefix/ {
    auto_redirect on;
}
```

在这里,对 `/prefix` 的请求会导致重定向到 `/prefix/`。

值 `on` 显式启用重定向,而 `off` 禁用它。当设置为 `default` 时,仅当位置使用 [api](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api)、[proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass)、[fastcgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-pass)、[uwsgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-pass)、[scgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-pass)、[memcached_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_memcached.md#memcached-pass) 或 [grpc_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_grpc.md#grpc-pass) 处理请求时才启用重定向。

<a id="index-6"></a>

<a id="chunked-transfer-encoding"></a>

### chunked_transfer_encoding

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `chunked_transfer_encoding` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `chunked_transfer_encoding on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

允许在 HTTP/1.1 中禁用分块传输编码。当使用的软件尽管标准要求但不支持分块编码时,这可能会派上用场。

<a id="index-7"></a>

<a id="client"></a>

### client

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `client` { ... }   |
|--------------------------------------------------------------------------------------|--------------------|
| 默认值                                                                                  | —                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http               |

创建一个特殊的 `client` 上下文,用于处理 Angie 自行执行的内部 HTTP 请求,而无需外部客户端参与。

`client` 上下文将来自各种 Angie 模块的服务流量与用户流量隔离,允许对其进行额外控制。在此上下文中,只能定义命名位置(带有 `@` 前缀);它们无法被外部 HTTP 请求访问,只能通过内部服务器机制以编程方式调用。

`client` 上下文用于:

- 在 [ACME](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 模块中通过预定义的 `location @acme` 向证书颁发机构发送请求,可以使用 [代理](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy) 模块的指令进行额外配置;
- 在 [Docker](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker) 模块中通过预定义的 `location @docker_events` 和 `@docker_containers` 向 Docker API 发送请求,可以使用 [代理](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy) 模块的指令进行额外配置;
- 通过 [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe) 对代理服务器进行健康探测;
- 在流 [Upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 模块中使用 `remote_action` 的 [sticky learn](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-sticky) 模式。

支持多个 `client` 块允许在每个块内为多个 `location` 块分组通用设置,这有助于避免配置重复。

在每个 `client` 块中指定的指令仅由在其中显式声明的 `location` 块继承。特别是,这就是为什么它们不会影响隐式使用 `client` 块进行出站请求的其他模块的配置(例如 [ACME](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 或 [Docker](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker))。

使用多个 `client` 块并继承设置的示例:

```nginx
client {

    proxy_set_header Host docker.example.com;
    proxy_set_header Authorization "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==";

    location @docker_events {

    }

    location @docker_containers {

    }
}

client {

    proxy_method GET;
    proxy_set_header Host backend.example.com;
    proxy_set_header X-Real-IP $remote_addr;

    location @health_check {

        proxy_pass http://upstream-server/health;
    }
}
```

#### NOTE
这里允许使用与常规 `location` 块中相同的指令,
但实际上只有内容处理器
(如 [js_content](https://cn.angie.software//angie/docs/installation/external-modules/http_js.md#js-content) 或 [autoindex](https://cn.angie.software//angie/docs/configuration/modules/http/http_autoindex.md#id3))
和变量处理器(如 [map](https://cn.angie.software//angie/docs/configuration/modules/http/http_map.md#id3)),
以及自身生成请求的指令
(如 `upstream_probe`)才会生效。

在其他 [请求处理阶段](https://cn.angie.software//angie/docs/configuration/processing.md#http-sessions) 操作的指令
(如 [limit_req](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#limit-req)、[auth_request](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_request.md#id3)、
[try_files](#try-files)、图像过滤器、XSLT 等)
在这里不起作用。

<a id="index-8"></a>

<a id="client-body-buffer-size"></a>

### client_body_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `client_body_buffer_size` size;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `client_body_buffer_size 8k|16k;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

设置读取客户端请求体的缓冲区大小。如果请求体大于缓冲区,则将整个请求体或仅其部分写入 [临时文件](#client-body-temp-path)。默认情况下,缓冲区大小等于两个内存页。在 x86、其他 32 位平台和 x86-64 上,这是 8K。在其他 64 位平台上,通常是 16K。

<a id="index-9"></a>

<a id="client-body-in-file-only"></a>

### client_body_in_file_only

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `client_body_in_file_only` `on` | `clean` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------------|
| 默认值                                                                                  | `client_body_in_file_only off;`                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                               |

确定是否将整个客户端请求体保存到文件中。此指令可在调试期间使用,或在使用 [$request_body_file](#v-request-body-file) 变量或 [Perl](https://cn.angie.software//angie/docs/configuration/modules/http/http_perl.md#http-perl) 模块的 [$r->request_body_file](https://cn.angie.software//angie/docs/configuration/modules/http/http_perl.md#p-r-request-body-file) 方法时使用。

| `on`    | 请求处理后不删除临时文件     |
|---------|------------------|
| `clean` | 允许删除请求处理后留下的临时文件 |

<a id="index-10"></a>

<a id="client-body-in-single-buffer"></a>

### client_body_in_single_buffer

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `client_body_in_single_buffer` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | `client_body_in_single_buffer off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                         |

确定是否将整个客户端请求体保存在单个缓冲区中。建议在使用 [$request_body](#v-request-body) 变量时使用此指令,以减少涉及的复制操作数量。

<a id="index-11"></a>

<a id="client-body-temp-path"></a>

### client_body_temp_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `client_body_temp_path` path [level1 [level2 [level3]]];                                                                                                             |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `client_body_temp_path client_body_temp;`<br/>(路径取决于 [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#paths) `--http-client-body-temp-path`) |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                                               |

定义用于存储客户端请求体临时文件的目录。在指定目录下最多可以使用三级子目录层次结构。例如,在以下配置中

```nginx
client_body_temp_path /spool/angie/client_temp 1 2;
```

临时文件的路径可能如下所示:

```nginx
/spool/angie/client_temp/7/45/00000123457
```

<a id="index-12"></a>

<a id="client-body-timeout"></a>

### client_body_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `client_body_timeout` time;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `client_body_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

定义读取客户端请求体的超时时间。超时仅针对两次连续读取操作之间的时间段设置,而不是针对整个请求体的传输。如果客户端在此时间内未传输任何内容,则请求将以 408 (Request Time-out) 错误终止。

<a id="index-13"></a>

<a id="client-header-buffer-size"></a>

### client_header_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `client_header_buffer_size` size;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `client_header_buffer_size 1k;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                        |

设置读取客户端请求头的缓冲区大小。对于大多数请求,1K 字节的缓冲区就足够了。但是,如果请求包含长 cookie,或来自 WAP 客户端,则可能无法容纳在 1K 中。如果请求行或请求头字段无法容纳在此缓冲区中,则会分配由 [large_client_header_buffers](#large-client-header-buffers) 指令配置的更大缓冲区。

如果在 [server](#server) 级别指定该指令,则可以使用默认服务器的值。详情请参阅 [虚拟服务器选择](https://cn.angie.software//angie/docs/configuration/processing.md#request-processing) 部分。

<a id="index-14"></a>

<a id="client-header-timeout"></a>

### client_header_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `client_header_timeout` time;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `client_header_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                    |

定义读取客户端请求头的超时时间。如果客户端在此时间内未传输整个请求头,则请求将以 408 (Request Time-out) 错误终止。

<a id="index-15"></a>

<a id="client-max-body-size"></a>

### client_max_body_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `client_max_body_size` size;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `client_max_body_size 1m;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

设置客户端请求体的最大允许大小。如果请求中的大小超过配置的值,则向客户端返回 413 (Request Entity Too Large) 错误。请注意,浏览器无法正确显示此错误。

| `0`   | 禁用检查客户端请求体大小   |
|-------|----------------|

<a id="index-16"></a>

<a id="connection-pool-size"></a>

### connection_pool_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `connection_pool_size` size;        |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `connection_pool_size 256` | `512;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

允许精确调整每个连接的内存分配。此指令对性能的影响很小,通常不应使用。默认情况下:

| `256` (字节)   | 在 32 位平台上   |
|--------------|-------------|
| `512` (字节)   | 在 64 位平台上   |

<a id="index-17"></a>

<a id="default-type"></a>

### default_type

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `default_type` mime-type;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `default_type text/plain;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

定义响应的默认 MIME 类型。文件扩展名到 MIME 类型的映射可以使用 [types](#types) 指令设置。

<a id="index-18"></a>

<a id="directio"></a>

### directio

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `directio` size | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `directio off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

在读取大于或等于指定大小的文件时,启用 `O_DIRECT` 标志(FreeBSD、Linux)、`F_NOCACHE` 标志(macOS)或 `directio()` 函数(Solaris)的使用。该指令会自动禁用给定请求的 [sendfile](#sendfile) 使用。建议用于提供大文件:

```nginx
directio 4m;
```

或在 Linux 上使用 [aio](#aio) 时。

<a id="index-19"></a>

<a id="directio-alignment"></a>

### directio_alignment

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `directio_alignment` size;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `directio_alignment 512;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

设置 [directio](#directio) 的对齐方式。在大多数情况下,512 字节对齐就足够了。但是,在 Linux 下使用 XFS 时,需要将其增加到 4K。

<a id="index-20"></a>

<a id="disable-symlinks"></a>

### disable_symlinks

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `disable_symlinks` `off`;<br/><br/>`disable_symlinks` `on` | `if_not_owner` [`from=`part];   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `disable_symlinks off;`                                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                       |

确定在打开文件时应如何处理符号链接:

| `off`          | 允许路径中的符号链接且不进行检查。这是默认行为。                                                                                                                                                                              |
|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `on`           | 如果路径的任何组成部分是符号链接,则拒绝访问该文件。                                                                                                                                                                            |
| `if_not_owner` | 如果路径的任何组成部分是符号链接,且该链接与其指向的对象具有不同的所有者,则拒绝访问该文件。                                                                                                                                                        |
| `from=`part    | 在检查符号链接时(参数 `on` 和 `if_not_owner`),通常会检查所有路径组成部分。可以通过额外指定 `from=part` 参数来跳过对路径初始部分中符号链接的检查。在这种情况下,仅从指定初始部分之后的路径组成部分开始检查符号链接。如果该值不是被检查路径的初始部分,则会完整检查路径,就像根本没有指定此参数一样。如果该值与文件名完全匹配,则不检查符号链接。参数值中可以使用变量。 |

示例:

```nginx
disable_symlinks on from=$document_root;
```

此指令仅在具有 `openat()` 和 `fstatat()` 接口的系统上可用。此类系统包括现代版本的 FreeBSD、Linux 和 Solaris。

#### WARNING
`on` 和 `if_not_owner` 参数会增加处理开销。

在不支持仅为搜索而打开目录的系统上,使用这些参数需要工作进程对所有被检查的目录具有读取权限。

#### NOTE
[AutoIndex](https://cn.angie.software//angie/docs/configuration/modules/http/http_autoindex.md#http-autoindex)、[Random Index](https://cn.angie.software//angie/docs/configuration/modules/http/http_random_index.md#http-random-index) 和 [DAV](https://cn.angie.software//angie/docs/configuration/modules/http/http_dav.md#http-dav) 模块目前忽略此指令。

<a id="index-21"></a>

<a id="early-hints"></a>

### early_hints

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `early_hints` string ...;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

定义将 "103 Early Hints" 响应传递给客户端的条件。如果字符串参数的至少一个值不为空且不等于 `0`,则将传递响应:

```nginx
map $http_sec_fetch_mode $early_hints {
    navigate $http2$http3;
}

server {
    ...
    location / {
        early_hints $early_hints;
        proxy_pass http://example.com;
    }
}
```

<a id="index-22"></a>

<a id="error-page"></a>

### error_page

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `error_page` code ... [=[response]] uri;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | —                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location     |

定义针对指定错误显示的 URI。uri 值可以使用变量。

示例:

```nginx
error_page 404             /404.html;
error_page 500 502 503 504 /50x.html;
```

这会导致内部重定向到指定的 uri,并将客户端请求方法更改为 "GET"(对于除 "GET" 和 "HEAD" 之外的所有方法)。

此外,可以使用类似 `=response` 的语法将响应代码更改为另一个代码,例如:

```nginx
error_page 404 =200 /empty.gif;
```

如果错误响应由代理服务器或 FastCGI/uwsgi/SCGI/gRPC 服务器处理,并且该服务器可能返回不同的响应代码(例如 200、302、401 或 404),则可以传递它返回的代码:

```nginx
error_page 404 = /404.php;
```

如果在内部重定向期间不需要更改 URI 和方法,可以将错误处理传递到命名的 `location`:

```nginx
location / {
  error_page 404 = @fallback;
}

location @fallback {
  proxy_pass http://backend;
}
```

#### NOTE
如果在处理 uri 期间发生错误,则会将最后发生的错误代码的响应返回给客户端。

也可以使用 URL 重定向进行错误处理:

```nginx
error_page 403      http://example.com/forbidden.html;
error_page 404 =301 http://example.com/notfound.html;
```

在这种情况下,默认情况下会向客户端返回响应代码 302。它只能更改为重定向响应代码之一(301、302、303、307 和 308)。

<a id="index-23"></a>

<a id="etag"></a>

### etag

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `etag` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | `etag on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

启用或禁用为静态资源自动生成 `ETag` 响应头字段。

<a id="index-24"></a>

<a id="d-http"></a>

### http

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http` { ... }   |
|--------------------------------------------------------------------------------------|------------------|
| 默认值                                                                                  | —                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main             |

提供配置文件上下文,在其中指定 HTTP 服务器指令。

<a id="index-25"></a>

<a id="if-modified-since"></a>

### if_modified_since

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `if_modified_since` `off` | `exact` | `before`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------|
| 默认值                                                                                  | `if_modified_since exact;`                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                            |

指定如何将响应的修改时间与 `If-Modified-Since` 请求头字段中的时间进行比较:

| `off`    | 响应始终被视为已修改                                 |
|----------|--------------------------------------------|
| `exact`  | 精确匹配                                       |
| `before` | 响应的修改时间小于或等于 `If-Modified-Since` 请求头字段中的时间 |

<a id="index-26"></a>

<a id="ignore-invalid-headers"></a>

### ignore_invalid_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ignore_invalid_headers` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `ignore_invalid_headers on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                             |

控制 Angie 是否忽略具有无效名称的头字段。有效名称由英文字母、数字、连字符组成,可能还包括下划线(由 [underscores_in_headers](#underscores-in-headers) 指令控制)。

如果在 [server](#server) 级别指定该指令,则可以使用默认服务器的值。

<a id="index-27"></a>

<a id="internal"></a>

### internal

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `internal;`   |
|--------------------------------------------------------------------------------------|---------------|
| 默认值                                                                                  | —             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location      |

指定给定的 `location` 只能用于内部请求。对于外部请求,将向客户端返回 404 (Not Found) 错误。内部请求包括以下几种:

* 由 [error_page](#error-page)、[index](https://cn.angie.software//angie/docs/configuration/modules/http/http_index.md#id3)、[random_index](https://cn.angie.software//angie/docs/configuration/modules/http/http_random_index.md#id3) 和 [try_files](#try-files) 指令重定向的请求;
* 由上游服务器的 `X-Accel-Redirect` 响应头字段重定向的请求;
* 由 [SSI](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssi.md#http-ssi) 模块的 `include virtual` 命令、[Addition](https://cn.angie.software//angie/docs/configuration/modules/http/http_addition.md#http-addition) 模块指令以及 [auth_request](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_request.md#id3) 和 [mirror](https://cn.angie.software//angie/docs/configuration/modules/http/http_mirror.md#id3) 指令形成的子请求;
* 由 [rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 指令更改的请求。

示例:

```nginx
error_page 404 /404.html;

location = /404.html {
  internal;
}
```

由于 404 错误是在带有 `internal` 指令的 `location` 上下文中返回的,外部请求可以重定向到不同的 location。这允许对外部和内部请求使用相同的前缀,但进行不同的处理,例如:

```nginx
location /path {

    internal;
    error_page 404 =@external;

    proxy_pass https://internal;
}

location @external {

    proxy_pass https://external;
}
```

在这里,外部请求 `GET /path` 将被代理到
`https://external/path`,而相同的内部请求将被代理到
`https://internal/path`。

#### NOTE
为了防止错误配置可能导致的循环,内部重定向的次数限制为十次。当达到此限制时,将返回 500 (Internal Server Error) 错误。在这种情况下,可以在错误日志中看到 `rewrite or internal redirection cycle` 消息。

<a id="index-28"></a>

<a id="keepalive-disable"></a>

### keepalive_disable

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `keepalive_disable` `none` | browser ...;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `keepalive_disable msie6;`                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

禁用与行为异常的浏览器的保持连接。browser 参数指定将受影响的浏览器。

| `none`   | 对所有浏览器启用保持连接                                        |
|----------|-----------------------------------------------------|
| `msie6`  | 一旦收到 POST 请求,禁用与旧版本 MSIE 的保持连接                      |
| `safari` | 禁用与 macOS 和类 macOS 操作系统上的 Safari 和类 Safari 浏览器的保持连接 |

<a id="index-29"></a>

<a id="keepalive-requests"></a>

### keepalive_requests

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `keepalive_requests` number;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `keepalive_requests 1000;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

设置通过一个保持连接可以处理的最大请求数。在达到最大请求数后,连接将被关闭。

定期关闭连接对于释放每个连接的内存分配是必要的。因此,使用过高的最大请求数可能会导致过度的内存使用,不建议这样做。

<a id="index-30"></a>

<a id="keepalive-time"></a>

### keepalive_time

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `keepalive_time` time;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | `keepalive_time 1h;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location   |

限制通过一个保持连接处理请求的最长时间。达到此时间后,连接将在后续请求处理完成后关闭。

<a id="index-31"></a>

<a id="keepalive-timeout"></a>

### keepalive_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `keepalive_timeout` timeout [header_timeout];   |
|--------------------------------------------------------------------------------------|-------------------------------------------------|
| 默认值                                                                                  | `keepalive_timeout 75s;`                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                          |

| timeout   | 设置保持连接的客户端连接在服务器端保持打开的超时时间   |
|-----------|------------------------------|
| `0`       | 禁用保持连接的客户端连接                 |

第二个  *可选* 参数在响应中设置 `Keep‑Alive: timeout=time` 头字段的值。这两个参数可以不同。

`Keep-Alive: timeout=time` 头字段被 Mozilla 和 Konqueror 识别。MSIE 会在大约 60 秒后自行关闭保持连接。

<a id="index-32"></a>

<a id="large-client-header-buffers"></a>

### large_client_header_buffers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `large_client_header_buffers` number size;   |
|--------------------------------------------------------------------------------------|----------------------------------------------|
| 默认值                                                                                  | `large_client_header_buffers 4 8k;`          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                                 |

设置用于读取大型客户端请求头的缓冲区的最大数量和大小。请求行不能超过一个缓冲区的大小,否则将向客户端返回 414 (Request-URI Too Large) 错误。请求头字段也不能超过一个缓冲区的大小,否则将向客户端返回 400 (Bad Request) 错误。缓冲区仅在需要时分配。默认情况下,缓冲区大小等于 8K 字节。如果在请求处理结束后连接转换为保持连接状态,这些缓冲区将被释放。

如果在 [server](#server) 级别指定该指令,则可以使用默认服务器的值。

<a id="index-33"></a>

<a id="limit-except"></a>

### limit_except

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_except` method1 [method2...] { ... };   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | —                                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location                                       |

限制 location 内允许的 HTTP 方法。method 参数可以是以下之一:`GET`、`HEAD`、`POST`、`PUT`、`DELETE`、`MKCOL`、`COPY`、`MOVE`、`OPTIONS`、`PROPFIND`、`PROPPATCH`、`LOCK`、`UNLOCK` 或 `PATCH`。允许 `GET` 方法也会使 `HEAD` 方法被允许。可以使用 [Access](https://cn.angie.software//angie/docs/configuration/modules/http/http_access.md#http-access) 和 [Auth Basic](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_basic.md#http-auth-basic) 模块指令限制对其他方法的访问:

```nginx
limit_except GET {
  allow 192.168.1.0/32;
  deny  all;
}
```

#### NOTE
此示例中的限制适用于 **除** `GET` 和 `HEAD` **之外** 的所有方法。

<a id="index-34"></a>

<a id="limit-rate"></a>

### limit_rate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_rate` rate;                     |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `limit_rate 0;`                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

限制向客户端传输响应的速率。速率以每秒字节数指定。零值禁用速率限制。限制是针对每个请求设置的,因此如果客户端同时打开两个连接,总速率将是指定限制的两倍。

参数值可以包含变量。在需要根据特定条件限制速率的情况下,这可能很有用:

```nginx
map $slow $rate {
  1     4k;
  2     8k;
}

limit_rate $rate;
```

速率限制也可以在 [$limit_rate](#v-limit-rate) 变量中设置,但不建议使用此方法:

```nginx
server {

  if ($slow) {
    set $limit_rate 4k;
  }

}
```

速率限制也可以在代理服务器响应的 `X-Accel-Limit-Rate` 头字段中设置。可以使用 [proxy_ignore_headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ignore-headers)、[fastcgi_ignore_headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-ignore-headers)、[uwsgi_ignore_headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-ignore-headers) 和 [scgi_ignore_headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-ignore-headers) 指令禁用此功能。

<a id="index-35"></a>

<a id="limit-rate-after"></a>

### limit_rate_after

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_rate_after` size;               |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `limit_rate_after 0;`                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

设置初始数量,在此之后向客户端传输响应的速率将受到限制。参数值可以包含变量。

示例:

```nginx
location /flv/ {
 flv;
 limit_rate_after 500k;
 limit_rate       50k;
}
```

<a id="index-36"></a>

<a id="lingering-close"></a>

### lingering_close

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `lingering_close` `on` | `always` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------------|
| 默认值                                                                                  | `lingering_close on;`                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                       |

控制 Angie 如何关闭客户端连接。

| `on`     | Angie 将 [等待](#lingering-timeout) 并 [处理](#lingering-time) 来自客户端的额外数据,然后完全关闭连接,但仅当启发式方法表明客户端可能正在发送更多数据时。   |
|----------|----------------------------------------------------------------------------------------------------------|
| `always` | Angie 将始终等待并处理额外的客户端数据。                                                                                  |
| `off`    | Angie 不会等待更多数据,将立即关闭连接。此行为会破坏协议,在正常情况下不应使用。                                                              |

要控制 HTTP/2 连接的关闭,必须在 [server](#server) 级别指定该指令。

<a id="index-37"></a>

<a id="lingering-time"></a>

### lingering_time

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `lingering_time` time;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | `lingering_time 30s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location   |

当 [lingering_close](#lingering-close) 生效时,此指令指定 Angie 处理(读取并忽略)来自客户端的额外数据的最长时间。在此之后,连接将被关闭,即使还有更多数据。

<a id="index-38"></a>

<a id="lingering-timeout"></a>

### lingering_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `lingering_timeout` time;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `lingering_timeout 5s;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

当 [lingering_close](#lingering-close) 生效时,此指令指定等待更多客户端数据到达的最长等待时间。如果在此时间内未收到数据,连接将被关闭。否则,数据将被读取并忽略,Angie 再次开始等待更多数据。"等待-读取-忽略"循环会重复,但不会超过 [lingering_time](#lingering-time) 指令指定的时间。

在优雅关闭期间,客户端保持连接仅在空闲时间至少达到 `lingering_timeout` 中指定的时间时才会关闭。

#### NOTE
在 nginx 中,类似的指令称为 [keepalive_min_timeout](https://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_min_timeout)。

<a id="index-39"></a>

<a id="listen"></a>

### listen

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `listen` address[:port] [`default_server`] [`ssl`] [http2 | `quic`] [`proxy_protocol`] [`setfib=`number] [`fastopen=`number] [`backlog=`number] [`rcvbuf=`size] [`sndbuf=`size] [`accept_filter=`filter] [`deferred`] [`bind`] [`ipv6only=``on` | `off`] [`reuseport`] [`so_keepalive=`on|off|[`keepidle`]:[`keepintvl`]:[`keepcnt`]];<br/><br/>`listen` port [`default_server`] [`ssl`] [http2 | `quic`] [`proxy_protocol`] [`setfib=`number] [`fastopen=`number] [`backlog=`number] [`rcvbuf=`size] [`sndbuf=`size] [`accept_filter=`filter] [`deferred`] [`bind`] [`ipv6only=``on` | `off`] [`reuseport`] [`so_keepalive=`on|off|[`keepidle`]:[`keepintvl`]:[`keepcnt`]];<br/><br/>`listen` unix:path [`default_server`] [`ssl`] [http2 | `quic`] [`proxy_protocol`] [`backlog=`number] [`rcvbuf=`size] [`sndbuf=`size] [`accept_filter=`filter] [`deferred`] [`bind`] [`so_keepalive=`on|off|[`keepidle`]:[`keepintvl`]:[`keepcnt`]];   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `listen *:80` | `*:8000;`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |

设置监听套接字的 address 和 port，或服务器接受请求的 UNIX 域套接字的路径。address 也可以是主机名，例如：

```nginx
listen 127.0.0.1:8000;
listen 127.0.0.1;
listen 8000;
listen *:8000;
listen localhost:8000;
```

IPv6 地址用方括号指定：

```nginx
listen [::]:8000;
listen [::1];
```

UNIX 域套接字使用 `unix:` 前缀指定：

```nginx
listen unix:/var/run/angie.sock;
```

可以同时指定 address 和 port，或仅指定 address 或仅指定 port。
当省略某些部分时，适用以下规则：

- 如果仅给出 address，则使用端口 80。
- 如果仅给出 port，
  Angie 将监听所有可用的 IPv4（以及 IPv6，如果已启用）接口。
  该端口的第一个 `server` 块
  将成为具有不匹配 `Host` 头的请求的默认服务器。
- 如果完全省略该指令，Angie 在以超级用户权限运行时使用 `*:80`，
  否则使用 `*:8000`。

| `default_server`   | 指定了此参数的服务器<br/>将成为给定 address:port 对的默认服务器<br/>（它们共同构成一个  *监听套接字*）。<br/><br/>如果没有带 `default_server` 参数的指令，<br/>该监听套接字的默认服务器<br/>将是配置中为该套接字提供服务的第一个服务器。                                                                               |
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `ssl`              | 表示在此监听套接字上接受的所有连接都应在 SSL 模式下工作。这允许为同时处理 HTTP 和 HTTPS 请求的服务器提供更 [紧凑的配置](https://cn.angie.software//angie/docs/configuration/ssl.md#compact-server)。                                                                                  |
| `http2`            | 配置端口接受 HTTP/2 连接。通常，为了使其工作，还应指定 `ssl` 参数，但 Angie 也可以配置为接受不带 SSL 的 HTTP/2 连接。<br/><br/>#### Deprecated<br/>自 1.2.0 版本弃用.<br/><br/>请改用 [http2](https://cn.angie.software//angie/docs/configuration/modules/http/http_v2.md#http2) 指令。 |
| `quic`             | 配置端口接受 QUIC 连接。<br/>要使用此选项，<br/>Angie 必须启用并配置 [HTTP3 模块](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#http-v3)。<br/>设置 `quic` 后，<br/>您还可以指定 `reuseport`<br/>以便可以使用多个工作进程。                            |
| `proxy_protocol`   | 表示在此监听套接字上接受的所有连接都应使用 PROXY 协议。                                                                                                                                                                                                     |

`listen` 指令还可以指定几个特定于套接字相关系统调用的附加参数。这些参数可以在任何 `listen` 指令中指定，但对于给定的监听套接字只能指定一次：

| `setfib=`number                                                    | 为监听套接字设置路由表 FIB（`SO_SETFIB` 选项）。目前仅在 FreeBSD 上有效。                                                                                                                                                                                                                                                                                                                                                                   |
|--------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fastopen=`number                                                  | 为监听套接字启用"TCP Fast Open"，并限制尚未完成三次握手的连接队列的最大长度。<br/><br/>#### WARNING<br/>除非服务器能够处理多次接收带有数据的相同 SYN 数据包，否则不要启用"TCP Fast Open"。                                                                                                                                                                                                                                                                                        |
| `backlog=`number                                                   | 设置 `listen()` 调用中的 `backlog` 参数，<br/>该参数限制待处理连接队列的最大长度。默认情况下，<br/>在 FreeBSD、DragonFly BSD 和 macOS 上 backlog 设置为 -1，<br/>在其他平台上设置为 511。                                                                                                                                                                                                                                                                              |
| `rcvbuf=`size                                                      | 为监听套接字设置接收缓冲区大小（`SO_RCVBUF` 选项）。                                                                                                                                                                                                                                                                                                                                                                                    |
| `sndbuf=`size                                                      | 为监听套接字设置发送缓冲区大小（`SO_SNDBUF` 选项）。                                                                                                                                                                                                                                                                                                                                                                                    |
| `accept_filter=`filter                                             | 为监听套接字设置接受过滤器的名称（`SO_ACCEPTFILTER` 选项），<br/>该过滤器在将传入连接传递给 `accept()` 之前对其进行过滤。<br/>这仅在 FreeBSD 和 NetBSD 5.0+ 上有效。<br/>可能的值为 `dataready` 和 `httpready`。                                                                                                                                                                                                                                                              |
| `deferred`                                                         | 指示在 Linux 上使用延迟 `accept()`<br/>（`TCP_DEFER_ACCEPT` 套接字选项）。                                                                                                                                                                                                                                                                                                                                                          |
| `bind`                                                             | 指示为给定的 address:port 对进行单独的 `bind()` 调用。<br/>这很有用，因为如果有多个具有相同端口但不同地址的 `listen`<br/>指令，并且其中一个 `listen` 指令监听给定 `port`<br/>的所有地址（`*:port`），Angie 将只 `bind()` 到<br/>`*:port`。应该注意的是，在这种情况下将进行 `getsockname()`<br/>系统调用以确定接受连接的地址。如果使用了 `setfib`、`fastopen`、<br/>`backlog`、`rcvbuf`、`sndbuf`、`accept_filter`、<br/>`deferred`、`ipv6only`、`reuseport` 或 `so_keepalive`<br/>参数，那么对于给定的 `address:port` 对将始终进行单独的 `bind()` 调用。 |
| `ipv6only=on` | `off`                                              | 确定（通过 `IPV6_V6ONLY` 套接字选项）<br/>监听通配符地址 [::] 的 IPv6 套接字是否只接受<br/>IPv6 连接或同时接受 IPv6 和 IPv4 连接。此参数<br/>默认开启。它只能在启动时设置一次。                                                                                                                                                                                                                                                                                               |
| `reuseport`                                                        | 指示为每个工作进程创建单独的监听套接字<br/>（在 Linux 3.9+ 和 DragonFly BSD 上使用 `SO_REUSEPORT` 套接字选项，<br/>或在 FreeBSD 12+ 上使用 `SO_REUSEPORT_LB`），<br/>允许内核在工作进程之间分配传入连接。目前仅在 Linux 3.9+、<br/>DragonFly BSD 和 FreeBSD 12+ 上有效。<br/><br/>#### WARNING<br/>不当使用 `reuseport` 参数<br/>可能会带来安全隐患。                                                                                                                                                 |
| `multipath`                                                        | 启用通过 [Multipath TCP](https://en.wikipedia.org/wiki/Multipath_TCP) (MPTCP) 接受连接，<br/>自 Linux 内核版本 5.6 起支持。<br/>此参数与 `quic` **不兼容**。                                                                                                                                                                                                                                                                                  |
| `so_keepalive=on` | `off` | [`keepidle`]:[`keepintvl`]:[`keepcnt`] | 为监听套接字配置"TCP keepalive"行为。<br/><br/>| `''`   | 如果省略此参数，则套接字将使用操作系统的设置   |<br/>|--------|--------------------------|<br/>| `on`   | 为套接字开启 `SO_KEEPALIVE` 选项 |<br/>| `off`  | 为套接字关闭 `SO_KEEPALIVE` 选项 |                                                                                                                                                                                                             |

某些操作系统支持使用 `TCP_KEEPIDLE`、`TCP_KEEPINTVL` 和
`TCP_KEEPCNT` 套接字选项在每个套接字的基础上设置 TCP keepalive 参数。在这些系统上（目前包括 Linux、NetBSD、
Dragonfly、FreeBSD 和 macOS），可以使用
`keepidle`、`keepintvl` 和 `keepcnt` 参数进行配置。可以省略一个或两个
参数，在这种情况下，相应套接字选项的系统默认设置将生效。例如，

```nginx
so_keepalive=30m::10
```

将空闲超时（`TCP_KEEPIDLE`）设置为 30 分钟，将探测间隔（`TCP_KEEPINTVL`）保留为系统默认值，并将探测次数（`TCP_KEEPCNT`）设置为 10 次探测。

示例：

```nginx
listen 127.0.0.1 default_server accept_filter=dataready backlog=1024;
```

<a id="index-40"></a>

<a id="location"></a>

### location

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `location` ([ = | ~ | ~\* | ^~ ] uri | `@name`)+ { ... }   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------|
| 默认值                                                                                  | —                                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server, location                                           |

根据请求 URI 是否匹配任何匹配表达式来设置配置。

匹配是针对规范化的 URI 执行的，在解码以"%XX"形式编码的文本、解析对相对路径组件"."和".."的引用，以及可能将两个或多个相邻斜杠 [压缩](#merge-slashes) 为单个斜杠之后进行。

`location` 可以由前缀字符串定义，也可以由正则表达式定义。

正则表达式使用前置修饰符指定：

| `~*`   | 不区分大小写的匹配   |
|--------|-------------|
| `~`    | 区分大小写的匹配    |

为了找到与请求匹配的 location，Angie 首先检查使用前缀字符串定义的 location（前缀 location）。在这些 location 中，选择并记住具有最长匹配前缀的 location。

#### NOTE
对于不区分大小写的操作系统（如 macOS），前缀字符串匹配不区分大小写。
但是，匹配仅限于单字节区域设置。

然后按照正则表达式在配置文件中出现的顺序检查正则表达式。在第一次匹配后停止搜索，并使用相应的配置。如果没有找到与正则表达式的匹配，则使用之前记住的前缀 location 的配置。

除了下面提到的一些例外情况，`location` 块可以嵌套。

正则表达式可以创建捕获组，这些捕获组稍后可以与其他指令一起使用。

如果最长匹配前缀 location 具有 `^~` 修饰符，则不检查正则表达式。

此外，使用 `=` 修饰符，可以定义 URI 和 location 的精确匹配。如果找到精确匹配，则搜索终止。例如，如果 `/` 请求频繁发生，定义 `location =/` 将加快这些请求的处理速度，因为搜索在第一次比较后终止。这样的 location 不能包含嵌套的 location，因为它定义了精确匹配。

示例：

```nginx
location =/ {
   #configuration A
}

location / {
   #configuration B
}

location /documents/ {
   #configuration C
}

location ^~/images/ {
   #configuration D
}

location ~*\.(gif|jpg|jpeg)$ {
   #configuration E
}
```

- `/` 请求将匹配配置 A，
- `/index.html` 请求将匹配配置 B，
- `/documents/document.html` 请求将匹配配置 C，
- `/images/1.gif` 请求将匹配配置 D，
- `/documents/1.jpg` 请求将匹配配置 E。

<a id="location-redirect"></a>

#### NOTE
如果前缀 `location` 以斜杠字符结尾且
[auto_redirect](#auto-redirect) 已启用,则会发生以下情况:
当请求到达时,其 URI 没有尾部斜杠
但在其他方面与前缀完全匹配,则会返回
代码为 301 的永久重定向,指向附加了斜杠的请求 URI。

对于精确 URI 匹配的 location,不会应用重定向:

```nginx
location /user/ {
  proxy_pass http://user.example.com;
}

location =/user {
  proxy_pass http://login.example.com;
}
```

<a id="named-location"></a>

`@` 前缀定义了一个  *命名* `location`。此类 location 不用于常规请求处理,
而是仅用于请求重定向。
它们不能嵌套,也不能包含嵌套 location。

<a id="combined-locations"></a>

#### 组合位置

多个定义相同配置块的 `location` 上下文可以通过在单个 `location` 中列出所有匹配表达式并使用单个配置块来压缩。这称为\*组合\* `location`。

假设前面示例中的配置 A、D 和 E 定义了相同的配置;您可以将它们组合成一个 `location`:

```nginx
location =/
         ^~/images/
         ~*\.(gif|jpg|jpeg)$ {
   # 通用配置
}
```

命名的 `location` 也可以是组合的一部分:

```nginx
location =/
         @named_combined {
   #...
}
```

#### WARNING
组合 `location` 的匹配表达式修饰符和表达式本身之间不能有空格。
正确形式: `location ~*/match(ing|es|er)$  *...*`。

#### NOTE
目前,组合 `location` 不能\*\*直接\*\*包含设置了 URI 的 `proxy_pass` 指令,也不能包含 `api` 或 `alias`。
但是,这些指令可以在嵌套于组合位置内的位置中使用。

<a id="index-41"></a>

<a id="log-not-found"></a>

### log_not_found

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `log_not_found` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `log_not_found on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

启用或禁用将未找到文件的错误记录到 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 中。

<a id="index-42"></a>

<a id="log-subrequest"></a>

### log_subrequest

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `log_subrequest` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `log_subrequest off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

启用或禁用将子请求记录到 [access_log](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#access-log) 中。

<a id="index-43"></a>

<a id="max-headers"></a>

### max_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `max_headers` number;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | `max_headers 1000;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server            |

设置允许的客户端请求头字段的最大数量。
如果超过此限制,将返回 `400 (Bad Request)` 错误。

当此指令在 [server](#server) 级别设置时,
可能会应用默认服务器的值。
有关更多信息,请参阅 [虚拟服务器选择](https://cn.angie.software//angie/docs/configuration/processing.md#virtual-server-selection) 部分。

<a id="index-44"></a>

<a id="max-ranges"></a>

### max_ranges

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `max_ranges` number;   |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | —                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

限制字节范围请求中允许的最大范围数量。超过限制的请求将被视为未指定字节范围。默认情况下,范围数量不受限制。

| `0`   | 完全禁用字节范围支持   |
|-------|--------------|

<a id="index-45"></a>

<a id="merge-slashes"></a>

### merge_slashes

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `merge_slashes` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `merge_slashes on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                    |

启用或禁用将 URI 中两个或多个相邻斜杠压缩为单个斜杠。

请注意,压缩对于正确匹配前缀字符串和正则表达式位置至关重要。如果没有压缩,:samp://scripts/one.php 请求将不会匹配

```nginx
location /scripts/ { }
```

并且可能被作为静态文件处理。因此它会被转换为 `/scripts/one.php`。

如果 URI 包含 base64 编码的名称,则可能需要关闭压缩,因为 base64 在内部使用 "/" 字符。但是,出于安全考虑,最好避免关闭压缩。

如果在 [server](#server) 级别指定该指令,则可以使用默认服务器的值。

<a id="index-46"></a>

<a id="msie-padding"></a>

### msie_padding

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `msie_padding` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `msie_padding on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

启用或禁用为状态大于 400 的 MSIE 客户端响应添加注释,以将响应大小增加到 512 字节。

<a id="index-47"></a>

<a id="msie-refresh"></a>

### msie_refresh

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `msie_refresh` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `msie_refresh off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

启用或禁用为 MSIE 客户端发出刷新而不是重定向。

<a id="index-48"></a>

<a id="open-file-cache"></a>

### open_file_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `open_file_cache` `off`;<br/><br/>`open_file_cache` `max=`N [`inactive=`time];   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------|
| 默认值                                                                                  | `open_file_cache off;`                                                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                           |

配置可以存储以下内容的缓存:

* 打开的文件描述符、它们的大小和修改时间;
* 目录存在性信息;
* 文件查找错误,例如"文件未找到"、"无读取权限"等。

错误缓存应通过 [open_file_cache_errors](#open-file-cache-errors) 指令单独启用。

| `max`      | 设置缓存中元素的最大数量;缓存溢出时,将删除最近最少使用 (LRU) 的元素           |
|------------|--------------------------------------------------|
| `inactive` | 定义一个时间,如果在此时间内未访问元素,则将其从缓存中删除;<br/><br/>默认为 60 秒 |
| `off`      | 禁用缓存                                             |

示例:

```nginx
open_file_cache          max=1000 inactive=20s;
open_file_cache_valid    30s;
open_file_cache_min_uses 2;
open_file_cache_errors   on;
```

<a id="index-49"></a>

<a id="open-file-cache-errors"></a>

### open_file_cache_errors

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `open_file_cache_errors` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `open_file_cache_errors off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

启用或禁用通过 [open_file_cache](#open-file-cache) 缓存文件查找错误。

<a id="index-50"></a>

<a id="open-file-cache-min-uses"></a>

### open_file_cache_min_uses

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `open_file_cache_min_uses` number;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `open_file_cache_min_uses 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

设置在 [open_file_cache](#open-file-cache) 指令的 `inactive` 参数配置的期间内,文件描述符在缓存中保持打开所需的最小文件访问次数。

<a id="index-51"></a>

<a id="open-file-cache-valid"></a>

### open_file_cache_valid

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `open_file_cache_valid` time;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `open_file_cache_valid 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

设置应验证 [open_file_cache](#open-file-cache) 元素的时间。

<a id="index-52"></a>

<a id="output-buffers"></a>

### output_buffers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `output_buffers` number size;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `output_buffers 2 32k;`         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

设置用于从磁盘读取响应的缓冲区数量和大小。

<a id="index-53"></a>

<a id="port-in-redirect"></a>

### port_in_redirect

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `port_in_redirect` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `port_in_redirect on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

启用或禁用在 Angie 发出的 [绝对](#absolute-redirect) 重定向中指定端口。

在重定向中使用主服务器名称由 [server_name_in_redirect](#server-name-in-redirect) 指令控制。

<a id="index-54"></a>

<a id="postpone-output"></a>

### postpone_output

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `postpone_output` size;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `postpone_output 1460;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location    |

如果可能,客户端数据的传输将被推迟,直到 Angie 至少有指定数量的字节要发送。

| `0`   | 禁用推迟数据传输   |
|-------|------------|

<a id="index-55"></a>

<a id="read-ahead"></a>

### read_ahead

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `read_ahead` size;     |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | `read_ahead 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

设置在处理文件时内核的预读取量。

在 Linux 上,使用 `posix_fadvise(0, 0, 0, POSIX_FADV_SEQUENTIAL)` 系统调用,因此 size 参数会被忽略。

在 FreeBSD 上,使用 `fcntl(O_READAHEAD,` size ) 系统调用,该调用从 FreeBSD 9.0-CURRENT 开始支持。

<a id="index-56"></a>

<a id="recursive-error-pages"></a>

### recursive_error_pages

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `recursive_error_pages` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `recursive_error_pages off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

启用或禁用使用 [error_page](#error-page) 指令进行多次重定向。此类重定向的次数是 [有限的](#internal)。

<a id="index-57"></a>

<a id="request-pool-size"></a>

### request_pool_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `request_pool_size` size;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `request_pool_size 4k;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                |

允许精确调整每个请求的内存分配。此指令对性能的影响很小,通常不应使用。

<a id="index-58"></a>

<a id="reset-timedout-connection"></a>

### reset_timedout_connection

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `reset_timedout_connection` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `reset_timedout_connection off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

启用或禁用重置超时连接和使用非标准代码 444 关闭的连接。重置按如下方式执行。在关闭套接字之前,为其设置 `SO_LINGER` 选项,超时值为 0。当套接字关闭时,TCP RST 被发送到客户端,并释放与此套接字关联的所有内存。这有助于避免长时间保持已关闭的套接字处于 FIN_WAIT1 状态且缓冲区已满。

#### NOTE
keep-alive 连接在超时时会正常关闭。

<a id="index-59"></a>

<a id="resolver"></a>

### resolver

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `resolver` address ... [`valid=`time] [`ipv4=``on` | `off`] [`ipv6=``on` | `off`] [`status_zone=`zone];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, upstream                                                                          |

配置用于将上游服务器名称解析为地址的名称服务器，例如：

```nginx
resolver 127.0.0.53 [::1]:5353;
```

地址可以指定为域名或 IP 地址，并可选端口。如果未指定端口，则使用端口 53。名称服务器以轮询方式查询。

#### NOTE
建议使用本地可信解析器，例如 `127.0.0.53` (systemd-resolved)，而非
公共解析器（如 `8.8.8.8`）。公共解析器会将 DNS 查询暴露给第三方，
并增加缓存投毒攻击的风险。

#### NOTE
该指令值会被嵌套块继承，
并可在其中根据需要覆盖。
在单个块内，该指令只能指定一次。
如果重复指定，则最后的定义生效。

默认情况下，Angie 使用响应的 TTL 值缓存答案。如果未指定 `resolver` 指令且不执行动态 DNS 查询（例如，在 [代理](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy) 中使用固定名称而不使用变量时），则不需要指定解析器：名称将在启动时使用系统解析器进行解析。可选的 `valid` 参数允许覆盖此行为：

| `valid`   |  *可选* 参数允许覆盖响应缓存的有效期   |
|-----------|------------------------|
```nginx
resolver 127.0.0.53 [::1]:5353 valid=30s;
```

默认情况下，Angie 在解析时会同时查找 IPv4 和 IPv6 地址。

| `ipv4=off`   | 禁用查找 IPv4 地址   |
|--------------|----------------|
| `ipv6=off`   | 禁用查找 IPv6 地址   |

<a id="resolver-status"></a>

| `status_zone`   |  *可选* 参数;<br/>启用在指定区域中收集 DNS 服务器请求和响应指标<br/>([/status/resolvers/<zone>](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-resolvers))   |
|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

<a id="index-60"></a>

<a id="resolver-timeout"></a>

### resolver_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `resolver_timeout` time;         |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `resolver_timeout 30s;`          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, upstream |

设置名称解析的超时时间,例如:

```nginx
resolver_timeout 5s;
```

<a id="index-61"></a>

<a id="error-log-user-tag"></a>

### error_log_user_tag

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `error_log_user_tag` value;          |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | —                                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, limit_except |

向错误日志记录添加特定于请求的标签。value 是一个 [复杂值](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax),
可以使用变量。该指令可以多次指定以添加多个标签。
标签可以在 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 中使用 `filter=tag:` 进行匹配。

<a id="index-62"></a>

<a id="root"></a>

### root

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `root` path;                           |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `root html;`                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

设置请求的根目录。例如,使用以下配置

```nginx
location /i/ {
  root /data/w3;
}
```

将发送 `/data/w3/i/top.gif` 文件来响应 `/i/top.gif` 请求。

path 值可以包含变量,但 [$document_root](#v-document-root) 和 [$realpath_root](#v-realpath-root) 除外。

文件路径的构造仅仅是将 URI 添加到 root 指令的值。如果需要修改 URI,应使用 [alias](#alias) 指令。

<a id="index-63"></a>

<a id="satisfy"></a>

### satisfy

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `satisfy` `all` | `any`;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `satisfy all;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

如果所有 (`all`) 或至少一个 (`any`) [Access](https://cn.angie.software//angie/docs/configuration/modules/http/http_access.md#http-access)、[Auth Basic](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_basic.md#http-auth-basic) 或 [Auth Request](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_request.md#http-auth-request) 模块允许访问,则允许访问。

```nginx
location / {
  satisfy any;

  allow 192.168.1.0/32;
  deny  all;

  auth_basic           "closed site";
  auth_basic_user_file conf/htpasswd;
}
```

<a id="index-64"></a>

<a id="send-lowat"></a>

### send_lowat

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `send_lowat` size;     |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | `send_lowat 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

如果该指令设置为非零值,Angie 将尝试通过使用 [kqueue](https://cn.angie.software//angie/docs/configuration/processing.md#kqueue) 方法的 `NOTE_LOWAT` 标志或 `SO_SNDLOWAT` 套接字选项来最小化客户端套接字上的发送操作次数。在这两种情况下都使用指定的大小。

<a id="index-65"></a>

<a id="send-timeout"></a>

### send_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `send_timeout` time;   |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | `send_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

设置向客户端传输响应的超时时间。超时仅在两次连续的写操作之间设置,而不是用于整个响应的传输。如果客户端在此时间内没有收到任何内容,连接将被关闭。

<a id="index-66"></a>

<a id="sendfile"></a>

### sendfile

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sendfile` `on` | `off`;               |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `sendfile off;`                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

启用或禁用 `sendfile()` 的使用。

[aio](#aio) 可用于为 `sendfile()` 预加载数据:

```nginx
location /video/ {
  sendfile       on;
  tcp_nopush     on;
  aio            on;
}
```

在此配置中,:samp:sendfile() 使用 `SF_NODISKIO` 标志调用,这使其不会在磁盘 I/O 上阻塞,而是报告数据不在内存中。然后 Angie 通过读取一个字节来启动异步数据加载。在第一次读取时,FreeBSD 内核将文件的前 128K 字节加载到内存中,但后续读取将仅以 16K 块加载数据。这可以使用 [read_ahead](#read-ahead) 指令更改。

<a id="index-67"></a>

<a id="sendfile-max-chunk"></a>

### sendfile_max_chunk

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sendfile_max_chunk` size;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `sendfile_max_chunk 2m;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

限制单次 `sendfile()` 调用中可以传输的数据量。如果没有限制,一个快速连接可能会完全占用工作进程。

<a id="index-68"></a>

<a id="server"></a>

### server

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server` { ... }   |
|--------------------------------------------------------------------------------------|--------------------|
| 默认值                                                                                  | —                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http               |

设置虚拟服务器的配置。基于 IP(基于 IP 地址)和基于名称(基于 "Host" 请求头字段)的虚拟服务器之间没有明确的分隔。相反,:ref:listen 指令描述应该接受服务器连接的所有地址和端口,:ref:server_name 指令列出所有服务器名称。

[Angie 如何处理请求](https://cn.angie.software//angie/docs/configuration/processing.md#request-processing) 文档中提供了配置示例。

<a id="index-69"></a>

<a id="server-name"></a>

### server_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server_name` name ...;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `server_name ""`;         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                    |

设置虚拟服务器的名称,例如:

```nginx
server {
  server_name example.com www.example.com;
}
```

第一个名称成为主服务器名称。

服务器名称可以包含星号("\*")来替换名称的第一部分或最后部分:

```nginx
server {
  server_name example.com *.example.com www.example.*;
}
```

这样的名称称为通配符名称。

上述提到的前两个名称可以合并为一个:

```nginx
server {
  server_name .example.com;
}
```

也可以在服务器名称中使用正则表达式,在名称前加上波浪号("~"):

```nginx
server {
  server_name ~^www\d+\.example\.com$ www.example.com;
}
```

正则表达式可以包含捕获,这些捕获可以在其他指令中使用:

```nginx
server {
  server_name ~^(www\.)?(.+)$;

  location / {
     root /sites/$2;
  }
}

server {
  server_name _;

  location / {
     root /sites/default;
  }
}
```

正则表达式中的命名捕获会创建变量,这些变量可以在其他指令中使用:

```nginx
server {
  server_name ~^(www\.)?(?<domain>.+)$;

  location / {
     root /sites/$domain;
  }
}

server {
  server_name _;

  location / {
     root /sites/default;
  }
}
```

#### NOTE
如果指令的参数设置为 [$hostname](#v-hostname),
则使用机器名称。

也可以指定空服务器名称:

```nginx
server {
    server_name www.example.com "";
}
```

按名称搜索虚拟服务器时,
如果名称匹配多个指定的变体
(例如,通配符名称和正则表达式都匹配),
将按以下优先级顺序选择第一个匹配的变体:

- 精确名称;
- 以星号开头的最长通配符名称,例如 `*.example.com`;
- 以星号结尾的最长通配符名称,例如 `mail.*`;
- 第一个匹配的正则表达式(按配置文件中出现的顺序),
  包括空名称。

#### WARNING
要在 TLS 中使用 `server_name`,
需要 TLS 连接终止。
此指令匹配 HTTP 请求中的 `Host`,
因此必须完成握手并解密连接。

<a id="index-70"></a>

<a id="server-name-in-redirect"></a>

### server_name_in_redirect

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server_name_in_redirect` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | `server_name_in_redirect off`;            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                    |

启用或禁用在 Angie 发出的 [绝对](#absolute-redirect) 重定向中使用由 [server_name](#server-name) 指令指定的主服务器名称。

| `on`   | 使用由 [server_name](#server-name) 指令设置的主服务器名称   |
|--------|-----------------------------------------------|
| `off`  | 使用 "Host" 请求头字段中的名称。如果此字段不存在,则使用服务器的 IP 地址。   |

重定向中端口的使用由 [port_in_redirect](#port-in-redirect) 指令控制。

<a id="index-71"></a>

<a id="server-names-hash-bucket-size"></a>

### server_names_hash_bucket_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server_names_hash_bucket_size` size;              |
|--------------------------------------------------------------------------------------|----------------------------------------------------|
| 默认值                                                                                  | `server_names_hash_bucket_size 32` | `64` | `128;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                               |

设置服务器名称哈希表的桶大小。默认值取决于处理器缓存行的大小。有关设置哈希表的详细信息在 [单独的文档](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes) 中提供。

<a id="index-72"></a>

<a id="server-names-hash-max-size"></a>

### server_names_hash_max_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server_names_hash_max_size` size;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `server_names_hash_max_size 512`;    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                 |

设置服务器名称哈希表的最大大小。有关设置哈希表的详细信息在 [单独的文档](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes) 中提供。

<a id="index-73"></a>

<a id="server-tokens"></a>

### server_tokens

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server_tokens` `on` | `off` | `build` | string;   |
|--------------------------------------------------------------------------------------|----------------------------------------------------|
| 默认值                                                                                  | `server_tokens on;`                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                             |

启用或禁用在错误页面和 `Server` 响应头字段中显示 Angie 版本。
`build` 参数启用显示构建名称,
该名称由相应的 [configure](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 参数设置,
与版本一起显示。

在 Angie PRO 中,如果指令设置了一个 string,该字符串也可以包含变量,
错误页面和 `Server` 响应头字段
将使用该字符串的变量插值后的值
来代替服务器名称、版本和构建名称。
空 string 将禁用 `Server` 字段的显示。

<a id="index-74"></a>

<a id="status-zone"></a>

### status_zone

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `status_zone` `off` | zone | key `zone=`zone[:number];   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------|
| 默认值                                                                                  | —                                                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server, location, if in location                         |

分配一个共享内存区域用于收集
[/status/http/location_zones/<zone>](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-location-zones) 和 [/status/http/server_zones/<zone>](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-server-zones) 指标。

多个 `server` 上下文
可以共享同一个区域进行数据收集;
特殊值 `off`
在嵌套的 `location` 块中禁用数据收集。

使用单个 zone 值的语法
将当前上下文的所有指标合并到一个共享内存区域中:

```nginx
server {

    listen 80;
    server_name *.example.com;

    status_zone single;
    # ...
}
```

替代语法允许设置以下参数:

| key         | 包含变量的字符串,其值决定区域中请求的分组。<br/>所有在替换后产生相同值的请求<br/>被分组在一起。如果替换产生空值,<br/>则不更新指标。   |
|-------------|------------------------------------------------------------------------------|
| zone        | 共享内存区域的名称。                                                                   |
| number (可选) | 用于收集指标的独立组的最大数量。<br/>如果新的 key 值超过此限制,它们将被分组到 `zone` 下。<br/><br/>默认值为 1。      |

在以下示例中,
所有共享相同 `$host` 值的请求
被分组到 `host_zone` 中。
为每个唯一的 `$host` 单独跟踪指标,
直到有 10 个指标组。
一旦达到此限制,
任何额外的 `$host` 值都将包含在 `host_zone` 下:

```nginx
server {

    listen 80;
    server_name *.example.com;

    status_zone $host zone=host_zone:10;

    location / {

        proxy_pass http://example.com;
    }
}
```

因此,生成的指标在 API 输出中按各个主机分割。

<a id="index-75"></a>

<a id="subrequest-output-buffer-size"></a>

### subrequest_output_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `subrequest_output_buffer_size` size;      |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | `subrequest_output_buffer_size 4k` | `8k;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                     |

设置用于存储子请求响应体的缓冲区大小。
默认情况下,缓冲区大小等于一个内存页。这是
`4K` 或 `8K`,取决于平台。它可以设置得更小。

#### NOTE
该指令仅适用于响应体保存在内存中的子请求。例如,这样的子请求由 [SSI](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssi.md#ssi-include-set) 创建。

<a id="index-76"></a>

<a id="tcp-nodelay"></a>

### tcp_nodelay

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `tcp_nodelay` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `tcp_nodelay on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

启用或禁用 `TCP_NODELAY` 选项的使用。当连接转换到保持活动状态时启用该选项。此外,它在 SSL 连接、无缓冲代理和 [WebSocket 代理](https://cn.angie.software//angie/docs/configuration/processing.md#websocket-proxy) 中也被启用。

<a id="index-77"></a>

<a id="tcp-nopush"></a>

### tcp_nopush

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `tcp_nopush` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `tcp_nopush off`;            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

启用或禁用在 FreeBSD 上使用 `TCP_NOPUSH` 套接字选项或在 Linux 上使用 `TCP_CORK` 套接字选项。这些选项仅在使用 [sendfile](#sendfile) 时启用。启用该选项允许

* 在 Linux 和 FreeBSD 4.\* 上,在一个数据包中发送响应头和文件的开头;
* 以完整数据包发送文件。

<a id="index-78"></a>

<a id="try-files"></a>

### try_files

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `try_files` file ... uri;<br/><br/>`try_files` file ... =code;   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server, location                                                 |

按指定顺序检查文件是否存在,并使用第一个找到的文件进行请求处理;处理在当前 location 的上下文中执行。文件的路径根据 file 参数按照 [root](#root) 和 [alias](#alias) 指令构造。可以通过在名称末尾指定斜杠来检查目录是否存在,例如 `$uri/`。如果没有找到任何文件,则进行内部重定向到最后一个参数中指定的 uri。

例如:

```nginx
location /images/ {
  try_files $uri /images/default.gif;
}

location = /images/default.gif {
  expires 30s;
}
```

最后一个参数可以是用于内部重定向的 URI、
对命名 location 的引用(例如 `@drupal`)、
或以 `=code` 形式的响应码(例如 `=404`):

```nginx
location / {
  try_files $uri $uri/index.html $uri.html =404;
}
```

应该注意的是,过度使用 `try_files` 指令
会增加系统调用的数量,
这可能会对性能产生负面影响。

因此,:samp:try_files 不应该用于复制
实际上是默认行为的行为,例如:

```nginx
location /bad_pattern {

      # try_files $uri $uri/ =404;  # 不推荐!
}
```

此外,:samp:try_files 不应该
仅用于在文件不存在时进行重定向。
原因是 `try_files` 指令有两个特点:

- 首先,它检查每个文件是否存在,
  这会增加系统负载。
- 其次,任何文件打开错误(例如 `打开文件过多`、
  权限错误)也被视为文件不存在并触发回退
  到备用处理程序,这可能会用成功响应掩盖 5xx 错误
  并导致错误的缓存。

因此,在实践中,可能会遇到以下有问题的结构:

```nginx
location / {
   try_files $uri $uri/ @drupal;  # 不推荐!
}
```

这里的问题是唯一的目的是重定向。
使用 `try_files` 会导致上述缺点,
但没有任何好处,
因为不需要检查文件是否存在。
正确的解决方案是使用 [error_page](#error-page) 指令,
它没有这些缺点:

```nginx
error_page 404 = @drupal;
log_not_found off;
```

相比之下,在以下示例中:

```nginx
location ~ \.php$ {
  try_files $uri @drupal;

  fastcgi_pass ...;

  fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;

#  ...
}
```

`try_files` 指令在将请求传递给同一块中配置的 FastCGI 服务器之前
检查 PHP 文件是否存在;
这里使用 `try_files` 是合理的。

### 代理到 Mongrel 时的使用示例:

```nginx
location / {
  try_files /system/maintenance.html
           $uri $uri/index.html $uri.html
           @mongrel;
}

location @mongrel {
  proxy_pass http://mongrel;
}
```

### 与 Drupal/FastCGI 一起使用的示例:

```nginx
location / {
  error_page 404 = @drupal;
}

location ~ \.php$ {
  try_files $uri @drupal;

  fastcgi_pass ...;

  fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;
  fastcgi_param SCRIPT_NAME     $fastcgi_script_name;
  fastcgi_param QUERY_STRING    $args;

#  ... 其他 fastcgi_param
}

location @drupal {
  fastcgi_pass ...;

  fastcgi_param SCRIPT_FILENAME /path/to/index.php;
  fastcgi_param SCRIPT_NAME     /index.php;
  fastcgi_param QUERY_STRING    q=$uri&$args;

#  ... 其他 fastcgi_param
}
```

### 与 Wordpress 和 Joomla 一起使用的示例:

```nginx
location / {
  error_page 404 = @wordpress;
}

location ~ \.php$ {
  try_files $uri @wordpress;

  fastcgi_pass ...;

  fastcgi_param SCRIPT_FILENAME /path/to$fastcgi_script_name;
#  ... 其他 fastcgi_param
}

location @wordpress {
  fastcgi_pass ...;

  fastcgi_param SCRIPT_FILENAME /path/to/index.php;
#  ... 其他 fastcgi_param
}
```

<a id="index-79"></a>

<a id="types"></a>

### types

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `types` { ... }                                            |
|--------------------------------------------------------------------------------------|------------------------------------------------------------|
| 默认值                                                                                  | `types  *text/html html; image/gif gif; image/jpeg jpg;* ` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                     |

将文件扩展名映射到响应的 MIME 类型。扩展名不区分大小写。多个扩展名可以映射到一个类型,例如:

```nginx
types {
  application/octet-stream bin exe dll;
  application/octet-stream deb;
  application/octet-stream dmg;
}
```

Angie 随附了一个足够完整的映射表,位于 `conf/mime.types` 文件中。

要使特定的 location 对所有响应返回 "application/octet-stream" MIME 类型,可以使用以下配置:

```nginx
location /download/ {
  types        { }
  default_type application/octet-stream;
}
```

<a id="index-80"></a>

<a id="types-hash-bucket-size"></a>

### types_hash_bucket_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `types_hash_bucket_size` size;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `types_hash_bucket_size 64;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

设置类型哈希表的桶大小。有关设置哈希表的详细信息,请参阅 [单独讨论](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes)。

<a id="index-81"></a>

<a id="types-hash-max-size"></a>

### types_hash_max_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `types_hash_max_size` size;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `types_hash_max_size 1024;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

设置类型哈希表的最大大小。有关设置哈希表的详细信息,请参阅 [单独讨论](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes)。

<a id="index-82"></a>

<a id="underscores-in-headers"></a>

### underscores_in_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `underscores_in_headers` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `underscores_in_headers off`;            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                             |

启用或禁用在客户端请求头字段中使用下划线。当禁用下划线的使用时,名称包含下划线的请求头字段将被标记为无效,并受 [ignore_invalid_headers](#ignore-invalid-headers) 指令的约束。

如果该指令在 [server](#server) 级别指定,则可以使用默认服务器的值。

<a id="index-83"></a>

<a id="variables-hash-bucket-size"></a>

### variables_hash_bucket_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `variables_hash_bucket_size` size;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `variables_hash_bucket_size 64;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                 |

设置变量哈希表的桶大小。有关设置哈希表的详细信息,请参阅 [单独讨论](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes)。

<a id="index-84"></a>

<a id="variables-hash-max-size"></a>

### variables_hash_max_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `variables_hash_max_size` size;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `variables_hash_max_size 2048;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                              |

设置变量哈希表的最大大小。有关设置哈希表的详细信息,请参阅 [单独讨论](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes)。

<a id="http-core-variables"></a>

## 内置变量

`http_core` 模块支持与 Apache Server 变量名称匹配的内置变量。首先,这些是表示客户端请求头字段的变量,例如 `$http_user_agent`、`$http_cookie` 等。此外,还有其他变量:

<a id="v-angie-version"></a>

### `$angie_version`

Angie 版本

<a id="v-arg"></a>

### `$arg_<name>`

请求行中的参数 name

<a id="v-args"></a>

### `$args`

请求行中的参数

<a id="v-binary-remote-addr"></a>

### `$binary_remote_addr`

二进制形式的客户端地址,对于 IPv4 地址,值的长度始终为 4 字节,对于 IPv6 地址则为 16 字节

<a id="v-body-bytes-sent"></a>

### `$body_bytes_sent`

发送给客户端的字节数,不包括响应头;此变量与 `mod_log_config` Apache 模块的 "%B" 参数兼容

<a id="v-bytes-sent"></a>

### `$bytes_sent`

发送给客户端的字节数

<a id="v-connection"></a>

### `$connection`

连接序列号

<a id="v-connection-requests"></a>

### `$connection_requests`

通过一个连接发出的当前请求数

<a id="v-connection-time"></a>

### `$connection_time`

连接时间(以秒为单位),具有毫秒分辨率

<a id="v-content-length"></a>

### `$content_length`

`Content-Length` 请求头字段

<a id="v-content-type"></a>

### `$content_type`

`Content-Type` 请求头字段

<a id="v-cookie"></a>

### `$cookie_<name>`

具有指定 name 的 cookie

<a id="v-document-root"></a>

### `$document_root`

当前请求的 [root](#root) 或 [alias](#alias) 指令的值

<a id="v-document-uri"></a>

### `$document_uri`

与 [$uri](#v-uri) 相同

<a id="v-host"></a>

### `$host`

按以下优先顺序:请求行中的主机名,或 "Host" 请求头字段中的主机名,或与请求匹配的服务器名称

<a id="v-hostname"></a>

### `$hostname`

主机名

<a id="v-http"></a>

### `$http_<name>`

任意请求头字段;变量名的最后部分对应于转换为小写并将破折号替换为下划线的字段名称

<a id="v-https"></a>

### `$https`

如果连接在 SSL 模式下运行,则为 `on`,否则为空字符串

<a id="v-is-args"></a>

### `$is_args`

如果请求行有参数,则为 `?`,否则为空字符串

<a id="v-is-request-port"></a>

### `$is_request_port`

如果 [$request_port](#v-request-port) 值非空,则为 `:`,否则为空字符串

<a id="v-limit-rate"></a>

### `$limit_rate`

设置此变量可启用响应速率限制;参见 [limit_rate](#limit-rate)

<a id="v-msec"></a>

### `$msec`

当前时间(以秒为单位),具有毫秒分辨率

<a id="v-nginx-version"></a>

### `$nginx_version`

nginx 版本

<a id="v-pid"></a>

### `$pid`

工作进程的 PID

<a id="v-pipe"></a>

### `$pipe`

如果请求是流水线式的,则为 `p`,否则为 `.`

<a id="v-proxy-protocol-addr"></a>

### `$proxy_protocol_addr`

来自 PROXY 协议头的客户端地址

必须先通过在 [listen](#listen) 指令中设置 `proxy_protocol` 参数来启用 PROXY 协议。

<a id="v-proxy-protocol-port"></a>

### `$proxy_protocol_port`

来自 PROXY 协议头的客户端端口

必须先通过在 [listen](#listen) 指令中设置 `proxy_protocol` 参数来启用 PROXY 协议。

<a id="v-proxy-protocol-server-addr"></a>

### `$proxy_protocol_server_addr`

来自 PROXY 协议头的服务器地址

必须先通过在 [listen](#listen) 指令中设置 `proxy_protocol` 参数来启用 PROXY 协议。

<a id="v-proxy-protocol-server-port"></a>

### `$proxy_protocol_server_port`

来自 PROXY 协议头的服务器端口

必须先通过在 [listen](#listen) 指令中设置 `proxy_protocol` 参数来启用 PROXY 协议。

<a id="v-proxy-protocol-tlv"></a>

### `$proxy_protocol_tlv_<name>`

来自 PROXY 协议头的 TLV。name 可以是 TLV 类型名称或其数值。在后一种情况下,该值为十六进制,应以 `0x` 为前缀:

```none
$proxy_protocol_tlv_alpn
$proxy_protocol_tlv_0x01
```

SSL TLV 也可以通过 TLV 类型名称或其数值访问,两者都以 `ssl_` 为前缀:

```none
$proxy_protocol_tlv_ssl_version
$proxy_protocol_tlv_ssl_0x21
```

支持以下 TLV 类型名称:

* `alpn (0x01)` - 连接上使用的上层协议
* `authority (0x02)` - 客户端传递的主机名值
* `unique_id (0x05)` - 唯一连接 ID
* `netns (0x30)` - 命名空间的名称
* `ssl (0x20)` - 二进制 SSL TLV 结构

支持以下 SSL TLV 类型名称:

* `ssl_version (0x21)` - 客户端连接中使用的 SSL 版本
* `ssl_cn (0x22)` - SSL 证书通用名称
* `ssl_cipher (0x23)` - 使用的密码名称
* `ssl_sig_alg (0x24)` - 用于签署证书的算法
* `ssl_key_alg (0x25)` - 公钥算法

此外,还支持以下特殊 SSL TLV 类型名称:

* `ssl_verify` - 客户端 SSL 证书验证结果:如果客户端提供了证书并且验证成功,则为 `0`,否则为非零值

必须先通过在 [listen](#listen) 指令中设置 `proxy_protocol` 参数来启用 PROXY 协议。

<a id="v-query-string"></a>

### `$query_string`

与 [$args](#v-args) 相同

<a id="v-realpath-root"></a>

### `$realpath_root`

与当前请求的 [root](#root) 或 [alias](#alias) 指令的值对应的绝对路径名,所有符号链接都解析为实际路径

<a id="v-remote-addr"></a>

### `$remote_addr`

客户端地址

<a id="v-remote-port"></a>

### `$remote_port`

客户端端口

<a id="v-remote-user"></a>

### `$remote_user`

通过基本身份验证提供的用户名

<a id="v-request"></a>

### `$request`

完整的原始请求行

<a id="v-request-body"></a>

### `$request_body`

请求体

当请求体被读取到 [内存缓冲区](#client-body-buffer-size) 时,该变量的值在由 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass)、[fastcgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-pass)、[uwsgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-pass) 和 [scgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-pass) 指令处理的位置中\*可用\*。

<a id="v-request-body-file"></a>

### `$request_body_file`

包含请求体的临时文件名

在处理结束时,需要删除该文件。要始终将请求体写入文件,请启用 [client_body_in_file_only](#client-body-in-file-only)。在代理请求或向 FastCGI/uwsgi/SCGI 服务器发送请求时传递临时文件名时,应分别使用 [proxy_pass_request_body off](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass-request-body)、[fastcgi_pass_request_body off](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-pass-request-body)、[uwsgi_pass_request_body off](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-pass-request-body) 或 [scgi_pass_request_body off](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-pass-request-body) 指令禁用请求体本身的传递。

<a id="v-request-completion"></a>

### `$request_completion`

如果请求已完成,则为 `OK`,否则为空字符串

<a id="v-request-filename"></a>

### `$request_filename`

当前请求的文件路径,基于 [root](#root) 或 [alias](#alias) 指令以及请求 URI

<a id="v-request-id"></a>

### `$request_id`

从 16 个随机字节生成的唯一请求标识符,以十六进制表示

<a id="v-request-length"></a>

### `$request_length`

请求长度(包括请求行、头和请求体)

<a id="v-request-method"></a>

### `$request_method`

请求方法,通常为 `GET` 或 `POST`

<a id="v-request-port"></a>

### `$request_port`

按以下优先顺序:请求 URI 的 authority 组件中的端口号,或 "Host" 请求头字段中的端口号

<a id="v-request-time"></a>

### `$request_time`

请求处理时间(以秒为单位),具有毫秒分辨率;从客户端读取第一个字节以来经过的时间

<a id="v-request-uri"></a>

### `$request_uri`

完整的原始请求 URI（带参数），在请求处理过程中不会被修改；参阅 [$uri](#v-uri) 了解当前（可能已重写的）URI

<a id="v-scheme"></a>

### `$scheme`

请求方案,"http" 或 "https"

<a id="v-sent-body"></a>

### `$sent_body`

子请求或外部请求的响应体(当其存储在内存中时);否则为空字符串

<a id="v-sent-http"></a>

### `$sent_http_<name>`

任意响应头字段;变量名的最后部分对应于转换为小写并将破折号替换为下划线的字段名称

<a id="v-sent-trailer"></a>

### `$sent_trailer_<name>`

在响应末尾发送的任意字段;变量名的最后部分对应于转换为小写并将破折号替换为下划线的字段名称

<a id="v-server-addr"></a>

### `$server_addr`

接受请求的服务器地址

计算此变量的值通常需要一次系统调用。为避免系统调用,:ref:listen 指令必须指定地址并使用 `bind` 参数。

<a id="v-server-name"></a>

### `$server_name`

接受请求的服务器名称

<a id="v-server-port"></a>

### `$server_port`

接受请求的服务器端口

<a id="v-server-protocol"></a>

### `$server_protocol`

请求协议,通常为 "HTTP/1.0"、"HTTP/1.1" 或 "HTTP/2.0"

<a id="v-status"></a>

### `$status`

响应状态

<a id="v-time-iso8601"></a>

### `$time_iso8601`

ISO 8601 标准格式的本地时间

<a id="v-time-local"></a>

### `$time_local`

通用日志格式的本地时间

<a id="v-tcpinfo"></a>

### `$tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, $tcpinfo_rcv_space`

关于客户端 TCP 连接的信息;在支持 `TCP_INFO` 套接字选项的系统上可用

<a id="v-uri"></a>

### `$uri`

请求中的当前 URI,已 [规范化](#location)

`$uri` 的值可能在请求处理过程中发生变化,例如在使用 [rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 进行重写时、执行内部重定向时,或在使用索引文件时。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_access.md

<!-- review: finished -->

<a id="http-access"></a>

# Access

该模块基于客户端 IP 地址或网络控制对服务器资源的访问。它允许对特定 IP 地址、IP 范围或 UNIX 域套接字允许或阻止访问,通过限制对网站或应用程序敏感区域的访问来增强安全性。

还可以通过使用 [Auth Basic](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_basic.md#http-auth-basic) 模块的密码或基于 [Auth Request](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_request.md#http-auth-request) 模块的子请求结果来限制访问。要同时应用地址和密码限制,请使用 [satisfy](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#satisfy) 指令。

<a id="configuration-example-3"></a>

## 配置示例

```nginx
location / {

    deny 192.168.1.1;
    allow 192.168.1.0/24;
    allow 10.1.1.0/16;
    allow 2001:0db8::/32;
    deny all;
}
```

规则按顺序评估,直到找到匹配项。在此示例中,仅允许 IPv4 网络 `10.1.1.0/16` 和 `192.168.1.0/24` (不包括特定地址 `192.168.1.1`)以及 IPv6 网络 `2001:0db8::/32` 访问。当有许多规则时,最好使用 [Geo](https://cn.angie.software//angie/docs/configuration/modules/http/http_geo.md#http-geo) 模块中的变量。

<a id="directives-3"></a>

## 指令

<a id="index-0"></a>

<a id="allow"></a>

### allow

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `allow` address | CIDR | `unix:` | `all`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | —                                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, limit_except        |

允许指定网络或地址的访问。
特殊值 `all` 表示所有客户端 IP 地址。

特殊值 `unix:` 允许任何 UNIX 域套接字的访问。

<a id="index-1"></a>

<a id="deny"></a>

### deny

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `deny` address | CIDR | `unix:` | `all`;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | —                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, limit_except       |

拒绝指定网络或地址的访问。
特殊值 `all` 表示所有客户端 IP 地址。

特殊值 `unix:` 拒绝任何 UNIX 域套接字的访问。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_acme.md

<a id="http-acme"></a>

# ACME

提供使用 [ACME 协议](https://datatracker.ietf.org/doc/html/rfc8555) 自动获取证书的功能。

在 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时,默认不会构建此模块;
需要使用 [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) `--with-http_acme_module` 启用它。
在来自 [我们的软件仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的包和镜像中,
该模块已包含在构建中。

<a id="configuration-example-4"></a>

## 配置示例

有关配置示例和设置说明,请参阅 [ACME 配置](https://cn.angie.software//angie/docs/configuration/acme.md#acme-config) 部分。

<a id="directives-4"></a>

## 指令

<a id="index-0"></a>

<a id="acme"></a>

### acme

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `acme` 名称;   |
|--------------------------------------------------------------------------------------|--------------|
| 默认值                                                                                  | —            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server       |

对于所有引用名为 名称 的 [ACME 客户端](#acme-client) 的 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 块中的 [server_name](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name) 指令指定的所有域名,
将获得单个证书;
如果 `server_name` 配置更改,
证书将更新以反映这些更改。

每次 Angie 启动时,都会为所有缺少有效证书的域名请求新证书。
可能的原因包括证书已过期、
文件丢失或不可读、
证书配置发生更改等。

#### NOTE
该指令仅控制证书请求中包含的域名,
并不影响证书可在何处使用。
任何 `server` 块都可以通过
[$acme_cert_<name>](#v-acme-cert-name) 变量
引用该证书,
无论该块是否包含 `acme` 指令。
从 `server` 块中移除 `acme`
仅会将该块的 [server_name](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name) 值
排除在后续的证书请求之外,
但不会阻止该块使用证书。

#### NOTE
目前,不支持使用正则表达式指定的域名,
这些域名将被忽略。

通配符域名仅在 `acme_client` 中设置了 `challenge=dns` 时才受支持。

此指令可以多次指定以加载不同类型的证书,例如 RSA 和 ECDSA:

```nginx
server {

    listen 443 ssl;
    server_name example.com www.example.com;

    ssl_certificate $acme_cert_rsa;
    ssl_certificate_key $acme_cert_key_rsa;

    ssl_certificate $acme_cert_ecdsa;
    ssl_certificate_key $acme_cert_key_ecdsa;

    acme rsa;
    acme ecdsa;
}
```

<a id="index-1"></a>

<a id="acme-client"></a>

### acme_client

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `acme_client` 名称 uri [`enabled=``on` | `off`] [`key_type=`类型] [`key_bits=`数字] [`email=`email] [`max_cert_size=`数字] [`renew_before_expiry=`时间] [`renew_on_load`] [`retry_after_error=`off|时间] [`challenge=``dns` | `http` | `alpn`] [`account_key=`文件];   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                                                                                                                                                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                                                                                                                                                                                                                                     |

定义一个全局唯一的名为 名称 的 ACME 客户端。
该名称必须对目录有效,
是一个包含变量的字符串,
并且将被视为不区分大小写。

第二个必需参数是 ACME 目录的 uri。
例如,Let's Encrypt ACME 目录的 URI [列出](https://letsencrypt.org/getting-started/)
为
[https://acme-v02.api.letsencrypt.org/directory](https://acme-v02.api.letsencrypt.org/directory)。

#### NOTE
ACME 模块会在 [client](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client) 上下文中添加一个名为 `location @acme` 的位置,
可用于配置对 ACME 目录的请求;
默认情况下,此 `location`
包含一个带有目录 uri 的 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass) 指令,
可以向其添加来自 [代理](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy) 模块的其他设置。

为了使此指令生效,
必须在相同上下文中配置 [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver)。

#### NOTE
出于测试目的,
证书颁发机构通常提供单独的测试环境。
例如,\`Let's Encrypt 的测试环境 <[https://letsencrypt.org/docs/staging-environment/](https://letsencrypt.org/docs/staging-environment/)>\`_
为
[https://acme-staging-v02.api.letsencrypt.org/directory](https://acme-staging-v02.api.letsencrypt.org/directory)。

| `enabled`             | 启用或禁用客户端证书的更新;<br/>例如,在不从配置中删除客户端的情况下临时暂停时,这很有用。<br/><br/>默认值:`on`。                                                                                                                                                                                                                                                                                                                                                                                                                                     |
|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `key_type`            | 证书的私钥算法类型。<br/>有效值:`rsa`,:samp:ecdsa。<br/><br/>默认值:`ecdsa`。                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `key_bits`            | 证书密钥的位数。<br/>默认值:`ecdsa` 为 256,:samp:rsa 为 2048。                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `email`               | 用于反馈的可选电子邮件地址;<br/>在 CA 服务器上创建账户时使用。                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `max_cert_size`       | 指定新证书文件的最大允许大小(以字节为单位),<br/>以在共享内存中为新证书保留空间;<br/>请求的域名越多,需要的空间越大。<br/>此参数不限制 ACME 服务器响应的大小;<br/>请使用 [acme_max_response_size](#acme-max-response-size) 来限制响应大小。<br/><br/>如果未设置该参数,Angie 会根据配置的域名列表计算大致大小,<br/>并将其用于共享内存分配。<br/><br/>如果启动时已存在证书但其大小超过 `max_cert_size` 值,<br/>则 `max_cert_size` 值会动态增加以匹配现有证书文件的大小。<br/><br/>如果更新过程中获得的证书大小超过 `max_cert_size`,<br/>则更新过程将失败并报错。<br/><br/>默认值:自动计算。                                                                                                         |
| `renew_before_expiry` | 证书到期前应开始更新的 [时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)。<br/><br/>默认值:`30d`。                                                                                                                                                                                                                                                                                                                                                                                         |
| `renew_on_load`       | 指定在每次加载配置时强制更新证书。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `retry_after_error`   | 在证书获取失败时重试前等待的 [时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)。<br/>如果设置为 `off`,<br/>客户端不会在失败后重试获取证书。<br/><br/>默认值:`2h`。                                                                                                                                                                                                                                                                                                                                                 |
| `challenge`           | 指定 ACME 客户端的验证类型。<br/>有效值:`dns`,:samp:http,:samp:alpn。<br/><br/>`alpn` 值启用 [TLS-ALPN-01](https://datatracker.ietf.org/doc/rfc8737/) 验证,需要<br/>Angie 使用支持 ALPN 的 OpenSSL 构建<br/>(不支持 BoringSSL 或 AWS-LC 构建)。<br/><br/>默认值:`http`。                                                                                                                                                                                                                                                                        |
| `account_key`         | 指定包含 PEM 格式密钥的文件的完整路径。<br/>如果您想使用现有账户密钥而不是自动生成一个,<br/>或者需要为多个 ACME 客户端使用同一个密钥,这很有用。<br/><br/>支持的密钥类型:<br/><br/>- RSA 密钥,长度为 8 的倍数,范围从 2048 到 8192 位。<br/>- ECDSA 密钥,长度为 256、384 或 521 位。<br/><br/>指定 `account_key` 参数时,<br/>应确保密钥文件确实存在。<br/>如果文件不存在,<br/>Angie 将尝试在指定路径创建它。<br/><br/>请注意,ACME 客户端的密钥是按照它们在配置中<br/>通过 [acme_client](#acme-client)、[acme](#id4) 或 [acme_hook](#acme-hook) 指令提及的顺序创建的。<br/>因此,如果一个客户端应该使用为另一个客户端创建的密钥,<br/>那么另一个客户端必须在配置中更早出现。<br/><br/>此外,密钥仅为设置了 `enabled=on` 参数的客户端创建。 |

<a id="index-2"></a>

<a id="acme-max-response-size"></a>

### acme_max_response_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `acme_max_response_size` 大小;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `acme_max_response_size 32k;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                           |

限制 ACME 服务器响应正文的最大大小。如果响应超过此限制,请求将失败并报错。
如果您看到类似 `too big subrequest response while sending to client` 的错误,请增加该值。

<a id="index-3"></a>

<a id="acme-client-path"></a>

### acme_client_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `acme_client_path` 路径;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | —                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                     |

覆盖用于存储证书和密钥的目录的 路径,
该路径在构建时由 [构建参数](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) `--http-acme-client-path` 设置。

<a id="index-4"></a>

<a id="acme-dns-port"></a>

### acme_dns_port

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `acme_dns_port` 端口 | ip[:端口] | [ip6][:端口];   |
|--------------------------------------------------------------------------------------|----------------------------------------------|
| 默认值                                                                                  | `acme_dns_port 53;`                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                         |

指定模块通过 UDP 处理来自 ACME 服务器的 DNS 查询所使用的端口。
端口号必须在 1 到 65535 之间。

也支持同时指定 IP 地址和可选端口。
可以使用 `ip:端口` 格式的 IPv4 地址
和 `[ip6]:端口` 格式的 IPv6 地址:

```nginx
acme_dns_port 8053;
acme_dns_port 127.0.0.1;
acme_dns_port [::1];
```

要使用 1024 或更低的端口号,
Angie 必须以 [超级用户](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 权限运行。

<a id="index-5"></a>

<a id="acme-http-port"></a>

### acme_http_port

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `acme_http_port` 端口 | ip[:端口] | [ip6][:端口];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | `acme_http_port 80;`                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                          |

指定模块用于处理 HTTP ACME 验证请求的端口。
端口号必须在 1 到 65535 之间。

也支持同时指定 IP 地址和可选端口。
可以使用 `ip:端口` 格式的 IPv4 地址
和 `[ip6]:端口` 格式的 IPv6 地址:

```nginx
acme_http_port 8080;
acme_http_port 127.0.0.1;
acme_http_port [::1];
```

如果没有服务器配置为监听指定的地址和端口,
模块会为 HTTP 验证创建专用监听器。

要使用 1024 或更低的端口号,
Angie 必须以 [超级用户](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 权限运行。

<a id="index-6"></a>

<a id="acme-hook"></a>

### acme_hook

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `acme_hook` 名称 [uri];   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | —                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location                |

为由 名称 指定的 [ACME 客户端](#acme-client)
启用基于钩子的域名验证。
当证书签发或续订需要进行域名验证时,
Angie 会向放置该指令的命名 `location`
生成一个内部请求。
请求的处理方式完全取决于同一 `location`
中配置的其他指令,
例如 [fastcgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-pass)、[proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass),
或任何其他请求处理程序。

| 名称   | 由该钩子处理域名验证的<br/>[ACME 客户端](#acme-client) 的名称。   |
|------|-------------------------------------------------|
| uri  | 包含变量的字符串;<br/>指定钩子调用的请求 URI。<br/><br/>默认值:`/`。  |

例如,以下配置将 [hook 变量](#http-acme-variables) 的值
通过请求 URI 传递给 FastCGI 应用程序:

```nginx
acme_hook example uri=/acme_hook/$acme_hook_name?domain=$acme_hook_domain&key=$acme_hook_keyauth;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_pass ...;
```

<a id="http-acme-variables"></a>

## 内置变量

<a id="v-acme-cert-name"></a>

### `$acme_cert_<名称>`

由此 名称 的客户端获得的最后一个证书文件(如果有)的内容。

<a id="v-acme-cert-key-name"></a>

### `$acme_cert_key_<名称>`

此 名称 的客户端使用的证书密钥文件的内容。

#### NOTE
证书文件仅在 ACME 客户端获得至少一个证书后可用,
而密钥文件在启动后立即可用。

<a id="v-acme-hook-challenge"></a>

### `$acme_hook_challenge`

验证类型。可能的值:`dns`,:samp:http,:samp:alpn。

<a id="v-acme-hook-client"></a>

### `$acme_hook_client`

发起请求的 ACME 客户端的名称。

<a id="v-acme-hook-domain"></a>

### `$acme_hook_domain`

被验证的域名。
如果是通配符域名,将不带 `*.` 前缀传递。

<a id="v-acme-hook-keyauth"></a>

### `$acme_hook_keyauth`

授权字符串:

- 在 DNS 验证中,用作 TXT 记录的值,
  记录名称格式为 `_acme-challenge. + $acme_hook_domain + .`。
- 在 HTTP 验证中,此字符串应用作
  ACME 服务器请求的响应内容。

<a id="v-acme-hook-name"></a>

### `$acme_hook_name`

钩子名称。对于不同类型的验证,它可能有不同的值和含义:

| 值               | DNS 验证中的含义               | HTTP 验证中的含义                             |
|-----------------|--------------------------|-----------------------------------------|
| `add` (添加钩子)    | 需要在 DNS 配置中添加相应的 TXT 记录。 | 需要准备对相应 HTTP 请求的响应。                     |
| `remove` (移除钩子) | 可以从 DNS 配置中删除 TXT 记录。    | 此 HTTP 请求不再相关;<br/>可以删除先前创建的包含授权字符串的文件。 |

<a id="v-acme-hook-token"></a>

### `$acme_hook_token`

验证令牌。
在 HTTP 验证中,用作请求的文件名:
`/.well-known/acme-challenge/` + `$acme_hook_token`。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_addition.md

<!-- review: finished -->

<a id="http-addition"></a>

# Addition

该模块是一个过滤器，用于在响应之前和之后添加文本。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，
该模块默认不被构建；
它需要通过
`--with-http_addition_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 来启用。

在来自 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的包和镜像中，
该模块已包含在构建中。

<a id="configuration-example-5"></a>

## 配置示例

```nginx
location / {
    add_before_body /before_action;
    add_after_body  /after_action;
}
```

<a id="directives-5"></a>

## 指令

<a id="index-0"></a>

<a id="add-before-body"></a>

### add_before_body

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `add_before_body` uri;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | —                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location   |

在响应体之前添加处理给定子请求返回的文本。参数为空字符串 (`""`) 则取消继承自先前配置级别的添加。

<a id="index-1"></a>

<a id="add-after-body"></a>

### add_after_body

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `add_after_body` uri;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | —                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location  |

在响应体之后添加处理给定子请求返回的文本。参数为空字符串 (`""`) 则取消继承自先前配置级别的添加。

<a id="index-2"></a>

<a id="addition-types"></a>

### addition_types

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `addition_types` mime-type ...;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `addition_types text/html;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

允许在具有指定 MIME 类型的响应中添加文本，除了 "text/html" 之外。特殊值 "\*" 匹配任何 MIME 类型。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_api.md

<a id="http-api"></a>

# API

`API` 模块实现了一个 HTTP RESTful 接口,用于以 JSON 格式获取 Web 服务器的基本信息,以及关于客户端连接、共享内存区域、DNS 查询、HTTP 请求、HTTP 响应缓存、[stream](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#stream-core) 模块会话,以及 [limit_conn http](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_conn.md#http-limit-conn)、[limit_conn stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_limit_conn.md#stream-limit-conn)、[limit_req](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_req.md#http-limit-req) 和 [http upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块区域的 [统计信息](#metrics)。

该接口接受 `GET` 和 `HEAD` HTTP 方法;
使用其他方法的请求将导致错误:

```json
{
    "error": "MethodNotAllowed",
    "description": "The POST method is not allowed for the requested API element \"/\"."
}
```

在 Angie PRO 中,此接口包含一个 [动态配置](#api-config) 部分,允许在不重新加载配置或重启的情况下更改设置;目前,可以配置 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 中的各个服务器。

<a id="directives-6"></a>

## 指令

<a id="index-0"></a>

<a id="a-api"></a>

### api

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `api` path;   |
|--------------------------------------------------------------------------------------|---------------|
| 默认值                                                                                  | —             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location      |

在 `location` 中启用 HTTP RESTful 接口。

path 参数是必需的。与 [alias](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#alias) 指令类似,它设置用于替换 `location` 中指定路径的路径,但是是在 API 树上而不是文件系统上。

如果在前缀 `location` 中指定:

```nginx
location /stats/ {
    api /status/http/server_zones/;
}
```

请求 URI 中与前缀 /stats/ 匹配的部分将被替换为 path 参数中指定的路径:/status/http/server_zones/。例如,对 /stats/foo/ 的请求将访问 API 元素 `/status/http/server_zones/foo/`。

允许使用变量:api /status/$module/server_zones/$name/ 以及在正则表达式 location 中使用:

```nginx
location ~^/api/([^/]+)/(.*)$ {
    api /status/http/$1_zones/$2;
}
```

这里 path 参数定义了 API 元素的完整路径;
因此,从对 `/api/location/data/` 的请求中将提取以下变量:

```console
$1 = "location"
$2 = "data/"
```

最终请求将是 `/status/http/location_zones/data/`。

#### NOTE
在 Angie PRO 中,您可以分离 [动态配置 API](#api-config) 和反映当前状态的不可变 [状态 API](#metrics):

```nginx
location /config/ {
    api /config/;
}

location /status/ {
    api /status/;
}
```

path 参数还允许控制 API 访问:

```nginx
location /status/ {
    api /status/;

    allow 127.0.0.1;
    deny  all;
}
```

或者:

```nginx
location /blog/requests/ {
    api /status/http/server_zones/blog/requests/;

    auth_basic           "blog";
    auth_basic_user_file conf/htpasswd;
}
```

#### NOTE
如果 `api` 放置在前缀带有尾部斜杠的 `location` 中(例如,:samp:location /name/),并且 [auto_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#auto-redirect) 指令设置为 `default`,则不带尾部斜杠的请求将被重定向(`/name -> /name/`)。

<a id="index-1"></a>

<a id="a-api-config-files"></a>

### api_config_files

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `api_config_files` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | off                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location                           |

启用或禁用向 [/status/angie/](#status-angie) API 部分添加 `config_files` 对象,该对象列出服务器实例当前加载的所有 Angie 配置文件的内容。例如,使用此配置:

```nginx
location /status/ {
    api /status/;
    api_config_files on;
}
```

对 `/status/angie/` 的请求返回大致如下内容:

```json
{
    "version":"|version|",
    "address":"192.168.16.5",
    "generation":1,
    "load_time":"|sampledateshort|T12:58:39.789Z",
    "config_files": {
        "/etc/angie/angie.conf": "...",
        "/etc/angie/mime.types": "..."
    }
}
```

默认情况下,输出被禁用,因为配置文件可能包含特别敏感的机密信息。

<a id="metrics"></a>

## 指标

Angie 在 `/status/` API 部分发布使用统计信息;您可以通过设置适当的 `location` 来开放访问权限。完全访问:

```nginx
location /status/ {
    api /status/;
}
```

部分访问的示例,如上所示:

```nginx
location /stats/ {
    api /status/http/server_zones/;
}
```

<a id="example-configuration"></a>

### 配置示例

配置包含 `location /status/`、`resolver`、`upstream` 中的 `http`、`http server`、`location`、`cache`、`http` 中的 `limit_conn` 和 `limit_req` 区域：

```nginx
http {

    resolver 127.0.0.53 status_zone=resolver_zone;
    proxy_cache_path /var/cache/angie/cache keys_zone=cache_zone:2m;
    limit_conn_zone $binary_remote_addr zone=limit_conn_zone:10m;
    limit_req_zone $binary_remote_addr zone=limit_req_zone:10m rate=1r/s;

    upstream upstream {
        zone upstream 256k;
        server backend.example.com service=_example._tcp resolve max_conns=5;
       keepalive 4;
    }

    server {
        server_name www.example.com;
        listen 443 ssl;

        status_zone http_server_zone;
        proxy_cache cache_zone;
        proxy_cache_valid 200 10m;

        access_log /var/log/access.log main;

        location / {
            root /usr/share/angie/html;
            status_zone location_zone;
            limit_conn limit_conn_zone 1;
            limit_req zone=limit_req_zone burst=5;
        }
        location /status/ {
            api /status/;

            allow 127.0.0.1;
            deny all;
        }

    }
}
```

响应请求 `curl https://www.example.com/status/`，Angie 返回：

### JSON 树

```json
{
    "angie": {
        "version":"|version|",
        "address":"192.168.16.5",
        "generation":1,
        "load_time":"|sampledateshort|T12:58:39.789Z"
    },

    "connections": {
        "accepted":2257,
        "dropped":0,
        "active":3,
        "idle":1
    },

    "slabs": {
        "cache_zone": {
            "pages": {
                "used":2,
                "free":506
            },

            "slots": {
                "64": {
                    "used":1,
                    "free":63,
                    "reqs":1,
                    "fails":0
                },

                "512": {
                    "used":1,
                    "free":7,
                    "reqs":1,
                    "fails":0
                }
            }
        },

        "limit_conn_zone": {
            "pages": {
                "used":2,
                "free":2542
            },

            "slots": {
                "64": {
                    "used":1,
                    "free":63,
                    "reqs":74,
                    "fails":0
                },

                "128": {
                    "used":1,
                    "free":31,
                    "reqs":1,
                    "fails":0
                }
            }
        },

        "limit_req_zone": {
            "pages": {
                "used":2,
                "free":2542
            },

            "slots": {
                "64": {
                    "used":1,
                    "free":63,
                    "reqs":1,
                    "fails":0
                },

                "128": {
                    "used":2,
                    "free":30,
                    "reqs":3,
                    "fails":0
                }
            }
        }
    },

    "http": {
        "server_zones": {
            "http_server_zone": {
                "ssl": {
                    "handshaked":4174,
                    "reuses":0,
                    "timedout":0,
                    "failed":0
                },

                "requests": {
                    "total":4327,
                    "processing":0,
                    "discarded":8
                },

                "responses": {
                    "200":4305,
                    "302":12,
                    "404":4
                },

                "data": {
                    "received":733955,
                    "sent":59207757
                }
            }
        },

        "location_zones": {
            "location_zone": {
                "requests": {
                    "total":4158,
                    "discarded":0
                },

                "responses": {
                    "200":4157,
                    "304":1
                },

                "data": {
                    "received":538200,
                    "sent":177606236
                }
            }
        },
        "caches": {
            "cache_zone": {
                "size":0,
                "cold":false,
                "hit": {
                    "responses":0,
                    "bytes":0
                },

                "stale": {
                    "responses":0,
                    "bytes":0
                },

                "updating": {
                    "responses":0,
                    "bytes":0
                },

                "revalidated": {
                    "responses":0,
                    "bytes":0
                },

                "miss": {
                    "responses":0,
                    "bytes":0,
                    "responses_written":0,
                    "bytes_written":0
                },

                "expired": {
                    "responses":0,
                    "bytes":0,
                    "responses_written":0,
                    "bytes_written":0
                },

                "bypass": {
                    "responses":0,
                    "bytes":0,
                    "responses_written":0,
                    "bytes_written":0
                }
            }
        },

        "limit_conns": {
            "limit_conn_zone": {
                "passed":73,
                "skipped":0,
                "rejected":0,
                "exhausted":0
            }
        },

        "limit_reqs": {
            "limit_req_zone": {
                "passed":54816,
                "skipped":0,
                "delayed":65,
                "rejected":26,
                "exhausted":0
            }
        },

        "upstreams": {
            "upstream": {
                "peers": {
                    "192.168.16.4:80": {
                        "server":"backend.example.com",
                        "service":"_example._tcp",
                        "backup":false,
                        "weight":5,
                        "state":"up",
                        "selected": {
                            "current":2,
                            "total":232
                        },

                        "max_conns":5,
                        "responses": {
                            "200":222,
                            "302":12
                        },

                        "data": {
                            "sent":543866,
                            "received":27349934
                        },

                        "health": {
                            "fails":0,
                            "unavailable":0,
                            "downtime":0
                        },

                        "sid":"<server_id>"
                    }
                },

                "keepalive":2
            }
        }
    },

    "resolvers": {
        "resolver_zone": {
            "queries": {
                "name":442,
                "srv":2,
                "addr":0
            },

            "responses": {
                "success":440,
                "timedout":1,
                "format_error":0,
                "server_failure":1,
                "not_found":1,
                "unimplemented":0,
                "refused":1,
                "other":0
            }
        }
    }
}
```

可以通过构造适当的请求，按单个 JSON 分支请求一组指标。例如：

```console
$ curl https://www.example.com/status/angie
$ curl https://www.example.com/status/connections
$ curl https://www.example.com/status/slabs
$ curl https://www.example.com/status/slabs/<zone>/slots
$ curl https://www.example.com/status/slabs/<zone>/slots/64
$ curl https://www.example.com/status/http/
$ curl https://www.example.com/status/http/acme_clients
$ curl https://www.example.com/status/http/acme_clients/<client>
$ curl https://www.example.com/status/http/metric_zones
$ curl https://www.example.com/status/http/metric_zones/<zone>/metrics
$ curl https://www.example.com/status/http/server_zones
$ curl https://www.example.com/status/http/server_zones/<http_server_zone>
$ curl https://www.example.com/status/http/server_zones/<http_server_zone>/ssl
```

<a id="api-date-format"></a>

#### NOTE
默认情况下，该模块使用 ISO 8601 格式字符串表示日期；
如需改用整数 UNIX 纪元格式，
请在查询字符串中添加 `date=epoch` 参数：

```console
$ curl https://www.example.com/status/angie/load_time

  "2024-04-01T00:59:59+01:00"

$ curl https://www.example.com/status/angie/load_time?date=epoch

  1711929599
```

<a id="server-status"></a>

### 服务器状态

<a id="status-angie"></a>

#### `/status/angie`

```json
{
    "version": "|version|",
    "build_time": "|sampledateshort|T16:05:43.805Z",
    "address": "192.168.16.5",
    "generation": 1,
    "load_time": "|sampledateshort|T16:15:43.805Z"
    "config_files": {
        "/etc/angie/angie.conf": "...",
        "/etc/angie/mime.types": "..."
    }
}
```

| `version`      | 字符串；正在运行的 Angie Web 服务器的版本                                                                                                                                                                                                                                                                                  |
|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `build`        | 字符串；编译期间指定的特定构建名称                                                                                                                                                                                                                                                                                           |
| `build_time`   | 字符串；Angie 可执行文件的构建时间，<br/>采用 [日期](#api-date-format) 格式                                                                                                                                                                                                                                                      |
| `address`      | 字符串；接受 API 请求的服务器地址                                                                                                                                                                                                                                                                                         |
| `generation`   | 数字；自上次启动以来配置重新加载的总次数                                                                                                                                                                                                                                                                                        |
| `load_time`    | 字符串；上次配置重新加载的时间，<br/>采用 [日期](#api-date-format) 格式；<br/>字符串值具有毫秒精度                                                                                                                                                                                                                                           |
| `config_files` | 对象；其成员是服务器实例当前加载的所有 Angie 配置文件的绝对路径名，<br/>其值是文件内容的字符串表示，<br/>例如：<br/><br/>```json<br/>{<br/>    "/etc/angie/angie.conf": "server {\n  listen 80;\n  # ...\n\n}\n"<br/>}<br/>```<br/><br/>#### WARNING<br/>`config_files` 对象仅在启用<br/>[api_config_files](#a-api-config-files)<br/>指令时才在 `/status/angie/` 中可用。 |

<a id="status-angie-license"></a>

#### `/status/angie/license` (PRO)

```json
{
    "path": "/etc/angie/license.pem",
    "status": "valid",
    "owner": "Example Corp",
    "days_left": 30,
    "since": "2024-01-01",
    "until": "2025-01-01",
    "limits": {
        "worker_processes": 16,
        "worker_connections": 65535
    }
}
```

| `path`      | 字符串；许可证文件的完整路径                                                           |
|-------------|--------------------------------------------------------------------------|
| `status`    | 字符串；许可证状态：`missing`、`invalid`、`valid`、<br/>`grace`、`expired` 或 `pending` |
| `owner`     | 字符串；来自证书主题的许可证所有者                                                        |
| `days_left` | 数字；许可证状态变更前的剩余天数。负值表示<br/>许可证已过期，该值为过期后的天数                               |
| `since`     | 字符串；许可证有效期开始日期                                                           |
| `until`     | 字符串；许可证有效期结束日期                                                           |
| `limits`    | 对象；当前实例的许可限制                                                             |

<a id="api-status-connections"></a>

### 连接

<a id="samp-status-connections"></a>

#### `/status/connections`

```json
{
  "accepted": 2257,
  "dropped": 0,
  "active": 3,
  "idle": 1
}
```

| `accepted`   | 数字；已接受的客户端连接总数   |
|--------------|------------------|
| `dropped`    | 数字；已丢弃的客户端连接总数   |
| `active`     | 数字；当前活动的客户端连接数   |
| `idle`       | 数字；当前空闲的客户端连接数   |

<a id="shared-memory-zones-with-slab-allocation"></a>

### 使用 slab 分配的共享内存区

<a id="samp-status-slabs-zone"></a>

#### `/status/slabs/<zone>`

使用 [slab 分配](https://en.wikipedia.org/wiki/Slab_allocation) 的共享内存区的使用统计信息，例如 [limit_conn](#limit-conn)、[limit_req](#limit-req) 和 [HTTP 缓存](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache)：

```nginx
limit_conn_zone $binary_remote_addr zone=limit_conn_zone:10m;
limit_req_zone $binary_remote_addr zone=limit_req_zone:10m rate=1r/s;
proxy_cache cache_zone;
proxy_cache_valid 200 10m;
```

指定的共享内存区将收集以下统计信息：

| `pages`   | 对象；内存页统计信息                                                           |
|-----------|----------------------------------------------------------------------|
| `used`    | 数字；当前使用的内存页数                                                         |
| `free`    | 数字；当前空闲的内存页数                                                         |
| `slots`   | 对象；每个槽大小的内存槽统计信息。`slots` 对象包含内存槽大小的数据（`8`、`16`、`32` 等，最大为页面大小的一半字节数） |
| `used`    | 数字；当前使用的指定大小内存槽数                                                     |
| `free`    | 数字；当前空闲的指定大小内存槽数                                                     |
| `reqs`    | 数字；尝试分配指定大小内存的总次数                                                    |
| `fails`   | 数字；分配指定大小内存失败的次数                                                     |

示例：

```json
{
  "pages": {
    "used": 2,
    "free": 506
  },

  "slots": {
    "64": {
      "used": 1,
      "free": 63,
      "reqs": 1,
      "fails": 0
  }
}
```

<a id="dns-queries-to-resolver"></a>

### 解析器的 DNS 查询

<a id="api-status-resolvers"></a>

#### `/status/resolvers/<zone>`

要收集解析器统计信息，
[resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 指令必须设置 `status_zone` 参数
（[HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver-status) 或 [Stream](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-resolver-status)）：

```nginx
resolver 127.0.0.53 status_zone=resolver_zone;
```

指定的共享内存区将收集以下统计信息：

| `queries`        | 对象；查询统计信息                         |
|------------------|-----------------------------------|
| `name`           | 数字；将名称解析为地址的查询数<br/>（A 和 AAAA 查询） |
| `srv`            | 数字；将服务解析为地址的查询数<br/>（SRV 查询）      |
| `addr`           | 数字；将地址解析为名称的查询数<br/>（PTR 查询）      |
| `responses`      | 对象；响应统计信息                         |
| `success`        | 数字；成功响应的数量                        |
| `timedout`       | 数字；超时查询的数量                        |
| `format_error`   | 数字；代码为 1（格式错误）的响应数量               |
| `server_failure` | 数字；代码为 2（服务器故障）的响应数量              |
| `not_found`      | 数字；代码为 3（名称错误）的响应数量               |
| `unimplemented`  | 数字；代码为 4（未实现）的响应数量                |
| `refused`        | 数字；代码为 5（拒绝）的响应数量                 |
| `other`          | 数字；以其他非零代码完成的查询数量                 |
| `sent`           | 对象；已发送 DNS 查询统计信息                 |
| `a`              | 数字；A 类型查询的数量                      |
| `aaaa`           | 数字；AAAA 类型查询的数量                   |
| `ptr`            | 数字；PTR 类型查询的数量                    |
| `srv`            | 数字；SRV 类型查询的数量                    |

#### NOTE
`queries` 和 `responses` 统计 Angie 在内部发出的每个解析请求，
包括从 TTL 缓存中响应的请求。`sent` 统计实际发送到名称服务器的
数据包；两者之间的差值反映了缓存命中数。

响应代码在 [RFC 1035](https://datatracker.ietf.org/doc/html/rfc1035.html) 的 [4.1.1](https://datatracker.ietf.org/doc/html/rfc1035.html#section-4.1.1) 节中描述。

各种 DNS 记录类型在 [RFC 1035](https://datatracker.ietf.org/doc/html/rfc1035.html)、
[RFC 2782](https://datatracker.ietf.org/doc/html/rfc2782.html) 和
[RFC 3596](https://datatracker.ietf.org/doc/html/rfc3596.html) 中详细说明。

示例：

```json
{
  "queries": {
    "name": 442,
    "srv": 2,
    "addr": 0
  },

  "responses": {
    "success": 440,
    "timedout": 1,
    "format_error": 0,
    "server_failure": 1,
    "not_found": 1,
    "unimplemented": 0,
    "refused": 1,
    "other": 0
  },

  "sent": {
    "a": 185,
    "aaaa": 245,
    "srv": 2,
    "ptr": 12
  }
}
```

<a id="http-server-and-location"></a>

### HTTP 服务器和位置

<a id="api-status-http-server-zones"></a>

#### `/status/http/server_zones/<zone>`

要收集 `server` 指标，
在 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 上下文中设置 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令：

```nginx
server {
    ...
    status_zone server_zone;
}
```

要按自定义值对指标进行分组，请使用替代语法。
此处，指标按 [$host](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-host) 聚合，
每个组作为独立区域报告：

```nginx
status_zone $host zone=server_zone:5;
```

指定的共享内存区将收集以下统计信息：

| `ssl`        | 对象；SSL 统计信息。<br/>仅在 `server` 设置 `listen ssl;` 时存在   |
|--------------|-----------------------------------------------------|
| `handshaked` | 数字；成功的 SSL 握手总数                                     |
| `reuses`     | 数字；SSL 握手期间会话重用的总次数                                 |
| `timedout`   | 数字；超时的 SSL 握手总数                                     |
| `failed`     | 数字；失败的 SSL 握手总数                                     |
| `requests`   | 对象；请求统计信息                                           |
| `total`      | 数字；客户端请求总数                                          |
| `processing` | 数字；当前正在处理的客户端请求数                                    |
| `discarded`  | 数字；未发送响应即完成的客户端请求总数                                 |
| `responses`  | 对象；响应统计信息                                           |
| `<code>`     | 数字；状态为 <code>（100-599）的响应的非零数量                      |
| `xxx`        | 数字；其他状态代码的响应的非零数量                                   |
| `data`       | 对象；数据统计信息                                           |
| `received`   | 数字；从客户端接收的总字节数                                      |
| `sent`       | 数字；发送到客户端的总字节数                                      |

示例：

```json
{
    "ssl":{
        "handshaked":4174,
        "reuses":0,
        "timedout":0,
        "failed":0
    },

    "requests":{
        "total":4327,
        "processing":0,
        "discarded":0
    },

    "responses":{
        "200":4305,
        "302":6,
        "304":12,
        "404":4
    },

    "data":{
        "received":733955,
        "sent":59207757
    }
}
```

<a id="api-status-http-location-zones"></a>

#### `/status/http/location_zones/<zone>`

要收集 `location` 指标，请在 [location](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#location) 或 [if in location](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#if) 上下文中设置 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令：

```nginx
location / {
    root /usr/share/angie/html;
    status_zone location_zone;

    if ($request_uri ~* "^/condition") {
        # ...
        status_zone if_location_zone;
    }
}
```

要按自定义值对指标进行分组，请使用替代语法。
在这里，指标按 [$host](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-host) 聚合，每个组作为独立区域报告：

```nginx
status_zone $host zone=server_zone:5;
```

指定的共享内存区域将收集以下统计信息：

| `requests`   | 对象；请求统计信息                    |
|--------------|------------------------------|
| `total`      | 数字；客户端请求总数                   |
| `discarded`  | 数字；未发送响应而完成的客户端请求总数          |
| `responses`  | 对象；响应统计信息                    |
| `<code>`     | 数字；状态为 <code>（100-599）的非零响应数 |
| `xxx`        | 数字；其他状态代码的非零响应数              |
| `data`       | 对象；数据统计信息                    |
| `received`   | 数字；从客户端接收的字节总数               |
| `sent`       | 数字；发送给客户端的字节总数               |

示例：

```json
{
  "requests": {
    "total": 4158,
    "discarded": 0
  },

  "responses": {
    "200": 4157,
    "304": 1
  },

  "data": {
    "received": 538200,
    "sent": 177606236
  }
}
```

<a id="api-status-http-metric-zones"></a>

#### `/status/http/metric_zones/<zone>`

由 `http` 上下文中的 [metric_zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#metric-zone) 或 [metric_complex_zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#metric-complex-zone)
定义的自定义指标。指标通过 [metric](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#id5)
指令或模块变量更新。

| `discarded`   | 数字；因区域内存不足而丢弃的指标条目数。                                                   |
|---------------|------------------------------------------------------------------------|
| `metrics`     | 对象；按键的指标。对于单指标区域，值为数字。<br/>对于复杂区域，值为带有指标名称的对象。对于直方图<br/>模式，值为带有桶名称的对象。 |

如果设置了 `discard_key` 并且某些条目已过期，
它们的聚合指标将在此键下公开。

示例：

```json
{
    "discarded": 3,
    "metrics": {
        "example.com": {
            "count": 42,
            "max": 8
        }
        "expired": {
            "count": 10,
            "max": 3.2
        }
    }
}
```

<a id="stream-server"></a>

### Stream 服务器

<a id="api-status-stream-server-zones"></a>

#### `/status/stream/server_zones/<zone>`

要收集 `server` 指标，
请在 [server](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-server) 上下文中设置 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-status-zone) 指令：

```nginx
server {
    ...
    status_zone server_zone;
}
```

要按自定义值对指标进行分组，请使用替代语法。
此处，指标按 [$host](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-host) 聚合，
每个组作为独立区域报告：

```nginx
status_zone $host zone=server_zone:5;
```

指定的共享内存区域将收集以下统计信息：

| `ssl`                 | 对象；SSL 统计信息。<br/>当 `server` 设置 `listen ssl;` 时出现   |
|-----------------------|----------------------------------------------------|
| `handshaked`          | 数字；成功 SSL 握手的总次数                                   |
| `reuses`              | 数字；SSL 握手期间会话重用的总次数                                |
| `timedout`            | 数字；超时 SSL 握手的总次数                                   |
| `failed`              | 数字；失败 SSL 握手的总次数                                   |
| `connections`         | 对象；连接统计信息                                          |
| `total`               | 数字；客户端连接的总数                                        |
| `processing`          | 数字；当前正在处理的客户端连接数                                   |
| `discarded`           | 数字；未创建会话即完成的客户端连接总数                                |
| `passed`              | 数字；通过 `pass` 指令中继到另一个监听端口的客户端连接总数                  |
| `sessions`            | 对象；会话统计信息                                          |
| `success`             | 数字；以代码 200 完成的会话数，表示成功完成                           |
| `invalid`             | 数字；以代码 400 完成的会话数，当无法解析客户端数据时发生，例如 PROXY 协议头       |
| `forbidden`           | 数字；以代码 403 完成的会话数，当访问被禁止时，例如当某些客户端地址的访问受到限制时       |
| `internal_error`      | 数字；以代码 500 完成的会话数，内部服务器错误                          |
| `bad_gateway`         | 数字；以代码 502 完成的会话数，错误网关，例如无法选择或访问上游服务器时             |
| `service_unavailable` | 数字；以代码 503 完成的会话数，服务不可用，例如当访问受连接数限制时               |
| `data`                | 对象；数据统计信息                                          |
| `received`            | 数字；从客户端接收的总字节数                                     |
| `sent`                | 数字；发送到客户端的总字节数                                     |

示例：

```json
{
  "ssl": {
    "handshaked": 24,
    "reuses": 0,
    "timedout": 0,
    "failed": 0
  },

  "connections": {
    "total": 24,
    "processing": 1,
    "discarded": 0,
    "passed": 2
  },

  "sessions": {
    "success": 24,
    "invalid": 0,
    "forbidden": 0,
    "internal_error": 0,
    "bad_gateway": 0,
    "service_unavailable": 0
  },

  "data": {
    "received": 2762947,
    "sent": 53495723
  }
}
```

<a id="http-caches"></a>

### HTTP 缓存

```nginx
proxy_cache cache_zone;
proxy_cache_valid 200 10m;
```

<a id="api-status-http-caches"></a>

#### `/status/http/caches/<cache>`

对于使用 [proxy_cache](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache) 配置的每个区域，存储以下数据：

```json
{
  "name_zone": {
    "size": 0,
    "cold": false,
    "hit": {
      "responses": 0,
      "bytes": 0
    },

    "stale": {
      "responses": 0,
      "bytes": 0
    },

    "updating": {
      "responses": 0,
      "bytes": 0
    },

    "revalidated": {
      "responses": 0,
      "bytes": 0
    },

    "miss": {
      "responses": 0,
      "bytes": 0,
      "responses_written": 0,
      "bytes_written": 0
    },

    "expired": {
      "responses": 0,
      "bytes": 0,
      "responses_written": 0,
      "bytes_written": 0
    },

    "bypass": {
      "responses": 0,
      "bytes": 0,
      "responses_written": 0,
      "bytes_written": 0
    }
  }
}
```

| `size`              | 数字；缓存的当前大小                                                                                                                                                         |
|---------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `max_size`          | 数字；配置的缓存最大大小限制                                                                                                                                                     |
| `cold`              | 布尔值；当 cache loader 从磁盘加载数据时为 `true`                                                                                                                                |
| `hit`               | 对象；有效缓存响应的统计信息 ([proxy_cache_valid](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-valid))                             |
| `responses`         | 数字；从缓存读取的响应总数                                                                                                                                                      |
| `bytes`             | 数字；从缓存读取的总字节数                                                                                                                                                      |
| `stale`             | 对象；从缓存获取的过期响应的统计信息 ([proxy_cache_use_stale](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-use-stale))                 |
| `responses`         | 数字；从缓存读取的响应总数                                                                                                                                                      |
| `bytes`             | 数字；从缓存读取的总字节数                                                                                                                                                      |
| `updating`          | 对象；在响应更新期间从缓存获取的过期响应的统计信息 ([proxy_cache_use_stale](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-use-stale) updating) |
| `responses`         | 数字；从缓存读取的响应总数                                                                                                                                                      |
| `bytes`             | 数字；从缓存读取的总字节数                                                                                                                                                      |
| `revalidated`       | 对象；从缓存获取的已过期并重新验证的响应的统计信息 ([proxy_cache_revalidate](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-revalidate))        |
| `responses`         | 数字；从缓存读取的响应总数                                                                                                                                                      |
| `bytes`             | 数字；从缓存读取的总字节数                                                                                                                                                      |
| `miss`              | 对象；在缓存中未找到的响应的统计信息                                                                                                                                                 |
| `responses`         | 数字；相应响应的总数                                                                                                                                                         |
| `bytes`             | 数字；从代理服务器读取的总字节数                                                                                                                                                   |
| `responses_written` | 数字；写入缓存的响应总数                                                                                                                                                       |
| `bytes_written`     | 数字；写入缓存的总字节数                                                                                                                                                       |
| `expired`           | 对象；未从缓存获取的已过期响应的统计信息                                                                                                                                               |
| `responses`         | 数字；相应响应的总数                                                                                                                                                         |
| `bytes`             | 数字；从代理服务器读取的总字节数                                                                                                                                                   |
| `responses_written` | 数字；写入缓存的响应总数                                                                                                                                                       |
| `bytes_written`     | 数字；写入缓存的总字节数                                                                                                                                                       |
| `bypass`            | 对象；未在缓存中查找的响应的统计信息 ([proxy_cache_bypass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-bypass))                       |
| `responses`         | 数字；相应响应的总数                                                                                                                                                         |
| `bytes`             | 数字；从代理服务器读取的总字节数                                                                                                                                                   |
| `responses_written` | 数字；写入缓存的响应总数                                                                                                                                                       |
| `bytes_written`     | 数字；写入缓存的总字节数                                                                                                                                                       |

在 Angie PRO 中，如果使用 [proxy_cache_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-path) 指令启用了 cache sharding，
各个分片将作为 `shards` 对象的对象成员公开：

| `shards`   | 对象；将各个分片列为成员                        |
|------------|-------------------------------------|
| `<shard>`  | 对象；表示单个分片，其缓存路径作为名称                 |
| `size`     | 数字；分片的当前大小                          |
| `max_size` | 数字；最大分片大小（如果已配置）                    |
| `cold`     | 布尔值；当 cache loader 从磁盘加载数据时为 `true` |
```json
{
  "name_zone": {
    "shards": {
        "/path/to/shard1": {
            "size": 0,
            "cold": false
        },

        "/path/to/shard2": {
            "size": 0,
            "cold": false
        }
    }
}
```

<a id="http-acme-clients"></a>

### ACME 客户端

<a id="api-status-http-acme-clients"></a>

#### `/status/http/acme_clients/<client>`

对于 `http` 块中配置的每个 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client)，返回当前客户端和证书状态：

```json
{
  "state": "ready",
  "certificate": "valid",
  "details": "The client is ready to request a certificate.",
  "next_run": "|sampledateshort|T16:15:43.805Z"
}
```

| `state`       | 字符串；ACME 客户端状态。可能的值：`ready`、<br/>`requesting`、`disabled`、`failed`。       |
|---------------|--------------------------------------------------------------------------|
| `certificate` | 字符串；证书状态。可能的值：`valid`、<br/>`expired`、`missing`、`mismatch`、`error`。       |
| `details`     | 字符串；上次 ACME 操作的简短状态详情。                                                   |
| `next_run`    | 日期；下次计划请求或续订证书的尝试时间。<br/>当 `state` 为 `disabled` 或<br/>`requesting` 时不返回。 |

<a id="limit-conn"></a>

### limit_conn

```nginx
limit_conn_zone $binary_remote_addr zone=limit_conn_zone:10m;
```

<a id="api-status-http-limit-conns"></a>

#### `/status/http/limit_conns/<zone>`，`/status/stream/limit_conns/<zone>`

每个配置的 [http 中的 limit_conn](#limit-conn) 或 [stream 中的 limit_conn](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_limit_conn.md#s-limit-conn) 上下文的对象，包含以下字段：

```json
{
  "passed": 73,
  "skipped": 0,
  "rejected": 0,
  "exhausted": 0
}
```

| `passed`    | 数字；通过的连接总数                   |
|-------------|------------------------------|
| `skipped`   | 数字；使用零长度键或键超过 255 字节而通过的连接总数 |
| `rejected`  | 数字；超过配置限制的连接总数               |
| `exhausted` | 数字；由于区域存储耗尽而拒绝的连接总数          |

<a id="limit-req"></a>

### limit_req

```nginx
limit_req_zone $binary_remote_addr zone=limit_req_zone:10m rate=1r/s;
```

<a id="api-status-http-limit-reqs"></a>

#### `/status/http/limit_reqs/<zone>`

每个配置的 [limit_req](#limit-req) 的对象，包含以下字段：

```json
{
  "passed": 54816,
  "skipped": 0,
  "delayed": 65,
  "rejected": 26,
  "exhausted": 0
}
```

| `passed`    | 数字；通过的请求总数                   |
|-------------|------------------------------|
| `skipped`   | 数字；使用零长度键或键超过 255 字节而通过的请求总数 |
| `delayed`   | 数字；延迟的请求总数                   |
| `rejected`  | 数字；拒绝的请求总数                   |
| `exhausted` | 数字；由于区域存储耗尽而拒绝的请求总数          |

<a id="a-upstream"></a>

### HTTP 上游

要启用以下指标的收集，
请在 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 上下文中设置 [zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-zone) 指令，
例如：

```nginx
upstream upstream {
    zone upstream 256k;
    server backend.example.com service=_example._tcp resolve max_conns=5;
    keepalive 4;
}
```

<a id="api-status-http-upstreams"></a>

#### `/status/http/upstreams/<upstream>`

其中 <upstream> 是使用 [zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-zone) 指令指定的任何 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 的名称

```json
{
    "peers": {
        "192.168.16.4:80": {
            "server": "backend.example.com",
            "service": "_example._tcp",
            "backup": false,
            "weight": 5,
            "state": "up",
            "selected": {
                "current": 2,
                "total": 232
            },

            "max_conns": 5,
            "responses": {
                "200": 222,
                "302": 12
            },

            "data": {
                "sent": 543866,
                "received": 27349934
            },

            "health": {
                "fails": 0,
                "unavailable": 0,
                "downtime": 0
            },

            "sid": "<server_id>"
        }
    },

    "keepalive": 2
}
```

| `peers`                           | 对象；包含上游节点的指标作为子对象，<br/>子对象的名称是节点地址的规范表示。<br/>每个子对象的成员：                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
|-----------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `server`                          | 字符串；[server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 指令的参数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `service`                         | 字符串；在 [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 指令中指定的服务名称（如果已配置）                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `backup`                          | 布尔值；备份服务器为 `true`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `weight`                          | 数字；配置的 [权重](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `state`                           | 字符串；节点的当前状态以及发送给它的请求：<br/><br/>- `busy`：表示发送到服务器的请求数量<br/>  已达到 [max_conns](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 设置的限制，<br/>  不再向其发送新请求；<br/>- `down`：手动禁用，不发送请求；<br/>- `recovering`：根据 [slow_start](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#slow-start) 从故障中恢复，<br/>  随着时间推移发送越来越多的请求；<br/>- `unavailable`：达到 [max_fails](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#max-fails) 限制，<br/>  仅在 [fail_timeout](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#fail-timeout) 定义的间隔内<br/>  发送试探性客户端请求；<br/>- `up`：正常运行，正常发送请求；<br/><br/>Angie PRO 中的附加状态：<br/><br/>- `checking`：配置为 `essential` 并正在检查中，<br/>  仅发送 [探测请求](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe)；<br/>- `draining`：类似于 `down`，<br/>  但来自先前绑定会话的请求<br/>  （通过 [sticky](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky)）仍会发送；<br/>- `unhealthy`：不可操作，<br/>  仅发送 [探测请求](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe)。 |
| `selected`                        | 对象；节点选择统计信息                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `current`                         | 数字；当前到节点的连接数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `total`                           | 数字；转发到节点的请求总数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `last`                            | 字符串或数字；节点最后被选择的时间，<br/>格式为 [日期](#api-date-format)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `max_conns`                       | 数字；配置的到节点的同时活动连接的 [最大](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 数量（如果指定）                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `responses`                       | 对象；响应统计信息                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `<code>`                          | 数字；状态码为 <code> (100-599) 的响应的非零数量                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `xxx`                             | 数字；其他状态码响应的非零数量                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `data`                            | 对象；数据统计信息                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `received`                        | 数字；从节点接收的字节总数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `sent`                            | 数字；发送到节点的字节总数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `health`                          | 对象；健康统计信息                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `fails`                           | 数字；与节点通信失败的尝试总数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `unavailable`                     | 数字；由于达到 [max_fails](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#max-fails) 限制而导致节点变为 `unavailable` 的次数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `downtime`                        | 数字；节点 `unavailable` 无法选择的总时间（以毫秒为单位）                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `downstart`                       | 字符串或数字；节点变为 `unavailable` 的时间，<br/>格式为 [日期](#api-date-format)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `header_time` <br/>(PRO 1.3.0+)   | 数字；从服务器接收响应头的平均时间（以毫秒为单位）；<br/>参见 [response_time_factor (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-response-time-factor)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `response_time` <br/>(PRO 1.3.0+) | 数字；从服务器接收完整响应的平均时间（以毫秒为单位）；<br/>参见 [response_time_factor (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-response-time-factor)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `sid`                             | 字符串；上游组中服务器的 [配置 id](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `keepalive`                       | 数字；当前缓存连接数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `backup_switch`                   | 对象；包含活动备份逻辑的当前状态，<br/>如果为上游配置了 [backup_switch (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-backup-switch) 则存在                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `active`                          | 数字；当前用于负载均衡请求的活动组级别。<br/>如果活动组是主组，则值为 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `timeout`                         | 数字；剩余等待时间（以毫秒为单位），<br/>之后负载均衡器将重新检查较低级别组中的健康节点，<br/>从主组开始，而不检查较高级别的组；<br/>主组（级别 0）不显示                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |

<a id="samp-health-probes-pro"></a>

##### `health/probes` (PRO)

#### Versionchanged
在 1.2.0 版本发生变更: PRO

如果上游配置了 [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe) 探测，
`health` 对象还有一个 `probes` 子对象
用于存储服务器的健康探测计数器，
而 `state` 除了上表中列出的值外，
还可以是 `checking` 和 `unhealthy`：

```json
{
    "192.168.16.4:80": {
        "state": "unhealthy",
        "...": "...",
        "health": {
            "...": "...",
            "probes": {
                "count": 10,
                "fails": 10,
                "last": "|sampledateshort|T09:56:07Z"
            }
        }
    }
}
```

`state` 的 `checking` 值不计入 `downtime`，
表示配置了 `essential` 探测的服务器尚未被检查；
`unhealthy` 值表示服务器出现故障。
这两种状态都意味着服务器不包含在负载均衡中。
有关健康探测的详细信息，请参见 [upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe)。

`probes` 中的计数器：

| `count`   | 数字；此服务器的探测总数                                  |
|-----------|-----------------------------------------------|
| `fails`   | 数字；失败探测总数                                     |
| `last`    | 字符串或数字；最后探测时间，<br/>格式为 [日期](#api-date-format) |

<a id="a-queue"></a>

##### `queue` (PRO)

#### Versionchanged
在 1.4.0 版本发生变更: PRO

如果为上游配置了 [请求队列](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-queue)，
上游对象还包含一个嵌套的 `queue` 对象，
其中包含请求队列计数器：

```json
{
    "queue": {
        "queued": 20112,
        "waiting": 1011,
        "dropped": 6031,
        "timedout": 560,
        "overflows": 13
    }
}
```

计数器值在所有工作进程中求和：

| `queued`    | 数字；进入队列的请求总数              |
|-------------|---------------------------|
| `waiting`   | 数字；队列中当前的请求数              |
| `dropped`   | 数字；因客户端过早关闭连接而从队列中移除的请求总数 |
| `timedout`  | 数字；因超时而从队列中移除的请求总数        |
| `overflows` | 数字；队列溢出发生的总次数             |

<a id="a-s-upstream"></a>

### Stream 上游

要启用以下指标的收集，
请在 [upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-upstream) 上下文中设置 [zone](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-zone) 指令，
例如：

```nginx
upstream upstream {
    zone upstream 256k;
    server backend.example.com service=_example._tcp resolve max_conns=5;
    keepalive 4;
}
```

<a id="api-status-stream-upstreams"></a>

#### `/status/stream/upstreams/<upstream>`

其中 <upstream> 是使用 [zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-zone) 指令配置的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 的名称。

```json
{
    "peers": {
        "192.168.16.4:1935": {
            "server": "backend.example.com",
            "service": "_example._tcp",
            "backup": false,
            "weight": 5,
            "state": "up",
            "selected": {
                "current": 2,
                "total": 232
            },

            "max_conns": 5,
            "data": {
                "sent": 543866,
                "received": 27349934
            },

            "health": {
                "fails": 0,
                "unavailable": 0,
                "downtime": 0
            }
        }
    }
}
```

| `peers`                           | 对象；包含上游服务器组中各对等节点的指标，作为子对象，<br/>其名称是对等节点地址的规范表示形式。<br/>每个子对象的成员：                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
|-----------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `server`                          | 字符串；由 [server](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-server) 指令设置的地址                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `service`                         | 字符串；在 [server](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-server) 指令中指定的服务名称（如果已配置）                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `backup`                          | 布尔值；备份服务器为 `true`                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `weight`                          | 数字；为对等节点设置的 [权重](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-server)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `state`                           | 字符串；对等节点的当前状态以及发送给它的请求：<br/><br/>- `busy`：表示发送到服务器的请求数<br/>  已达到 [max_conns](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-server) 设置的限制，<br/>  不再向其发送新请求<br/>- `down`：手动禁用，不发送请求<br/>- `recovering`：根据 [slow_start](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-slow-start) 从故障中恢复，<br/>  随着时间推移发送越来越多的请求<br/>- `unavailable`：达到 [max_fails](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-max-fails) 限制，<br/>  仅以 [fail_timeout](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-fail-timeout) 定义的间隔发送试探性客户端请求<br/>- `up`：正常运行，照常发送请求<br/><br/>Angie PRO 中的附加状态：<br/><br/>- `checking`：配置为 `essential` 并正在检查中，<br/>  仅发送 [探测请求](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#s-u-upstream-probe)<br/>- `draining`：类似于 `down`，<br/>  但来自先前绑定会话的请求<br/>  （通过 [sticky](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky)）仍会发送<br/>- `unhealthy`：不可用，<br/>  仅发送 [探测请求](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#s-u-upstream-probe) |
| `selected`                        | 对象；选择此对等节点进行连接的统计信息                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `current`                         | 数字；当前到对等节点的连接数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `total`                           | 数字；转发到对等节点的连接总数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `last`                            | 字符串或数字；上次选择对等节点的时间，<br/>格式为 [日期](#api-date-format)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `max_conns`                       | 数字；到对等节点的同时活动连接的 [最大](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-server) 数量（如果已设置）                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `data`                            | 对象；数据传输统计信息                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `received`                        | 数字；从对等节点接收的总字节数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `sent`                            | 数字；发送到对等节点的总字节数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `health`                          | 对象；对等节点健康统计信息                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `fails`                           | 数字；尝试到达对等节点失败的总次数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `unavailable`                     | 数字；由于达到 [max_fails](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-max-fails) 值，对等节点变为 `unavailable` 的总次数                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `downtime`                        | 数字；对等节点处于 `unavailable` 状态（无法被选择）的总时间（以毫秒为单位）                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `downstart`                       | 字符串或数字；对等节点上次变为 `unavailable` 的时间，<br/>格式为 [日期](#api-date-format)                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `connect_time`                    | 数字；与服务器建立连接的平均时间（以毫秒为单位）；<br/>参见 [response_time_factor (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-response-time-factor) 指令                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `first_byte_time`                 | 数字；从服务器接收第一个字节的平均时间（以毫秒为单位）；<br/>参见 [response_time_factor (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-response-time-factor) 指令                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `last_byte_time`                  | 数字；从服务器接收完整响应的平均时间（以毫秒为单位）；<br/>参见 [response_time_factor (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-response-time-factor) 指令                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `backup_switch`<br/>(PRO 1.10.0+) | 对象；包含活动备份逻辑的当前状态，<br/>如果为上游配置了 [backup_switch (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-backup-switch) 则显示                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `active`                          | 数字；当前用于负载均衡的活动组的级别。<br/>如果活动组是主组，则值为 0                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `timeout`                         | 数字；剩余等待时间（以毫秒为单位），<br/>之后负载均衡器将重新检查较低级别组中的健康节点，<br/>从主组开始，<br/>而不检查较高级别的组；<br/>主组（级别 0）不显示                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |

#### Versionchanged
在 1.4.0 版本发生变更: PRO

在 Angie PRO 中，如果上游配置了 [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#s-u-upstream-probe) 探测，
`health` 对象还包含一个 `probes` 子对象，
用于存储服务器的健康探测计数器，
而 `state` 除了上表中列出的值外，
还可以是 `checking` 和 `unhealthy`：

```json
{
    "192.168.16.4:80": {
        "state": "unhealthy",
        "...": "...",
        "health": {
            "...": "...",
            "probes": {
                "count": 2,
                "fails": 2,
                "last": "|sampledateshort|T11:03:54Z"
            }
        }
    }
}
```

`state` 的 `checking` 值表示配置了 `essential` 参数探测的服务器尚未被检查；
`unhealthy` 值表示服务器不可用。
这两种状态还意味着服务器不包含在负载均衡中。
有关健康探测的详细信息，请参见 [upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#s-u-upstream-probe)。

`probes` 中的计数器：

| `count`   | 数字；此服务器的探测总数                                   |
|-----------|------------------------------------------------|
| `fails`   | 数字；失败的探测数                                      |
| `last`    | 字符串或数字；上次探测的时间，<br/>格式为 [日期](#api-date-format) |

<a id="api-config"></a>

## 动态配置 API (PRO)

该 API 包含一个 `/config` 节，可通过 `PUT`、`PATCH` 和 `DELETE` HTTP 请求
以 JSON 格式动态更新 Angie 的配置。
所有更新都是原子性的：新设置作为一个整体应用，
或者完全不应用。
出错时，Angie 会报告原因。

<a id="api-config-sections"></a>

### `/config` 的子节

目前，`/config` 节中可用于 [HTTP](#api-config-http-upstreams-servers) 和 [stream](#api-config-stream-upstreams-servers) 模块的上游内各个服务器的配置；
可进行动态配置的设置数量正在稳步增加。

<a id="api-config-http-upstreams-servers"></a>

#### `/config/http/upstreams/<upstream>/servers/<name>`

允许配置单个上游对等节点，
包括删除现有对等节点或添加新对等节点。

URI 路径参数：

| `<upstream>`   | 上游的名称；要通过 `/config` 进行配置，必须配置<br/>[zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-zone) 指令，定义一个共享内存区域。               |
|----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `<name>`       | 上游中对等节点的名称，定义为<br/>`<service>@<host>`，其中：<br/><br/>- `<service>@` 是可选的服务名称，用于<br/>  SRV 记录解析。<br/>- `<host>` 是服务的域名（如果存在 `resolve`）<br/>  或其 IP 地址；可以在此定义可选的端口。 |

例如，以下配置：

```nginx
upstream backend {
    server backend.example.com service=_http._tcp resolve;
    server 127.0.0.1;
    zone backend 1m;
}
```

允许以下对等节点名称：

```console
$ curl http://127.0.0.1/config/http/upstreams/backend/servers/_http._tcp@backend.example.com/
$ curl http://127.0.0.1/config/http/upstreams/backend/servers/127.0.0.1:80/
```

此 API 子节允许设置 `weight`、`max_conns`、
`max_fails`、`fail_timeout`、`slow_start`、`backup`、`down` 和
`sid` 参数，如 [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 中所述。

#### NOTE
这里没有单独的 `drain` (PRO) 参数；
要启用 `drain`，
将 `down` 设置为字符串值 `drain`：

```console
$ curl -X PUT -d \"drain\" \
  http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com/down
```

示例：

```console
$ curl http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com?defaults=on
```

```json
{
    "weight": 1,
    "max_conns": 0,
    "max_fails": 1,
    "fail_timeout": 10,
    "slow_start": 0,
    "backup": true,
    "down": false,
    "sid": ""
}
```

实际可用的参数仅限于 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 当前负载均衡方法所支持的参数。
因此，如果上游配置了 `random` 方法：

```nginx
upstream backend {
    zone backend 256k;
    server backend.example.com resolve max_conns=5;
    random;
}
```

您将无法添加定义了 `backup` 的新对等节点：

```console
$ curl -X PUT -d '{ "backup": true }' \
    http://127.0.0.1/config/http/upstreams/backend/servers/backend1.example.com
```

```json
{
    "error": "FormatError",
    "description": "The \"backup\" field is unknown."
}
```

#### NOTE
即使使用兼容的负载均衡方法，`backup` 参数
也只能在添加新对等节点时设置。

<a id="api-config-stream-upstreams-servers"></a>

#### `/config/stream/upstreams/<upstream>/servers/<name>`

允许配置单个上游对等节点，
包括删除现有对等节点或添加新对等节点。

URI 路径参数：

| `<upstream>`   | `upstream` 块的名称；<br/>要通过 `/config` 进行配置，<br/>必须配置 [zone](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-zone) 指令，<br/>定义一个共享内存区域。   |
|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `<name>`       | 上游中对等节点的名称，定义为<br/>`<service>@<host>`，其中：<br/><br/>- `<service>@` 是可选的服务名称，用于<br/>  SRV 记录解析。<br/>- `<host>` 是服务的域名（如果存在 `resolve`）<br/>  或其 IP 地址；可以在此定义可选的端口。                |

例如，以下配置：

```nginx
upstream backend {
    server backend.example.com:8080 service=_example._tcp resolve;
    server 127.0.0.1:12345;
    zone backend 1m;
}
```

允许以下对等节点名称：

```console
$ curl http://127.0.0.1/config/stream/upstreams/backend/servers/_example._tcp@backend.example.com:8080/
$ curl http://127.0.0.1/config/stream/upstreams/backend/servers/127.0.0.1:12345/
```

此 API 子部分允许设置 `weight`、
`max_conns`、`max_fails`、`fail_timeout`、`slow_start`、`backup` 和
`down` 参数，如 [server](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-server) 中所述。

#### NOTE
这里没有单独的 `drain`（PRO）参数；
要启用 :samp:`drain` 模式，
将 `down` 设置为字符串值 `drain`：

```console
$ curl -X PUT -d \"drain\" \
  http://127.0.0.1/config/stream/upstreams/backend/servers/backend.example.com/down
```

示例：

```console
curl http://127.0.0.1/config/stream/upstreams/backend/servers/backend.example.com?defaults=on
```

```json
{
    "weight": 1,
    "max_conns": 0,
    "max_fails": 1,
    "fail_timeout": 10,
    "slow_start": 0,
    "backup": true,
    "down": false,
}
```

实际可用的参数仅限于 [upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-upstream) 当前负载均衡方法所支持的参数。
因此，如果上游配置了 `random` 方法：

```nginx
upstream backend {
    zone backend 256k;
    server backend.example.com resolve max_conns=5;
    random;
}
```

您将无法添加定义了 `backup` 的新对等节点：

```console
$ curl -X PUT -d '{ "backup": true }' \
    http://127.0.0.1/config/stream/upstreams/backend/servers/backend1.example.com
```

```json
{
    "error": "FormatError",
    "description": "The \"backup\" field is unknown."
}
```

#### NOTE
即使使用兼容的负载均衡方法，`backup` 参数
也只能在添加新对等节点时设置。

删除对等节点时，您可以设置
`connection_drop=<value>` 参数（PRO）来覆盖
[proxy_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#s-proxy-connection-drop) 设置：

```console
$ curl -X DELETE \
    http://127.0.0.1/config/stream/upstreams/backend/servers/backend1.example.com?connection_drop=off

$ curl -X DELETE \
    http://127.0.0.1/config/stream/upstreams/backend/servers/backend2.example.com?connection_drop=on

$ curl -X DELETE \
    http://127.0.0.1/config/stream/upstreams/backend/servers/backend3.example.com?connection_drop=1000
```

<a id="api-config-methods"></a>

### HTTP 方法

让我们以下面的上游配置为例，来考虑适用于本节的每个 HTTP 方法的语义：

```nginx
http {
    # ...

    upstream backend {
        zone upstream 256k;
        server backend.example.com resolve max_conns=5;
        # ...
    }

    server {
        # ...

        location /config/ {
            api /config/;

            allow 127.0.0.1;
            deny all;
        }
    }
}
```

<a id="get"></a>

#### GET

`GET` HTTP 方法查询 `/config` 中任何现有路径上的实体，
就像它对其他 API 部分所做的那样。

例如，
`/config/http/upstreams/backend/servers/`
上游服务器分支支持以下查询：

```console
$ curl http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com/max_conns
$ curl http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com
$ curl http://127.0.0.1/config/http/upstreams/backend/servers
$ # ...
$ curl http://127.0.0.1/config
```

您可以使用 `defaults=on` 参数获取默认参数值：

```console
$ curl http://127.0.0.1/config/http/upstreams/backend/servers?defaults=on
```

```json
{
    "backend.example.com": {
        "weight": 1,
        "max_conns": 5,
        "max_fails": 1,
        "fail_timeout": 10,
        "slow_start": 0,
        "backup": false,
        "down": false,
        "sid": ""
    }
}
```

<a id="put"></a>

#### PUT

`PUT` HTTP 方法在指定路径创建一个新的 JSON 实体，
或\*完全\*替换现有实体。

例如，要向 `backend` 上游中的 `backend.example.com` 服务器
添加之前未指定的 `max_fails` 参数：

```console
$ curl -X PUT -d '2' \
    http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com/max_fails
```

```json
{
    "success": "Updated",
    "description": "Existing configuration API entity \"/config/http/upstreams/backend/servers/backend.example.com/max_fails\" was updated with replacing."
}
```

验证更改：

```console
$ curl http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com
```

```json
{
    "max_conns": 5,
    "max_fails": 2
}
```

<a id="delete"></a>

#### DELETE

`DELETE` HTTP 方法删除指定路径上\*先前定义\*的设置；
这样做时，如果存在默认值，它会恢复默认值。

例如，要删除 `backend` 上游中 `backend.example.com` 服务器
之前修改的 `max_fails` 参数：

```console
$ curl -X DELETE \
    http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com/max_fails
```

```json
{
    "success": "Reset",
    "description": "Configuration API entity \"/config/http/upstreams/backend/servers/backend.example.com/max_fails\" was reset to default."
}
```

使用 `defaults=on` 参数验证更改：

```console
$ curl http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com?defaults=on
```

```json
{
    "weight": 1,
    "max_conns": 5,
    "max_fails": 1,
    "fail_timeout": 10,
    "slow_start": 0,
    "backup": false,
    "down": false,
    "sid": ""
}
```

`max_fails` 参数已恢复为其默认值。

删除服务器时，您可以设置 `connection_drop=<value>` 参数
（PRO）来覆盖 [proxy_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-connection-drop)、[grpc_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_grpc.md#grpc-connection-drop)、
[fastcgi_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-connection-drop)、[scgi_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-connection-drop) 和
[uwsgi_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-connection-drop) 设置：

```console
$ curl -X DELETE \
    http://127.0.0.1/config/http/upstreams/backend/servers/backend1.example.com?connection_drop=off

$ curl -X DELETE \
    http://127.0.0.1/config/http/upstreams/backend/servers/backend2.example.com?connection_drop=on

$ curl -X DELETE \
    http://127.0.0.1/config/http/upstreams/backend/servers/backend3.example.com?connection_drop=1000
```

<a id="patch"></a>

#### PATCH

`PATCH` HTTP 方法在指定路径创建一个新实体，
或部分替换或补充现有实体
（[RFC 7386](https://datatracker.ietf.org/doc/html/rfc7396)），
通过在其有效负载中提供 JSON 定义。

该方法的操作如下：如果新定义中的实体
存在于配置中，则会被覆盖；否则，它们会被添加。

例如，要更改 `backend` 上游中 `backend.example.com` 服务器的
`down` 参数，同时保持其余部分不变：

```console
$ curl -X PATCH -d '{ "down": true }' \
    http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com
```

```json
{
    "success": "Updated",
    "description": "Existing configuration API entity \"/config/http/upstreams/backend/servers/backend.example.com\" was updated with merging."
}
```

验证更改：

```console
$ curl http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com
```

```json
{
    "max_conns": 5,
    "down": true
}
```

请注意，随 `PATCH` 请求提供的 JSON 对象\*被合并\*到现有对象中，
而不是像 `PUT` 那样完全替换它。

`null` 值是一种特殊情况；它们用于在此类合并期间
删除特定的配置项。

#### NOTE
此删除与 `DELETE` 相同；
特别是，它会恢复默认值。

例如，要删除之前添加的 `down` 参数
并同时更新 `max_conns`：

```console
$ curl -X PATCH -d '{ "down": null, "max_conns": 6 }' \
    http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com
```

```json
{
    "success": "Updated",
    "description": "Existing configuration API entity \"/config/http/upstreams/backend/servers/backend.example.com\" was updated with merging."
}
```

验证更改：

```console
$ curl http://127.0.0.1/config/http/upstreams/backend/servers/backend.example.com
```

```json
{
    "max_conns": 6
}
```

提供了 `null` 值的 `down` 参数已被删除；
`max_conns` 值已更新。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_auth_basic.md

<!-- review: finished -->

<a id="http-auth-basic"></a>

# Auth Basic

允许通过使用"HTTP基本认证"协议验证用户名和密码来限制对资源的访问。

访问也可以通过 [地址](https://cn.angie.software//angie/docs/configuration/modules/http/http_access.md#http-access) 或通过 [子请求结果](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_request.md#http-auth-request) 来限制。通过地址和密码同时限制访问由 [satisfy](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#satisfy) 指令控制。

<a id="configuration-example-6"></a>

## 配置示例

```nginx
location / {
    auth_basic           "closed site";
    auth_basic_user_file conf/htpasswd;
}
```

<a id="directives-7"></a>

## 指令

<a id="index-0"></a>

<a id="auth-basic"></a>

### auth_basic

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `auth_basic` string | `off`;         |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认                                                                                   | `auth_basic off;`                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, limit_except |

通过"HTTP基本认证"协议启用用户名和密码验证。指定的参数用作 领域。参数值可以包含变量。

| `off`   | 取消从先前配置级别继承的 auth_basic 指令的效果   |
|---------|---------------------------------|

<a id="index-1"></a>

<a id="auth-basic-user-file"></a>

### auth_basic_user_file

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `auth_basic_user_file` file;         |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认                                                                                   | —                                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, limit_except |

指定一个 文件 来保存用户名和密码，格式如下：

```none
# 注释
name1:password1
name2:password2:comment
name3:password3
```

文件 名可以包含变量。

支持以下密码类型：

* 使用 crypt() 函数加密；可以使用Apache HTTP Server发行版中的 `htpasswd` 工具或"openssl passwd"命令生成；
* 使用基于MD5的密码算法的Apache变体（apr1）进行哈希；可以使用相同的工具生成；
* 按照 [RFC 2307](https://datatracker.ietf.org/doc/html/rfc2307#section-5.3) 中描述的"{scheme}data"语法指定；目前实现的方案包括 PLAIN （一个示例，不应使用）、SHA （纯SHA-1哈希，不应使用）和 SSHA （加盐SHA-1哈希，一些软件包使用，尤其是OpenLDAP和Dovecot）。

#### WARNING
SHA方案的支持仅为从其他Web服务器迁移提供帮助。它不应用于新密码，因为采用的未加盐SHA-1哈希易受 [彩虹表](http://en.wikipedia.org/wiki/Rainbow_attack) 攻击。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_auth_request.md

<!-- review: finished -->

<a id="http-auth-request"></a>

# Auth Request

根据子请求的结果实现客户端授权。如果子请求返回 2xx 响应代码，则允许访问。如果返回 401 或 403，则拒绝访问，并返回相应的错误代码。子请求返回的任何其他响应代码都被视为错误。

对于 401 错误，客户端还会收到来自子请求响应的 `WWW-Authenticate` 头。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，该模块默认未构建；应通过 `‑‑with‑http_auth_request_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用。

在来自 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的包和镜像中，模块已包含在构建中。

该模块可以与其他访问模块组合，例如 [Access](https://cn.angie.software//angie/docs/configuration/modules/http/http_access.md#http-access) 和 [Auth Basic](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_basic.md#http-auth-basic)，通过 [satisfy](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#satisfy) 指令。

<a id="configuration-example-7"></a>

## 配置示例

```nginx
location /private/ {
    auth_request /auth;
#    ...
}

location = /auth {
    proxy_pass ...;
    proxy_pass_request_body off;
    proxy_set_header Content-Length "";
    proxy_set_header X-Original-URI $request_uri;
}
```

<a id="directives-8"></a>

## 指令

<a id="index-0"></a>

<a id="auth-request"></a>

### auth_request

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `auth_request` `uri` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `auth_request off;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

根据子请求的结果启用授权，并设置子请求将被发送的 URI。

<a id="index-1"></a>

<a id="auth-request-set"></a>

### auth_request_set

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `auth_request_set` $variable value;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | —                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

在授权请求完成后，将请求变量设置为给定值。值可以包含来自授权请求的变量，例如 `$upstream_http_*`。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_autoindex.md

<!-- review: finished -->

<a id="http-autoindex"></a>

# AutoIndex

该模块处理以斜杠字符 (`/`) 结尾的请求，并生成目录列表。通常，当 [Index](https://cn.angie.software//angie/docs/configuration/modules/http/http_index.md#http-index) 模块找不到索引文件时，请求会传递给 `AutoIndex` 模块。

<a id="configuration-example-8"></a>

## 配置示例

```nginx
location / {
    autoindex on;
}
```

<a id="directives-9"></a>

## 指令

<a id="index-0"></a>

<a id="autoindex"></a>

### autoindex

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `autoindex` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `autoindex off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

启用或禁用目录列表输出。

<a id="index-1"></a>

<a id="autoindex-exact-size"></a>

### autoindex_exact_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `autoindex_exact_size` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `autoindex_exact_size on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

对于 HTML [格式](#autoindex-format)，指定目录列表中是否输出精确的文件大小，或者将其四舍五入到千字节、兆字节和千兆字节。

<a id="index-2"></a>

<a id="autoindex-format"></a>

### autoindex_format

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `autoindex_format` `html` | `xml` | `json` | `jsonp`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------|
| 默认值                                                                                  | `autoindex_format html;`                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                  |

设置目录列表的格式。

当使用 JSONP 格式时，回调函数的名称通过 `callback` 请求参数设置。如果参数缺失或为空值，则使用 JSON 格式。

XML 输出可以通过 [XSLT](https://cn.angie.software//angie/docs/configuration/modules/http/http_xslt.md#http-xslt) 模块进行转换。

### 输出格式

响应中的对象字段包含以下数据：

| 字段      | 描述                                                                     |
|---------|------------------------------------------------------------------------|
| `name`  | 文件或目录名称                                                                |
| `type`  | 对象类型：`file` 或 `directory`                                              |
| `size`  | 根据 [autoindex_exact_size](#autoindex-exact-size) 的对象大小；<br/>对于目录 — `0` |
| `mtime` | Unix 时间格式的最后修改时间                                                       |

HTML

```html
<html>
<head>
    <title>Index of /files/</title>
</head>
<body>
    <h1>Index of /files/</h1>
    <hr>
    <pre>
            <a href="../">../</a>
            <a href="example.txt">example.txt</a>               12-Jun-2025 14:21    1234
            <a href="image.png">image.png</a>                   12-Jun-2025 14:21    4321
            </pre>
    <hr>
</body>
</html>
```

XML

```xml
<?xml version="1.0" encoding="UTF-8"?>
<listing>
<file>
    <name>example.txt</name>
    <type>file</type>
    <size>1234</size>
    <mtime>2025-06-12T14:21:00Z</mtime>
</file>
<file>
    <name>image.png</name>
    <type>file</type>
    <size>4321</size>
    <mtime>2025-06-12T14:21:00Z</mtime>
</file>
</listing>
```

JSON

```json
[
{
    "name": "example.txt",
    "type": "file",
    "size": 1234,
    "mtime": "2025-06-12T14:21:00Z"
},
{
    "name": "image.png",
    "type": "file",
    "size": 4321,
    "mtime": "2025-06-12T14:21:00Z"
}
]
```

JSONP

```javascript
callback([
{
    "name": "example.txt",
    "type": "file",
    "size": 1234,
    "mtime": "2025-06-12T14:21:00Z"
},
{
    "name": "image.png",
    "type": "file",
    "size": 4321,
    "mtime": "2025-06-12T14:21:00Z"
}
]);
```

<a id="index-3"></a>

<a id="autoindex-localtime"></a>

### autoindex_localtime

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `autoindex_localtime` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `autoindex_localtime off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

对于 HTML [格式](#autoindex-format)，指定目录列表中的时间是以本地时区还是以 UTC 输出。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_browser.md

<!-- review: finished -->

<a id="http-browser"></a>

# Browser

该模块创建的变量值依赖于:samp:User-Agent 请求头字段的值。

<a id="variables"></a>

## 变量

<a id="v-modern-browser"></a>

### `$modern_browser`

如果识别为现代浏览器，则等于由 [modern_browser_value](#modern-browser-value) 指令设置的值；

<a id="v-ancient-browser"></a>

### `$ancient_browser`

如果识别为古老浏览器，则等于由 [ancient_browser_value](#ancient-browser-value) 指令设置的值；

<a id="v-msie"></a>

### `$msie`

如果识别为任何版本的 MSIE 浏览器，则等于"1"。

<a id="configuration-example-9"></a>

## 配置示例

<a id="choosing-an-index-file"></a>

### 选择索引文件：

```nginx
modern_browser_value "modern.";

modern_browser msie      5.5;
modern_browser gecko     1.0.0;
modern_browser opera     9.0;
modern_browser safari    413;
modern_browser konqueror 3.0;

index index.${modern_browser}html index.html;
```

<a id="redirection-for-old-browsers"></a>

### 为旧浏览器重定向：

```nginx
modern_browser msie      5.0;
modern_browser gecko     0.9.1;
modern_browser opera     8.0;
modern_browser safari    413;
modern_browser konqueror 3.0;

modern_browser unlisted;

ancient_browser Links Lynx netscape4;

if ($ancient_browser) {
    rewrite ^ /ancient.html;
}
```

<a id="directives-10"></a>

## 指令

<a id="index-0"></a>

<a id="ancient-browser"></a>

### ancient_browser

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ancient_browser` string ...;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认                                                                                   | —                               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

如果在:samp:User-Agent 请求头字段中找到任何指定的子字符串，则该浏览器将被视为古老。特殊字符串"netscape4"对应于正则表达式"^Mozilla/[1-4]"。

<a id="index-1"></a>

<a id="ancient-browser-value"></a>

### ancient_browser_value

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ancient_browser_value` string;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认                                                                                   | `ancient_browser_value 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

为 [$ancient_browser](#v-ancient-browser) 变量设置值。

<a id="index-2"></a>

<a id="modern-browser"></a>

### modern_browser

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `modern_browser` browser version;<br/><br/>`modern_browser` `unlisted`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------------|
| 默认                                                                                   | —                                                                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                    |

指定从哪个版本开始浏览器被视为现代。浏览器可以是以下任意一个：`msie`、`gecko` （基于 Mozilla 的浏览器）、`opera`、`safari` 或 `konqueror`。

版本可以采用以下格式指定：X、X.X、X.X.X 或 X.X.X.X。每种格式的最大值分别为 4000、4000.99、4000.99.99 和 4000.99.99.99。

特殊值 `unlisted` 指定如果浏览器未在 modern_browser 和 [ancient_browser](#id6) 指令中列出，则视为现代浏览器。否则，该浏览器将被视为古老。如果请求未在头中提供:samp:User-Agent 字段，则该浏览器被视为未列出。

<a id="index-3"></a>

<a id="modern-browser-value"></a>

### modern_browser_value

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `modern_browser_value` string;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认                                                                                   | `modern_browser_value 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

为 [$modern_browser](#v-modern-browser) 变量设置值。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_charset.md

<!-- review: finished -->

<a id="http-charset"></a>

# Charset

该模块将指定的字符集添加到:samp:Content-Type 响应头字段。此外，该模块可以在某些限制条件下将数据从一种字符集转换为另一种字符集：

* 转换是单向进行的——从服务器到客户端，
* 只能转换单字节字符集，
* 或单字节字符集与 UTF-8 之间的转换。

<a id="configuration-example-10"></a>

## 配置示例

```nginx
include        conf/koi-win;

charset        windows-1251;
source_charset koi8-r;
```

<a id="directives-11"></a>

## 指令

<a id="index-0"></a>

<a id="charset"></a>

### charset

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `charset` charset | `off`;             |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认                                                                                   | `charset off;`                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

将指定的字符集添加到:samp:Content-Type 响应头字段。如果该字符集与 [source_charset](#source-charset) 指令中指定的字符集不同，则会执行转换。

参数 `off` 取消将字符集添加到:samp:Content-Type 响应头字段。

字符集可以通过变量定义：

```nginx
charset $charset;
```

在这种情况下，变量的所有可能值必须至少在配置中以 [charset_map](#charset-map)、[charset](#id3) 或 [source_charset](#source-charset) 指令的形式出现一次。对于 `utf-8`、`windows-1251` 和 `koi8-r` 字符集，只需在配置中包含 `conf/koi-win`、`conf/koi-utf` 和 `conf/win-utf` 文件。对于其他字符集，只需创建一个虚构的转换表即可，例如：

```nginx
charset_map iso-8859-5 _ { }
```

此外，可以在:samp:X-Accel-Charset\`响应头字段中设置字符集。可以使用 :ref:\`proxy_ignore_headers、[fastcgi_ignore_headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-ignore-headers)、[uwsgi_ignore_headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-ignore-headers)、[scgi_ignore_headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-ignore-headers) 和 [grpc_ignore_headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_grpc.md#grpc-ignore-headers) 指令禁用此功能。

<a id="index-1"></a>

<a id="charset-map"></a>

### charset_map

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `charset_map` charset1 charset2  { ... }   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认                                                                                   | —                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                       |

描述从一种字符集到另一种字符集的转换表。使用相同的数据构建反向转换表。字符编码以十六进制给出。在范围 80-FF 中缺失的字符用 "?" 替代。从 UTF-8 转换时，在单字节字符集中缺失的字符用 "&#XXXX;" 替代。

示例：

```nginx
charset_map koi8-r windows-1251 {
    C0 FE ; # 小 ю
    C1 E0 ; # 小 а
    C2 E1 ; # 小 б
    C3 F6 ; # 小 ц
}
```

在描述到 UTF-8 的转换表时，UTF-8 字符集的代码应在第二列给出，例如：

```nginx
charset_map koi8-r utf-8 {
    C0 D18E ; # 小 ю
    C1 D0B0 ; # 小 а
    C2 D0B1 ; # 小 б
    C3 D186 ; # 小 ц
}
```

从 `koi8-r` 到 `windows-1251`，以及从 `koi8-r` 和 `windows-1251` 到 `utf-8` 的完整转换表在分发文件 `conf/koi-win`、`conf/koi-utf` 和 `conf/win-utf` 中提供。

<a id="index-2"></a>

<a id="charset-types"></a>

### charset_types

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `charset_types` mime-type ...;                                                                             |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|
| 默认                                                                                   | `charset_types text/html text/xml text/plain text/vnd.wap.wml application/javascript application/rss+xml;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                     |

使模块在处理指定 MIME 类型的响应时生效，除了 `text/html` 之外。特殊值 `*` 匹配任何 MIME 类型。

<a id="index-3"></a>

<a id="override-charset"></a>

### override_charset

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `override_charset` `on` | `off`;       |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认                                                                                   | `override_charset off;`                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

确定是否应对从代理或 FastCGI/uwsgi/SCGI/gRPC 服务器接收到的响应进行转换，当这些响应已在:samp:Content-Type 响应头字段中携带字符集时。如果启用转换，则使用接收到的响应中指定的字符集作为源字符集。

#### NOTE
如果在子请求中收到响应，则始终会将响应字符集转换为主请求字符集，而不管 override_charset 指令的设置。

<a id="index-4"></a>

<a id="source-charset"></a>

### source_charset

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `source_charset` charset;              |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认                                                                                   | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

定义响应的源字符集。如果该字符集与 [charset](#id3) 指令中指定的字符集不同，则会执行转换。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_dav.md

<!-- review: finished -->

<a id="http-dav"></a>

# DAV

该模块旨在通过 WebDAV 协议实现文件管理自动化。模块处理 HTTP 和 WebDAV 方法：PUT、DELETE、MKCOL、COPY 和 MOVE。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，默认不包含该模块；需要通过 `‑‑with‑http_dav_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 来启用。

在来自 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的包和镜像中，该模块包含在构建中。

#### NOTE
需要其他 WebDAV 方法才能操作的 WebDAV 客户端将无法与此模块一起使用。

<a id="configuration-example-11"></a>

## 配置示例

```nginx
location / {
    root                  /data/www;

    client_body_temp_path /data/client_temp;

    dav_methods PUT DELETE MKCOL COPY MOVE;

    create_full_put_path  on;
    dav_access            group:rw  all:r;

    limit_except GET {
        allow 192.168.1.0/32;
        deny  all;
    }
}
```

<a id="directives-12"></a>

## 指令

<a id="index-0"></a>

<a id="create-full-put-path"></a>

### create_full_put_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `create_full_put_path` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `create_full_put_path off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

WebDAV 规范仅允许在已存在的目录中创建文件。此指令允许创建所有需要的中间目录。

<a id="index-1"></a>

<a id="dav-access"></a>

### dav_access

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `dav_access` users:permissions ...;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `dav_access user:rw;`                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

为新创建的文件和目录设置访问权限，例如：

```nginx
dav_access user:rw group:rw all:r;
```

如果指定了任一组或所有访问权限，则可以省略用户权限：

```nginx
dav_access group:rw all:r;
```

<a id="index-2"></a>

<a id="dav-methods"></a>

### dav_methods

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `dav_methods` `off` | method ...;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `dav_methods off;`                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

允许指定的 HTTP 和 WebDAV 方法。参数 `off` 拒绝所有此模块处理的方法。支持以下方法：PUT、DELETE、MKCOL、COPY 和 MOVE。

使用 PUT 方法上传的文件首先被写入临时文件，然后文件被重命名。从版本 0.8.9 开始，临时文件和持久存储可以放在不同的文件系统上。但请注意，在这种情况下，文件是在两个文件系统之间复制，而不是便宜的重命名操作。因此建议在任何给定的 `location` 中，保存的文件和由 [client_body_temp_path](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-body-temp-path) 指令设置的临时文件目录放在同一个文件系统中。

使用 PUT 方法创建文件时，可以通过在 `Date` 头字段中传递修改日期来指定。

<a id="index-3"></a>

<a id="min-delete-depth"></a>

### min_delete_depth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `min_delete_depth` number;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `min_delete_depth 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

允许 DELETE 方法删除文件，前提是请求路径中的元素数量不小于指定的数量。例如，指令

```nginx
min_delete_depth 4;
```

允许删除以下请求的文件

```console
/users/00/00/name
/users/00/00/name/pic.jpg
/users/00/00/page.html
```

并拒绝删除

```console
/users/00/00
```


# https://cn.angie.software/angie/docs/configuration/modules/http/http_docker.md

<!-- review: reviewed -->

<a id="http-docker"></a>

# Docker

该模块基于 Docker 容器标签，在 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 和 [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-upstream) 上下文中提供代理服务器组的动态配置。
要使该功能正常工作，必须在组中配置共享内存区域（参见 [http](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-zone) 和 [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-zone) 的 `zone` 说明）。

#### NOTE
该模块支持与 Docker 及其替代品（如 Podman）配合使用，这些替代品实现了兼容的 API。

该模块通过 API 连接到 Docker 守护进程，与其交互的方法由 [docker_endpoint](#docker-endpoint) 指令指定。
在获取正在运行的容器列表后，Angie 会分析它们是否存在合适的 [标签](#docker-labels)。
如果容器描述中包含带有端口的标签，则该容器的地址和端口，以及该容器其他标签中的参数，将自动添加到 Angie 配置中相应的 `upstream` 块。

#### NOTE
同一个容器可以添加到多个 `upstream` 组。
要实现这一点，只需指定多组具有不同组名和端口的标签即可。

这在容器在不同端口上运行多个不同服务时特别有用——每个服务可以关联到自己的组。

然后，该模块订阅容器生命周期事件，并开始在不重新加载 Angie 的情况下更新代理服务器配置：

- 当启动带有合适标签的容器时，其内部 IP 地址将添加到指定的组；
- 当停止或删除容器时，它会自动从组中移除；
- 当使用 **docker pause** 命令暂停容器时，服务器被标记为 `down`，使用 **docker unpause** 时——标记为 `up`。

<a id="configuration-example-12"></a>

## 配置示例

该模块的指令始终位于 `http` 上下文中，但代理服务器组可以在 `http` 上下文和 `stream` 上下文中定义。

`http` 的配置示例：

```nginx
http {

    # 连接选项示例：
    # docker_endpoint http://127.0.0.1:2375;
    # docker_endpoint https://127.0.0.1:2376;
    docker_endpoint unix:/var/run/docker.sock;

    # Docker 响应缓冲区最大大小（可选）
    # docker_max_object_size 128k;

    upstream u {

        zone z 1m; # 需要共享内存区域
    }

    server {

        listen 80;
        server_name example.com;

        location / {

            proxy_pass http://u;
        }
    }
}
```

stream 上下文中的类似配置：

```nginx
http {

    # 连接选项示例：
    # docker_endpoint http://127.0.0.1:2375;
    # docker_endpoint https://127.0.0.1:2376;
    docker_endpoint unix:/var/run/docker.sock;

    # Docker 响应缓冲区最大大小（可选）
    # docker_max_object_size 128k;
}

stream {

    upstream u {

        zone z 1m;
    }

    server {

        listen 12345;
        proxy_pass u;
    }
}
```

收到容器事件后，Angie 会查找形式为 `angie.http.upstreams.<name>.port=<port>` （用于 HTTP 上下文）或 `angie.stream.upstreams.<name>.port=<port>` （用于 stream 上下文）的标签。
当存在标签时，容器在指定 Docker 网络中的地址（如果未指定 `angie.network` 标签，则为第一个可用的地址）将添加到相应的代理服务器组。

如果容器停止或被删除，服务器将从组中移除；如果容器被暂停，服务器将被标记为 `down`。

Angie 识别的带有标签的 `docker-compose.yml` 文件片段：

```yaml
services:
  myapp:
    image: myapp:latest
    labels:
      - "angie.http.upstreams.u.port=8080"
      - "angie.network=my_bridge"
      - "angie.http.upstreams.u.weight=2"
      - "angie.http.upstreams.u.max_conns=50"
      - "angie.http.upstreams.u.max_fails=3"
      - "angie.http.upstreams.u.fail_timeout=10s"
      - "angie.http.upstreams.u.backup=true"
```

<a id="docker-labels"></a>

## 标签

标签在代理服务器组中指定服务器参数，类似于 `server` 指令的参数：

| 标签                                                         | 用途                                      |
|------------------------------------------------------------|-----------------------------------------|
| `angie.(http|stream).upstreams.<name>.port=<port>`  *（必需）* | Angie 将连接到的容器端口；容器本身被添加到名为 `<name>` 的组。 |
| `angie.network=<docker-network>`                           | 用于获取容器 IP 地址的 Docker 网络名称。              |
| `angie.(http|stream).upstreams.<name>.weight=<n>`          | `weight` 参数的值。                          |
| `angie.(http|stream).upstreams.<name>.max_conns=<n>`       | 最大并发连接数（`max_conns`）。                   |
| `angie.(http|stream).upstreams.<name>.max_fails=<n>`       | 失败尝试阈值（`max_fails`）。                    |
| `angie.(http|stream).upstreams.<name>.fail_timeout=<t>`    | 计算失败尝试的时间间隔（`fail_timeout`）。            |
| `angie.(http|stream).upstreams.<name>.backup=true|false`   | 将服务器标记为 `backup`。                       |
| `angie.(http|stream).upstreams.<name>.sid=<string>`        | 为代理服务器设置自定义服务器标识符（`sid`）。               |
| `angie.(http|stream).upstreams.<name>.slow_start=<time>`   | 启用具有可配置时间段的 `slow_start` 模式。            |

<a id="directives-13"></a>

## 指令

<a id="index-0"></a>

<a id="docker-endpoint"></a>

### docker_endpoint

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `docker_endpoint` `URL`;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | —                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                       |

指定连接到 Docker 守护进程的方法并启用容器事件跟踪。
支持以下选项：

| `unix:/var/run/docker.sock`            | 通过 Unix 套接字连接（例如 `/var/run/docker.sock`）。   |
|----------------------------------------|---------------------------------------------|
| `http://host:port`、`https://host:port` | 通过 HTTP 或 HTTPS 连接到远程 Docker API。           |

可以使用 [client](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client) 上下文进一步配置连接，该模块在其中添加了两个命名的 `location` 块：

- `@docker_events` 用于接收容器事件；
- `@docker_containers` — 用于获取容器信息。

默认情况下，它们包含带有连接地址的 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass) 指令以及其他几个最佳默认设置，可以向其中添加 [代理](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy) 模块的其他设置。

如果指定了该指令，Angie 将使用指定的方法打开到 Docker 的连接，请求正在运行的容器列表，分析它们的标签并处理所有后续容器事件，根据标签在代理服务器组中添加或删除服务器。

<a id="index-1"></a>

<a id="docker-max-object-size"></a>

### docker_max_object_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `docker_max_object_size` `<size>`;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `64k`                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                 |

设置用于 Docker 请求的 JSON 响应和容器事件流的最大缓冲区大小。

- 对于常规请求（API 版本、容器列表、容器信息）：整个响应必须适合缓冲区，否则会发生错误。
- 对于容器事件，使用流式处理并重用缓冲区，这允许处理无限的事件流。

典型值 `64k` 足以容纳大约 25 个容器。

当发生 Docker API 连接错误或响应处理错误时，该模块会在特定时间间隔自动重试。
获取特定容器信息的最大重试次数限制为两次  *额外* 尝试；之后，该模块将停止对该容器的尝试。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_empty_gif.md

<!-- review: finished -->

<a id="http-empty-gif"></a>

# Empty GIF

该模块发出单像素透明 GIF。

<a id="configuration-example-13"></a>

## 配置示例

```nginx
location = /_.gif {
    empty_gif;
}
```

<a id="directives-14"></a>

## 指令

<a id="index-0"></a>

<a id="empty-gif"></a>

### empty_gif

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `empty_gif`;   |
|--------------------------------------------------------------------------------------|----------------|
| 默认                                                                                   | —              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location       |

在包含的 location 中启用发出单像素透明 GIF。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_fastcgi.md

<!-- review: finished -->

<a id="http-fastcgi"></a>

# FastCGI

该模块允许将请求传递给 FastCGI 服务器。

<a id="configuration-example-14"></a>

## 配置示例

```nginx
location / {
    fastcgi_pass  localhost:9000;
    fastcgi_index index.php;

    fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
    fastcgi_param QUERY_STRING    $query_string;
    fastcgi_param REQUEST_METHOD  $request_method;
    fastcgi_param CONTENT_TYPE    $content_type;
    fastcgi_param CONTENT_LENGTH  $content_length;
}
```

<a id="directives-15"></a>

## 指令

<a id="index-0"></a>

<a id="fastcgi-bind"></a>

### fastcgi_bind

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_bind` address [`transparent`] | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------|
| 默认值                                                                                  | —                                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                            |

使到 FastCGI 服务器的出站连接源自指定的本地 IP 地址及可选端口。参数值可以包含变量。特殊值 `off` 取消从上一配置级别继承的 fastcgi_bind 指令的效果,允许系统自动分配本地 IP 地址和端口。

`transparent` 参数允许到 FastCGI 服务器的出站连接源自非本地 IP 地址,例如来自客户端的真实 IP 地址:

```nginx
fastcgi_bind $remote_addr transparent;
```

要使此参数生效,
Angie 工作进程通常需要以
[超级用户](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 权限运行。
在 Linux 上,这不是必需的:
如果指定了 `transparent` 参数,
工作进程会从主进程继承 CAP_NET_RAW 能力。

#### NOTE
还应配置内核路由表
以拦截来自 FastCGI 服务器的网络流量。

<a id="index-1"></a>

<a id="fastcgi-buffer-size"></a>

### fastcgi_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_buffer_size` size;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `fastcgi_buffer_size 4k|8k;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

设置用于读取从 FastCGI 服务器接收的响应的第一部分的缓冲区大小。这部分通常包含一个小的响应头。默认情况下,缓冲区大小等于一个内存页。根据平台不同,这可能是 4K 或 8K。但它可以设置得更小。

<a id="index-2"></a>

<a id="fastcgi-buffering"></a>

### fastcgi_buffering

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_buffering` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `fastcgi_buffering on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

启用或禁用来自 FastCGI 服务器的响应的缓冲。

| `on`   | Angie 尽快从 FastCGI 服务器接收响应,将其保存到由 [fastcgi_buffer_size](#fastcgi-buffer-size) 和 [fastcgi_buffers](#fastcgi-buffers) 指令设置的缓冲区中。向客户端发送会并行进行:已填满的缓冲区会被传递用于发送,但其总大小受 [fastcgi_busy_buffers_size](#fastcgi-busy-buffers-size) 限制。如果缓冲区未被完全填满,则不会被传递用于发送,除非它包含响应的最后一部分。因此,当需要即时传输每几个字节时,缓冲读取并不适合。如果整个响应无法放入内存,则可以将其中一部分保存到磁盘上的 [临时文件](#fastcgi-temp-path) 中。写入临时文件由 [fastcgi_max_temp_file_size](#fastcgi-max-temp-file-size) 和 [fastcgi_temp_file_write_size](#fastcgi-temp-file-write-size) 指令控制。   |
|--------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 响应在接收到时立即传递给客户端。Angie 以"读取 — 发送"的循环工作,不会等待缓冲区完全填满:例如从 4K 缓冲区读取到 10 字节时就会立即发送。同时,如果整个响应可以放入缓冲区,Angie 可以完整读取它。Angie 一次可以从服务器接收的数据的最大大小由 [fastcgi_buffer_size](#fastcgi-buffer-size) 指令设置。使用 `off` 时,:ref:fastcgi_limit_rate 不生效。                                                                                                                                                                                                                                                                 |

还可以通过在 `X-Accel-Buffering` 响应头字段中传递 "yes" 或 "no" 来启用或禁用缓冲。可以使用 [fastcgi_ignore_headers](#fastcgi-ignore-headers) 指令禁用此功能。

<a id="index-3"></a>

<a id="fastcgi-buffers"></a>

### fastcgi_buffers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_buffers` number size;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `fastcgi_buffers 8 4k|8k;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

设置用于从 FastCGI 服务器读取响应的缓冲区的数量和大小,针对单个连接。

默认情况下,缓冲区大小等于一个内存页。根据平台不同,这可能是 4K 或 8K。

<a id="index-4"></a>

<a id="fastcgi-busy-buffers-size"></a>

### fastcgi_busy_buffers_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_busy_buffers_size` size;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `fastcgi_busy_buffers_size 8k|16k;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

当启用来自 FastCGI 服务器的响应的 [缓冲](#fastcgi-buffering) 时,限制在响应尚未完全读取时可以忙于向客户端发送响应的缓冲区的总大小。同时,其余缓冲区可用于读取响应,如果需要,还可以将部分响应缓冲到临时文件。默认情况下,大小受 [fastcgi_buffer_size](#fastcgi-buffer-size) 和 [fastcgi_buffers](#fastcgi-buffers) 指令设置的两个缓冲区大小的限制。

<a id="index-5"></a>

<a id="fastcgi-cache"></a>

### fastcgi_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache` zone | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `fastcgi_cache off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

定义用于缓存的共享内存区域。同一区域可以在多个地方使用。参数值可以包含变量。`off` 参数禁用从上一配置级别继承的缓存。

<a id="index-6"></a>

<a id="fastcgi-cache-background-update"></a>

### fastcgi_cache_background_update

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_background_update` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------|
| 默认值                                                                                  | `fastcgi_cache_background_update off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                            |

允许启动后台子请求来更新过期的缓存项,同时将陈旧的缓存响应返回给客户端。请注意,必须 [允许](#fastcgi-cache-use-stale-updating) 在更新时使用陈旧的缓存响应。

<a id="index-7"></a>

<a id="fastcgi-cache-bypass"></a>

### fastcgi_cache_bypass

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_bypass` string ...;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | —                                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

定义不从缓存中获取响应的条件。如果字符串参数中至少有一个值不为空且不等于 "0",则不会从缓存中获取响应:

```nginx
fastcgi_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
fastcgi_cache_bypass $http_pragma    $http_authorization;
```

可以与 [fastcgi_no_cache](#fastcgi-no-cache) 指令一起使用。

<a id="index-8"></a>

<a id="fastcgi-cache-key"></a>

### fastcgi_cache_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_key` string;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | —                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

定义缓存的键,例如

```nginx
fastcgi_cache_key localhost:9000$request_uri;
```

<a id="index-9"></a>

<a id="fastcgi-cache-lock"></a>

### fastcgi_cache_lock

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_lock` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `fastcgi_cache_lock off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

启用后,一次只允许一个请求通过将请求传递给 FastCGI 服务器来填充根据 [fastcgi_cache_key](#fastcgi-cache-key) 指令标识的新缓存元素。同一缓存元素的其他请求将等待响应出现在缓存中或此元素的缓存锁被释放,最长等待时间由 [fastcgi_cache_lock_timeout](#fastcgi-cache-lock-timeout) 指令设置。

<a id="index-10"></a>

<a id="fastcgi-cache-lock-age"></a>

### fastcgi_cache_lock_age

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_lock_age` time;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `fastcgi_cache_lock_age 5s;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

如果传递给 FastCGI 服务器以填充新缓存元素的最后一个请求在指定时间内未完成,则可以再传递一个请求给 FastCGI 服务器。

<a id="index-11"></a>

<a id="fastcgi-cache-lock-timeout"></a>

### fastcgi_cache_lock_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_lock_timeout` time;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `fastcgi_cache_lock_timeout 5s;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

设置 [fastcgi_cache_lock](#fastcgi-cache-lock) 的超时时间。当超时时间到期时,请求将被传递给 FastCGI 服务器,但响应不会被缓存。

<a id="index-12"></a>

<a id="fastcgi-cache-max-range-offset"></a>

### fastcgi_cache_max_range_offset

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_max_range_offset` number;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | —                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                     |

为字节范围请求设置以字节为单位的偏移量。如果范围超出偏移量,范围请求将被传递给 FastCGI 服务器,且响应不会被缓存。

<a id="index-13"></a>

<a id="fastcgi-cache-methods"></a>

### fastcgi_cache_methods

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_methods` `GET` | `HEAD` | `POST` ...;   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------|
| 默认值                                                                                  | `fastcgi_cache_methods GET HEAD;`                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                 |

如果客户端请求方法在此指令中列出,则响应将被缓存。"GET" 和 "HEAD" 方法始终会被添加到列表中,但建议显式指定它们。另请参阅 [fastcgi_no_cache](#fastcgi-no-cache) 指令。

<a id="index-14"></a>

<a id="fastcgi-cache-min-uses"></a>

### fastcgi_cache_min_uses

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_min_uses` number;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `fastcgi_cache_min_uses 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

设置请求次数,达到该次数后响应将被缓存。

#### WARNING
缓存元数据存储在共享内存中。手动删除缓存文件不会重置计数器,可能导致不可预测的行为。要完全重置缓存,请停止服务器,删除缓存目录,然后重新启动。

#### NOTE
第三方缓存清除模块(例如 [缓存清除](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge))仅删除文件,但不会重置 fastcgi_cache_min_uses 计数器。该指令旨在保护缓存免受不频繁请求的污染,在清除时重置计数器可能会对性能产生负面影响。

<a id="index-15"></a>

<a id="fastcgi-cache-path"></a>

### fastcgi_cache_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_path` path [`levels=`levels] [`use_temp_path=``on` | `off`] `keys_zone=`name:size [`inactive=`time] [`max_size=`size] [`min_free=`size] [`manager_files=`number] [`manager_sleep=`time] [`manager_threshold=`time] [`loader_files=`number] [`loader_sleep=`time] [`loader_threshold=`time];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                                                                                                                                                                                                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                                                                                                                                                                                       |

设置缓存的路径和其他参数。缓存数据存储在文件中。缓存中的键和文件名都是对代理 URL 应用 MD5 函数的结果。

`levels` 参数定义缓存的层次结构级别:从 1 到 3,每个级别接受值 1 或 2。例如,在以下配置中

```nginx
fastcgi_cache_path /data/angie/cache levels=1:2 keys_zone=one:10m;
```

缓存中的文件名将如下所示:

```nginx
/data/angie/cache/c/29/b7f54b2df7773722d382f4809d65029c
```

缓存的响应首先写入临时文件,然后重命名该文件。临时文件和缓存可以放在不同的文件系统上。但是,请注意,在这种情况下,文件将在两个文件系统之间复制,而不是进行廉价的重命名操作。因此,建议对于任何给定位置,将缓存和存放临时文件的目录放在同一文件系统上。

临时文件的目录基于 `use_temp_path` 参数设置。

| `on`   | 如果省略此参数或将其设置为值 `on`,将使用由给定位置的 [fastcgi_temp_path](#fastcgi-temp-path) 指令设置的目录。   |
|--------|----------------------------------------------------------------------------------|
| `off`  | 临时文件将直接放在缓存目录中。                                                                  |

此外,所有活动键和数据信息都存储在共享内存区域中,其名称和大小由 `keys_zone` 参数配置。一兆字节的区域可以存储大约 8 千个键。缓存元数据存储在共享内存中。

在 `inactive` 参数指定的时间内未被访问的缓存数据将从缓存中删除,无论其新鲜度如何。

默认情况下,:samp:inactive 设置为 10 分钟。

特殊的 **缓存管理器** 进程监控最大缓存大小以及缓存所在文件系统的最小可用空间量。当超出大小或可用空间不足时,它会删除最近最少使用的数据。数据以迭代方式删除。

| `max_size`          | 最大缓存大小                               |
|---------------------|--------------------------------------|
| `min_free`          | 缓存所在文件系统的最小可用空间量                     |
| `manager_files`     | 限制一次迭代期间要删除的项目数<br/><br/>默认值为 `100`。 |
| `manager_threshold` | 限制一次迭代的持续时间<br/><br/>默认值为 `200` 毫秒   |
| `manager_sleep`     | 配置迭代之间的暂停时间<br/><br/>默认值为 `50` 毫秒    |

Angie 启动一分钟后,特殊的 **缓存加载器** 进程被激活。它将存储在文件系统上的先前缓存数据的信息加载到缓存区域中。加载也以迭代方式完成。

| `loader_files`     | 一次迭代中要加载的最大缓存项目数<br/><br/>默认值:`100`   |
|--------------------|---------------------------------------|
| `loader_threshold` | 限制一次迭代的时间<br/><br/>默认值:`200` 毫秒       |
| `loader_sleep`     | 迭代之间保持暂停的时间<br/><br/>默认值:`50` 毫秒      |

<a id="index-16"></a>

<a id="fastcgi-cache-revalidate"></a>

### fastcgi_cache_revalidate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_revalidate` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | `fastcgi_cache_revalidate off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                     |

启用使用带有 `If-Modified-Since` 和 `If-None-Match` 头字段的条件请求重新验证过期的缓存项。

<a id="index-17"></a>

<a id="fastcgi-cache-use-stale"></a>

### fastcgi_cache_use_stale

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_use_stale` `error` | `timeout` | `invalid_header` | `updating` | `http_500` | `http_503` | `http_403` | `http_429` | `off` ...;   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `fastcgi_cache_use_stale off;`                                                                                                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                           |

确定在与 FastCGI 服务器通信期间发生错误时,在哪些情况下可以使用陈旧的缓存响应。该指令的参数与 [fastcgi_next_upstream](#fastcgi-next-upstream) 指令的参数匹配。

| `error`    | 如果无法选择 FastCGI 服务器来处理请求,则允许使用陈旧的缓存响应。                              |
|------------|--------------------------------------------------------------------|
| `updating` | 一个附加参数,如果缓存响应当前正在更新,则允许使用陈旧的缓存响应。这可以在更新缓存数据时最小化对 FastCGI 服务器的访问次数。 |

也可以直接在响应头中允许使用陈旧的缓存响应,在响应变陈旧后的指定秒数内。

* `Cache-Control` 头字段的 [stale-while-revalidate](https://datatracker.ietf.org/doc/html/rfc5861#section-3) 扩展允许在缓存响应当前正在更新时使用陈旧的缓存响应。
* `Cache-Control` 头字段的 [stale-if-error](https://datatracker.ietf.org/doc/html/rfc5861#section-4) 扩展允许在发生错误时使用陈旧的缓存响应。

#### NOTE
此方法的优先级低于设置指令参数。

为了在填充新缓存元素时最小化对 FastCGI 服务器的访问次数,可以使用 [fastcgi_cache_lock](#fastcgi-cache-lock) 指令。

<a id="index-18"></a>

<a id="fastcgi-cache-valid"></a>

### fastcgi_cache_valid

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_cache_valid` [code ...] time;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | —                                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

为不同的响应代码设置缓存时间。例如,以下指令

```nginx
fastcgi_cache_valid 200 302 10m;
fastcgi_cache_valid 404      1m;
```

为代码 200 和 302 的响应设置 10 分钟的缓存,为代码 404 的响应设置 1 分钟的缓存。

如果只指定了缓存时间,

```nginx
fastcgi_cache_valid 5m;
```

则只缓存 200、301 和 302 响应。

此外,可以使用 `any` 参数指定缓存任何响应:

```nginx
fastcgi_cache_valid 200 302 10m;
fastcgi_cache_valid 301      1h;
fastcgi_cache_valid any      1m;
```

#### NOTE
缓存参数也可以直接在响应头中设置。这比使用指令设置缓存时间具有更高的优先级。

* `X-Accel-Expires` 头字段以秒为单位设置响应的缓存时间。零值将禁用响应的缓存。如果值以 @ 前缀开头,则设置自 Epoch 以来的绝对时间(以秒为单位),直到该时间响应可以被缓存。
* 如果头不包含 `X-Accel-Expires` 字段,则可以在头字段 `Expires` 或 `Cache-Control` 中设置缓存参数。
* 如果头包含 `Set-Cookie` 字段,则此类响应将不会被缓存。
* 如果头包含具有特殊值 "\*" 的 `Vary` 字段,则此类响应将不会被缓存。如果头包含具有其他值的 `Vary` 字段,则此类响应将根据相应的请求头字段进行缓存。

可以使用 [fastcgi_ignore_headers](#fastcgi-ignore-headers) 指令禁用对这些响应头字段中的一个或多个的处理。

<a id="index-19"></a>

<a id="fastcgi-catch-stderr"></a>

### fastcgi_catch_stderr

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_catch_stderr` string;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

设置要在从 FastCGI 服务器接收的响应的错误流中搜索的字符串。如果找到该字符串,则认为 FastCGI 服务器返回了 [无效](#fastcgi-next-upstream) 响应。这允许在 Angie 中处理应用程序错误,例如:

```nginx
location /php/ {
    fastcgi_pass backend:9000;
    ...
    fastcgi_catch_stderr "PHP Fatal error";
    fastcgi_next_upstream error timeout invalid_header;
}
```

<a id="index-20"></a>

<a id="fastcgi-connect-timeout"></a>

### fastcgi_connect_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_connect_timeout` time;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `fastcgi_connect_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

定义与 FastCGI 服务器建立连接的超时时间。需要注意的是,此超时时间通常不能超过 75 秒。

<a id="index-21"></a>

<a id="fastcgi-connection-drop"></a>

### fastcgi_connection_drop

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_connection_drop` time | `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------------------|
| 默认值                                                                                  | `fastcgi_connection_drop off;`                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                           |

启用在代理服务器从组中删除或通过 [重新解析](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve) 进程或 [API 命令](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config-methods) `DELETE` 标记为永久不可用后,终止到该服务器的所有连接。

当为客户端或代理服务器处理下一个读取或写入事件时,连接将被终止。

设置 time 启用连接终止 [超时](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax);设置为 `on` 时,连接将立即断开。

<a id="index-22"></a>

<a id="fastcgi-force-ranges"></a>

### fastcgi_force_ranges

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_force_ranges` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `fastcgi_force_ranges off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

无论 FastCGI 服务器响应中的 `Accept-Ranges` 字段如何,都为来自该服务器的缓存和非缓存响应启用字节范围支持。

<a id="index-23"></a>

<a id="fastcgi-hide-header"></a>

### fastcgi_hide_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_hide_header` field;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | —                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

默认情况下,Angie 不会将 FastCGI 服务器响应中的头字段 `Status` 和 `X-Accel-...` 传递给客户端。`fastcgi_hide_header` 指令设置不会被传递的其他字段。相反,如果需要允许传递字段,可以使用 [fastcgi_pass_header](#fastcgi-pass-header) 指令。

<a id="index-24"></a>

<a id="fastcgi-ignore-client-abort"></a>

### fastcgi_ignore_client_abort

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_ignore_client_abort` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | `fastcgi_ignore_client_abort off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                        |

确定当客户端在不等待响应的情况下关闭连接时,是否应关闭与 FastCGI 服务器的连接。

<a id="index-25"></a>

<a id="fastcgi-ignore-headers"></a>

### fastcgi_ignore_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_ignore_headers` field;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

禁用对 FastCGI 服务器某些响应头字段的处理。可以忽略以下字段：`X-Accel-Redirect`、`X-Accel-Expires`、`X-Accel-Limit-Rate`、`X-Accel-Buffering`、`X-Accel-Charset`、`Expires`、`Cache-Control`、`Set-Cookie` 和 `Vary`。

如果未禁用，处理这些头字段将产生以下效果：

* `X-Accel-Expires`、`Expires`、`Cache-Control`、`Set-Cookie` 和 `Vary` 设置响应缓存的 [参数](#fastcgi-cache-valid)；
* `X-Accel-Redirect` 执行到指定 URI 的 [内部重定向](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#internal)；
* `X-Accel-Limit-Rate` 设置向客户端传输响应的 [速率限制](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#limit-rate)；
* `X-Accel-Buffering` 启用或禁用响应的 [缓冲](#fastcgi-buffering)；
* `X-Accel-Charset` 设置响应所需的 [字符集](https://cn.angie.software//angie/docs/configuration/modules/http/http_charset.md#id3)。

<a id="index-26"></a>

<a id="fastcgi-index"></a>

### fastcgi_index

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_index` name;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | —                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location  |

设置将附加在以斜杠结尾的 URI 之后的文件名，该文件名将用于 [$fastcgi_script_name](#v-fastcgi-script-name) 变量的值。例如，使用以下设置

```nginx
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
```

对于 `/page.php` 请求，`SCRIPT_FILENAME` 参数将等于 `/home/www/scripts/php/page.php`，而对于 `/` 请求，它将等于 `/home/www/scripts/php/index.php`。

<a id="index-27"></a>

<a id="fastcgi-intercept-errors"></a>

### fastcgi_intercept_errors

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_intercept_errors` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | `fastcgi_intercept_errors off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                     |

确定代码大于或等于 300 的 FastCGI 服务器响应应该传递给客户端，还是被拦截并重定向到 Angie 以使用 [error_page](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#error-page) 指令进行处理。

<a id="index-28"></a>

<a id="fastcgi-keep-conn"></a>

### fastcgi_keep_conn

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_keep_conn` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `fastcgi_keep_conn off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

默认情况下，FastCGI 服务器将在发送响应后立即关闭连接。但是，当此指令设置为值 `on` 时，Angie 将指示 FastCGI 服务器保持连接打开。这对于到 FastCGI 服务器的 [keepalive](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-keepalive) 连接正常工作尤其必要。

<a id="index-29"></a>

<a id="fastcgi-limit-rate"></a>

### fastcgi_limit_rate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_limit_rate` rate;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `fastcgi_limit_rate 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

限制从代理服务器读取响应的速度。
rate 以每秒字节数为单位指定；可以使用变量。

| `0`   | 禁用速率限制   |
|-------|----------|

#### NOTE
该限制是针对每个请求设置的，因此如果 Angie 同时打开两个到 FastCGI 服务器的连接，总速率将是指定限制的两倍。该限制仅在启用 FastCGI 服务器响应的 [缓冲](#fastcgi-buffering) 时有效。

<a id="index-30"></a>

<a id="fastcgi-max-temp-file-size"></a>

### fastcgi_max_temp_file_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_max_temp_file_size` size;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `fastcgi_max_temp_file_size 1024m;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

当启用 FastCGI 服务器响应的 [缓冲](#fastcgi-buffering) 时，如果整个响应无法放入 [fastcgi_buffer_size](#fastcgi-buffer-size) 和 [fastcgi_buffers](#fastcgi-buffers) 指令设置的缓冲区，响应的一部分可以保存到临时文件中。该指令设置临时文件的最大大小。一次写入临时文件的数据大小由 [fastcgi_temp_file_write_size](#fastcgi-temp-file-write-size) 指令设置。

| `0`   | 禁用将响应缓冲到临时文件   |
|-------|----------------|

#### NOTE
此限制不适用于将被 [缓存](#fastcgi-cache) 或 [存储](#fastcgi-store) 到磁盘的响应。

<a id="index-31"></a>

<a id="fastcgi-next-upstream"></a>

### fastcgi_next_upstream

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_next_upstream` `error` | `timeout` | `invalid_header` | `http_500` | `http_503` | `http_403` | `http_404` | `http_429` | `non_idempotent` | `off` ...;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `fastcgi_next_upstream error timeout;`                                                                                                                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                                            |

指定在哪些情况下应将请求传递给下一个服务器：

| `error`          | 与服务器建立连接、向其传递请求或读取响应头时发生错误；                                                                                                                             |
|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
| `timeout`        | 与服务器建立连接、向其传递请求或读取响应头时发生超时；                                                                                                                             |
| `invalid_header` | 服务器返回空响应或无效响应；                                                                                                                                          |
| `http_500`       | 服务器返回代码为 500 的响应；                                                                                                                                       |
| `http_503`       | 服务器返回代码为 503 的响应；                                                                                                                                       |
| `http_403`       | 服务器返回代码为 403 的响应；                                                                                                                                       |
| `http_404`       | 服务器返回代码为 404 的响应；                                                                                                                                       |
| `http_429`       | 服务器返回代码为 429 的响应；                                                                                                                                       |
| `non_idempotent` | 通常，使用 [非幂等](https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.2) 方法<br/>（`POST`、`LOCK`、`PATCH`）的请求在已发送到上游服务器后不会传递给下一个服务器；<br/>启用此选项将明确允许重试此类请求； |
| `off`            | 禁用将请求传递给下一个服务器。                                                                                                                                         |

#### NOTE
应该注意的是，只有在尚未向客户端发送任何内容时，才可能将请求传递给下一个服务器。也就是说，如果在传输响应的过程中发生错误或超时，则无法修复此问题。

该指令还定义了什么被视为与服务器通信的 [失败尝试](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#max-fails)。

| `error`<br/><br/>`timeout`<br/><br/>`invalid_header`   | 始终被视为失败尝试，即使它们未在指令中指定   |
|--------------------------------------------------------|-------------------------|
| `http_500`<br/><br/>`http_503`<br/><br/>`http_429`     | 仅在指令中指定时才被视为失败尝试        |
| `http_403`<br/><br/>`http_404`                         | 从不被视为失败尝试               |

将请求传递给下一个服务器可以通过 [尝试次数](#fastcgi-next-upstream-tries) 和 [时间](#fastcgi-next-upstream-timeout) 进行限制。

<a id="index-32"></a>

<a id="fastcgi-next-upstream-timeout"></a>

### fastcgi_next_upstream_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_next_upstream_timeout` time;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `fastcgi_next_upstream_timeout 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

限制可以将请求传递给 [下一个服务器](#fastcgi-next-upstream) 的时间。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-33"></a>

<a id="fastcgi-next-upstream-tries"></a>

### fastcgi_next_upstream_tries

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_next_upstream_tries` number;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `fastcgi_next_upstream_tries 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

限制将请求传递给 [下一个服务器](#fastcgi-next-upstream) 的可能尝试次数。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-34"></a>

<a id="fastcgi-no-cache"></a>

### fastcgi_no_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_no_cache` string ...;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

定义响应不会保存到缓存的条件。如果字符串参数中至少有一个值不为空且不等于"0"，则响应将不会被保存：

```nginx
fastcgi_no_cache $cookie_nocache $arg_nocache$arg_comment;
fastcgi_no_cache $http_pragma    $http_authorization;
```

可以与 [fastcgi_cache_bypass](#fastcgi-cache-bypass) 指令一起使用。

<a id="index-35"></a>

<a id="fastcgi-param"></a>

### fastcgi_param

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_param` parameter value [`if_not_empty`];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------|
| 默认值                                                                                  | —                                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                              |

设置应传递给 FastCGI 服务器的参数。值可以包含文本、变量及其组合。当且仅当当前级别上没有定义 fastcgi_param 指令时，这些指令才从上一级配置继承。

#### NOTE
在 Angie 附带的标准 `fastcgi.conf` 和 `fastcgi_params` 文件中，
`REQUEST_METHOD` 被设置为 `$upstream_request_method`。
这确保当缓存将 `HEAD` 转换为 `GET` 时，
上游请求方法反映该转换。

以下示例显示了 PHP 所需的最小设置：

```nginx
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
fastcgi_param QUERY_STRING    $query_string;
```

SCRIPT_FILENAME 参数在 PHP 中用于确定脚本名称，QUERY_STRING 参数用于传递请求参数。

对于处理 POST 请求的脚本，还需要以下三个参数：

```nginx
fastcgi_param REQUEST_METHOD  $request_method;
fastcgi_param CONTENT_TYPE    $content_type;
fastcgi_param CONTENT_LENGTH  $content_length;
```

如果 PHP 使用 `--enable-force-cgi-redirect` 配置参数构建，则还应传递值为"200"的 REDIRECT_STATUS 参数：

```nginx
fastcgi_param REDIRECT_STATUS 200;
```

如果指令使用 `if_not_empty` 指定，则仅当参数值不为空时才会将该参数传递给服务器：

```nginx
fastcgi_param HTTPS           $https if_not_empty;
```

<a id="index-36"></a>

<a id="fastcgi-pass"></a>

### fastcgi_pass

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_pass` address;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | —                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location, if in location  |

设置 FastCGI 服务器的地址。地址可以指定为域名或 IP 地址以及端口：

```nginx
fastcgi_pass localhost:9000;
```

或作为 UNIX 域套接字路径：

```nginx
fastcgi_pass unix:/tmp/fastcgi.socket;
```

如果域名解析为多个地址，则所有地址都将以轮询方式使用。此外，地址可以指定为 [服务器组](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream)。

参数值可以包含变量。在这种情况下，如果地址指定为域名，则在描述的 [服务器组](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 中搜索该名称，如果未找到，则使用 [解析器](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 确定。

#### NOTE
If `fastcgi_pass` is placed in a `location` whose prefix ends with a slash
(for example, `location /name/`),
and the [auto_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#auto-redirect) directive is set to `default`,
requests without a trailing slash will be redirected (`/name -> /name/`).

<a id="index-37"></a>

<a id="fastcgi-pass-header"></a>

### fastcgi_pass_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_pass_header` field;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | —                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

允许将 FastCGI 服务器的 [原本被禁用的](#fastcgi-hide-header) 头字段传递给客户端。

<a id="index-38"></a>

<a id="fastcgi-pass-request-body"></a>

### fastcgi_pass_request_body

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_pass_request_body` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `fastcgi_pass_request_body on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

指示是否将原始请求体传递给 FastCGI 服务器。另请参阅 [fastcgi_pass_request_headers](#fastcgi-pass-request-headers) 指令。

<a id="index-39"></a>

<a id="fastcgi-pass-request-headers"></a>

### fastcgi_pass_request_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_pass_request_headers` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | `fastcgi_pass_request_headers on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                         |

指示是否将原始请求的头字段传递给 FastCGI 服务器。另请参阅 [fastcgi_pass_request_body](#fastcgi-pass-request-body) 指令。

<a id="index-40"></a>

<a id="fastcgi-read-timeout"></a>

### fastcgi_read_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_read_timeout` time;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `fastcgi_read_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

定义从 FastCGI 服务器读取响应的超时时间。超时仅在两次连续读取操作之间设置，而不是针对整个响应的传输。如果 FastCGI 服务器在此时间内没有传输任何内容，则连接会关闭。

<a id="index-41"></a>

<a id="fastcgi-request-buffering"></a>

### fastcgi_request_buffering

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_request_buffering` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `fastcgi_request_buffering on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

启用或禁用客户端请求体的缓冲。

| `on`   | 在将请求发送到 FastCGI 服务器之前,从客户端 [读取](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-body-buffer-size) 整个请求体。   |
|--------|---------------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 请求体在接收时立即发送到 FastCGI 服务器。在这种情况下,如果 Angie 已经开始发送请求体,则无法将请求传递到 [下一个服务器](#fastcgi-next-upstream)。                                              |

<a id="index-42"></a>

<a id="fastcgi-send-lowat"></a>

### fastcgi_send_lowat

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_send_lowat` size;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `fastcgi_send_lowat 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

如果该指令设置为非零值,Angie 将尝试通过使用 [kqueue](https://cn.angie.software//angie/docs/configuration/processing.md#kqueue) 方法的 NOTE_LOWAT 标志或 SO_SNDLOWAT 套接字选项(使用指定的大小),来最小化到 FastCGI 服务器的出站连接上的发送操作次数。

#### NOTE
此指令在 Linux、Solaris 和 Windows 上被忽略。

<a id="index-43"></a>

<a id="fastcgi-send-timeout"></a>

### fastcgi_send_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_send_timeout` time;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `fastcgi_send_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

设置向 FastCGI 服务器传输请求的超时时间。该超时仅在两次连续的写操作之间设置,而不是用于整个请求的传输。如果 FastCGI 服务器在此时间内没有接收到任何内容,连接将被关闭。

<a id="index-44"></a>

<a id="fastcgi-socket-keepalive"></a>

### fastcgi_socket_keepalive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_socket_keepalive` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | `fastcgi_socket_keepalive off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                     |

配置到 FastCGI 服务器的出站连接的 "TCP keepalive" 行为。

| `off`   | 默认情况下,套接字使用操作系统的设置。        |
|---------|----------------------------|
| `on`    | 为套接字启用 SO_KEEPALIVE 套接字选项。 |

<a id="index-45"></a>

<a id="fastcgi-split-path-info"></a>

### fastcgi_split_path_info

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_split_path_info` regex;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | —                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location                           |

定义一个正则表达式,用于捕获 [$fastcgi_path_info](#v-fastcgi-path-info) 变量的值。该正则表达式应该有两个捕获组:第一个成为 [$fastcgi_script_name](#v-fastcgi-script-name) 变量的值,第二个成为 [$fastcgi_path_info](#v-fastcgi-path-info) 变量的值。例如,使用以下设置

```default
location ~ ^(.+\.php)(.*)$ {
    fastcgi_split_path_info       ^(.+\.php)(.*)$;
    fastcgi_param SCRIPT_FILENAME /path/to/php$fastcgi_script_name;
    fastcgi_param PATH_INFO       $fastcgi_path_info;
```

对于 `/show.php/article/0001` 请求,\`SCRIPT_FILENAME\` 参数将等于 `/path/to/php/show.php`,
而 PATH_INFO 参数将等于 `/article/0001`。

<a id="index-46"></a>

<a id="fastcgi-store"></a>

### fastcgi_store

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_store` `on` | `off` | string;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `fastcgi_store off;`                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

启用将文件保存到磁盘。

| `on`   | 使用与 [alias](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#alias) 或 [root](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#root) 指令对应的路径保存文件。   |
|--------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 禁用保存文件                                                                                                                                                                                               |

此外,可以使用带变量的字符串显式设置文件名:

```nginx
fastcgi_store /data/www$original_uri;
```

文件的修改时间根据接收到的 `Last-Modified` 响应头字段设置。响应首先写入临时文件,然后重命名该文件。临时文件和持久存储可以放在不同的文件系统上。但是请注意,在这种情况下,文件将跨两个文件系统复制,而不是廉价的重命名操作。因此建议对于任何给定位置,保存的文件和由 [fastcgi_temp_path](#fastcgi-temp-path) 指令设置的临时文件目录都放在同一个文件系统上。

此指令可用于创建静态不变文件的本地副本,例如:

```nginx
location /images/ {
    root                 /data/www;
    error_page           404 = /fetch$uri;
}

location /fetch/ {
    internal;

    fastcgi_pass         backend:9000;
    ...

    fastcgi_store        on;
    fastcgi_store_access user:rw group:rw all:r;
    fastcgi_temp_path    /data/temp;

    alias                /data/www/;
}
```

<a id="index-47"></a>

<a id="fastcgi-store-access"></a>

### fastcgi_store_access

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_store_access` users:permissions ...;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------|
| 默认值                                                                                  | `fastcgi_store_access user:rw;`                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                          |

设置新创建的文件和目录的访问权限,例如:

```nginx
fastcgi_store_access user:rw group:rw all:r;
```

如果指定了任何 group 或 all 访问权限,则可以省略 user 权限:

```nginx
fastcgi_store_access group:rw all:r;
```

<a id="index-48"></a>

<a id="fastcgi-temp-file-write-size"></a>

### fastcgi_temp_file_write_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_temp_file_write_size` size;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `fastcgi_temp_file_write_size 8k|16k;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

当启用将 FastCGI 服务器的响应缓冲到临时文件时,限制一次写入临时文件的数据大小。默认情况下,大小受 [fastcgi_buffer_size](#fastcgi-buffer-size) 和 [fastcgi_buffers](#fastcgi-buffers) 指令设置的两个缓冲区限制。临时文件的最大大小由 [fastcgi_max_temp_file_size](#fastcgi-max-temp-file-size) 指令设置。

<a id="index-49"></a>

<a id="fastcgi-temp-path"></a>

### fastcgi_temp_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `fastcgi_temp_path` path [level1 [level2 [level3]]]\`;                                                                                                   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `fastcgi_temp_path fastcgi_temp;`<br/>(路径取决于 `--http-fastcgi-temp-path` [构建参数](https://cn.angie.software//angie/docs/installation/sourcebuild.md#paths)) |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                                   |

定义一个目录,用于存储从 FastCGI 服务器接收的数据的临时文件。在指定目录下可以使用最多三级子目录层次结构。例如,在以下配置中

```nginx
fastcgi_temp_path /spool/angie/fastcgi_temp 1 2;
```

临时文件可能如下所示:

```nginx
/spool/angie/fastcgi_temp/7/45/00000123457
```

另请参阅 [fastcgi_cache_path](#fastcgi-cache-path) 指令的 use_temp_path 参数。

<a id="parameters-passed-to-a-fastcgi-server"></a>

## 传递给 FastCGI 服务器的参数

HTTP 请求头字段作为参数传递给 FastCGI 服务器。在作为 FastCGI 服务器运行的应用程序和脚本中,这些参数通常作为环境变量可用。例如,:samp:User-Agent 头字段作为 HTTP_USER_AGENT 参数传递。除了 HTTP 请求头字段之外,还可以使用 [fastcgi_param](#fastcgi-param) 指令传递任意参数。

<a id="built-in-variables"></a>

## 内置变量

http_fastcgi 模块支持内置变量,可用于通过 [fastcgi_param](#fastcgi-param) 指令设置参数:

<a id="v-fastcgi-script-name"></a>

### `$fastcgi_script_name`

请求 URI,或者如果 URI 以斜杠结尾,则为请求 URI 加上由 [fastcgi_index](#fastcgi-index) 指令配置的索引文件名。此变量可用于设置 SCRIPT_FILENAME 和 PATH_TRANSLATED 参数,这些参数特别用于确定 PHP 中的脚本名称。例如,对于 `/info/` 请求,使用以下指令

```nginx
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /home/www/scripts/php$fastcgi_script_name;
```

SCRIPT_FILENAME 参数将等于 `/home/www/scripts/php/info/index.php`。

当使用 [fastcgi_split_path_info](#fastcgi-split-path-info) 指令时,\`$fastcgi_script_name\` 变量等于该指令设置的第一个捕获组的值。

<a id="v-fastcgi-path-info"></a>

### `$fastcgi_path_info`

由 [fastcgi_split_path_info](#fastcgi-split-path-info) 指令设置的第二个捕获组的值。此变量可用于设置 PATH_INFO 参数。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_flv.md

<!-- review: finished -->

<a id="http-flv"></a>

# FLV

该模块为 Flash 视频（FLV）文件提供伪流式传输的服务器端支持。

它专门处理请求 URI 的查询字符串中的 start 参数，通过从请求的字节偏移量开始发送文件内容，并附加 FLV 头。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，
该模块默认未构建；
需要使用 `‑‑with‑http_flv_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 来启用。

在来自 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中，
该模块已包含在构建中。

<a id="configuration-example-15"></a>

## 配置示例

```nginx
location ~ \.flv$ {
    flv;
}
```

<a id="directives-16"></a>

## 指令

<a id="index-0"></a>

<a id="flv"></a>

### flv

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `flv`;   |
|--------------------------------------------------------------------------------------|----------|
| 默认值                                                                                  | —        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location |

在周围的 location 中开启模块处理。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_geo.md

<!-- review: finished -->

<a id="http-geo"></a>

# Geo

该模块根据客户端 IP 地址创建具有不同值的变量。

<a id="configuration-example-16"></a>

## 配置示例

```nginx
geo $geo {
    default        0;

    127.0.0.1      2;
    192.168.1.0/24 1;
    10.1.0.0/16    1;

    ::1            2;
    2001:0db8::/32 1;
}
```

<a id="directives-17"></a>

## 指令

<a id="index-0"></a>

<a id="geo"></a>

### geo

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geo` [$address] $variable { ... }   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | —                                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                 |

描述了指定变量的值如何依赖于客户端 IP 地址。默认情况下，地址从 [$remote_addr](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-remote-addr) 变量中获取，但也可以从其他变量中获取，例如：

```nginx
geo $arg_remote_addr $geo {
    ...;
}
```

#### NOTE
由于变量仅在使用时才会被计算，即使声明了大量的 `geo` 变量，也不会对请求处理造成额外开销。

如果变量的值不是有效的 IP 地址，则会使用 "255.255.255.255" 地址。

地址可以用 CIDR 表示法指定为前缀（包括单个地址）或作为范围。

还支持以下特殊参数：

| `delete`          | 删除指定的网络                                                                                                                                     |
|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------|
| `default`         | 如果客户端地址不匹配任何指定的地址，则为变量设置的值。当地址以 CIDR 表示法指定时，可以使用 `0.0.0.0/0` 和 `::/0` 代替 `default`。如果未指定 `default`，则默认值将为空字符串                               |
| `include`         | 包含一个带有地址和值的文件。可以有多个包含。                                                                                                                      |
| `proxy`           | 定义受信任的地址。当请求来自受信任的地址时，将使用 `X-Forwarded-For` 请求头字段中的地址。与常规地址不同，受信任的地址是按顺序检查的。                                                                |
| `proxy_recursive` | 启用递归地址搜索。如果禁用递归搜索，则将使用 `X-Forwarded-For` 中发送的最后一个地址，而不是与受信任地址匹配的原始客户端地址。如果启用递归搜索，则将使用 `X-Forwarded-For` 中发送的最后一个非受信任地址，而不是与受信任地址匹配的原始客户端地址。 |
| `ranges`          | 表示地址是作为范围指定的。此参数应为第一个。为加快地理数据库的加载，地址应按升序排列。                                                                                                 |
| `volatile`        | 表示该变量不可缓存。                                                                                                                                  |

示例：

```nginx
geo $country {
    default        ZZ;
    include        conf/geo.conf;
    delete         127.0.0.0/16;
    proxy          192.168.100.0/24;
    proxy          2001:0db8::/32;

    127.0.0.0/24   US;
    127.0.0.1/32   RU;
    10.1.0.0/16    RU;
    192.168.1.0/24 UK;
}
```

`conf/geo.conf` 文件可能包含以下行：

```console
10.2.0.0/16    RU;
192.168.2.0/24 RU;
```

使用最具体的匹配值。例如，对于 `127.0.0.1` 地址，将选择值 `RU`，而不是 `US`。

示例范围描述：

```nginx
geo $country {
    ranges;
    default                   ZZ;
    127.0.0.0-127.0.0.0       US;
    127.0.0.1-127.0.0.1       RU;
    127.0.0.2-127.0.0.255     US;
    10.1.0.0-10.1.255.255     RU;
    192.168.1.0-192.168.1.255 UK;
}
```


# https://cn.angie.software/angie/docs/configuration/modules/http/http_geoip.md

<!-- review: finished -->

<a id="http-geoip"></a>

# GeoIP

根据客户端 IP 地址创建变量并赋值，使用预编译的 [MaxMind](http://www.maxmind.com/) 数据库或其对应版本。

使用支持 IPv6 的数据库时，IPv4 地址将作为映射到 IPv6 的地址进行查找。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，默认不构建此模块；应通过 `‑‑with‑http_geoip_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 进行启用。

#### NOTE
此模块需要 [MaxMind GeoIP](https://www.maxmind.com/en/geoip-databases) 数据库或类似的 [MaxMind GeoLite2](https://dev.maxmind.com/geoip/geolite2-free-geolocation-data)。

<a id="configuration-example-17"></a>

## 配置示例

```nginx
http {
    geoip_country         GeoIP.dat;
    geoip_city            GeoLiteCity.dat;
    geoip_proxy           192.168.100.0/24;
    geoip_proxy           2001:0db8::/32;
    geoip_proxy_recursive on;
    ...
```

<a id="directives-18"></a>

## 指令

<a id="index-0"></a>

<a id="geoip-country"></a>

### geoip_country

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_country` file;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认                                                                                   | —                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                    |

指定用于根据客户端 IP 地址确定国家的数据库。使用此数据库时，可用以下变量：

| `$geoip_country_code`   | 两位的国家代码，例如 "RU"，"US"。                         |
|-------------------------|-----------------------------------------------|
| `$geoip_country_code3`  | 三位的国家代码，例如 "RUS"，"USA"。                       |
| `$geoip_country_name`   | 国家名称，例如 "Russian Federation"，"United States"。 |

<a id="index-1"></a>

<a id="geoip-city"></a>

### geoip_city

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_city` file;   |
|--------------------------------------------------------------------------------------|----------------------|
| 默认                                                                                   | —                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                 |

指定用于根据客户端 IP 地址确定国家、地区和城市的数据库。使用此数据库时，可用以下变量：

| `$geoip_city_continent_code`   | 两位的大陆代码，例如 "EU"，"NA"。                                                                                                                      |
|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------|
| `$geoip_city_country_code`     | 两位的国家代码，例如 "RU"，"US"。                                                                                                                      |
| `$geoip_city_country_code3`    | 三位的国家代码，例如 "RUS"，"USA"。                                                                                                                    |
| `$geoip_city_country_name`     | 国家名称，例如 "Russian Federation"，"United States"。                                                                                              |
| `$geoip_dma_code`              | 美国的 DMA 区域代码（也称为 "metro code"），根据 Google AdWords API 中的 [地理定位](https://developers.google.com/adwords/api/docs/appendix/cities-DMAregions)。 |
| `$geoip_latitude`              | 纬度。                                                                                                                                        |
| `$geoip_longitude`             | 经度。                                                                                                                                        |
| `$geoip_region`                | 两位的国家地区代码（地区、领地、州、省、联邦土地等），例如 "48"，"DC"。                                                                                                   |
| `$geoip_region_name`           | 国家地区名称（地区、领地、州、省、联邦土地等），例如 "Moscow City"，"District of Columbia"。                                                                           |
| `$geoip_city`                  | 城市名称，例如 "Moscow"，"Washington"。                                                                                                             |
| `$geoip_postal_code`           | 邮政编码。                                                                                                                                      |

<a id="index-2"></a>

<a id="geoip-org"></a>

### geoip_org

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_org` file;   |
|--------------------------------------------------------------------------------------|---------------------|
| 默认                                                                                   | —                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                |

指定用于根据客户端 IP 地址确定组织的数据库。使用此数据库时，可用以下变量：

| `$geoip_org`   | 组织名称，例如 "The University of Melbourne"。   |
|----------------|------------------------------------------|

<a id="index-3"></a>

<a id="geoip-proxy"></a>

### geoip_proxy

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_proxy` address | CIDR | unix:;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认                                                                                   | —                                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                    |

定义可信任地址。当请求来自可信任地址时，将使用 `X-Forwarded-For` 请求头字段中的地址。

<a id="index-4"></a>

<a id="geoip-proxy-recursive"></a>

### geoip_proxy_recursive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_proxy_recursive` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认                                                                                   | `geoip_proxy_recursive off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                    |

如果禁用递归搜索，则将使用 `X-Forwarded-For` 中发送的最后一个地址，而不是与可信任地址匹配的原始客户端地址。如果启用递归搜索，则将使用 `X-Forwarded-For` 中发送的最后一个非可信任地址，而不是与可信任地址匹配的原始客户端地址。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_grpc.md

<!-- review: finished -->

<a id="http-grpc"></a>

# gRPC

允许将请求传递到 gRPC 服务器。

#### NOTE
此模块需要 [HTTP2](https://cn.angie.software//angie/docs/configuration/modules/http/http_v2.md#http-v2) 模块。

<a id="configuration-example-18"></a>

## 配置示例

```nginx
server {
    listen 9000;

    http2 on;

    location / {
        grpc_pass 127.0.0.1:9000;
    }
}
```

<a id="directives-19"></a>

## 指令

<a id="index-0"></a>

<a id="grpc-bind"></a>

### grpc_bind

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_bind` address [`transparent`] | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | —                                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                         |

使到 gRPC 服务器的出站连接从指定的本地 IP 地址（可选端口)发起。参数值可以包含变量。特殊值 `off` 取消从上一配置级别继承的 grpc_bind 指令的效果,允许系统自动分配本地 IP 地址和端口。

`transparent` 参数允许到 gRPC 服务器的出站连接从非本地 IP 地址发起,例如从客户端的真实 IP 地址:

```nginx
grpc_bind $remote_addr transparent;
```

为使此参数生效,通常需要以 [超级用户](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 权限运行 Angie 工作进程。在 Linux 上不需要这样做,因为如果指定了 `transparent` 参数,工作进程会从主进程继承 CAP_NET_RAW 能力。

#### NOTE
需要配置内核路由表以拦截来自 gRPC 服务器的网络流量。

<a id="index-1"></a>

<a id="grpc-buffer-size"></a>

### grpc_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_buffer_size` size;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `grpc_buffer_size 4k|8k;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

设置用于读取从 gRPC 服务器接收的响应的第一部分的缓冲区大小。响应一旦接收到就会同步传递给客户端。

<a id="index-2"></a>

<a id="grpc-connect-timeout"></a>

### grpc_connect_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_connect_timeout` time;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `grpc_connect_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

定义与 gRPC 服务器建立连接的超时时间。需要注意的是,此超时时间通常不能超过 75 秒。

<a id="index-3"></a>

<a id="grpc-connection-drop"></a>

### grpc_connection_drop

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_connection_drop` time | `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | `grpc_connection_drop off;`                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                        |

启用在代理服务器从组中移除或被 [重新解析](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve) 进程或 [API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config-methods) `DELETE` 命令标记为永久不可用后,终止到该服务器的所有连接。

当为客户端或代理服务器处理下一个读或写事件时,连接将被终止。

设置 time 启用连接终止 [超时](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax);
设置为 `on` 时,连接立即断开。

<a id="index-4"></a>

<a id="grpc-hide-header"></a>

### grpc_hide_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_hide_header` field;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

默认情况下,Angie 不会将 gRPC 服务器响应中的头字段 `Date`、`Server` 和 `X-Accel-...` 传递给客户端。`grpc_hide_header` 指令设置不会被传递的附加字段。相反,如果需要允许传递字段,可以使用 [grpc_pass_header](#grpc-pass-header) 指令。

<a id="index-5"></a>

<a id="grpc-ignore-headers"></a>

### grpc_ignore_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ignore_headers` field ...;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | —                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

禁用对来自 gRPC 服务器的某些响应头字段的处理。可以忽略以下字段:`X-Accel-Redirect` 和 `X-Accel-Charset`。

如果未禁用,处理这些头字段将产生以下效果:

* `X-Accel-Redirect` 执行到指定 URI 的 [内部重定向](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#internal);
* `X-Accel-Charset` 设置响应所需的 [字符集](https://cn.angie.software//angie/docs/configuration/modules/http/http_charset.md#id3)。

<a id="index-6"></a>

<a id="grpc-intercept-errors"></a>

### grpc_intercept_errors

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_intercept_errors` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `grpc_intercept_errors off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

确定代码大于或等于 300 的 gRPC 服务器响应应该传递给客户端,还是被拦截并重定向到 Angie 使用 [error_page](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#error-page) 指令进行处理。

<a id="index-7"></a>

<a id="grpc-next-upstream"></a>

### grpc_next_upstream

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_next_upstream` `error` | `timeout` | `invalid_header` | `http_500` | `http_502` | `http_503` | `http_504` | `http_403` | `http_404` | `http_429` | `non_idempotent` | `off` ...;   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `grpc_next_upstream error timeout;`                                                                                                                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                                                                   |

指定在哪些情况下应将请求传递给 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 组中的下一个服务器:

| `error`          | 与服务器建立连接、向其传递请求或读取响应头时发生错误;                                                                                                                              |
|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
| `timeout`        | 与服务器建立连接、向其传递请求或读取响应头时发生超时;                                                                                                                              |
| `invalid_header` | 服务器返回空响应或无效响应;                                                                                                                                           |
| `http_500`       | 服务器返回代码为 500 的响应;                                                                                                                                        |
| `http_502`       | 服务器返回代码为 502 的响应;                                                                                                                                        |
| `http_503`       | 服务器返回代码为 503 的响应;                                                                                                                                        |
| `http_504`       | 服务器返回代码为 504 的响应;                                                                                                                                        |
| `http_403`       | 服务器返回代码为 403 的响应;                                                                                                                                        |
| `http_404`       | 服务器返回代码为 404 的响应;                                                                                                                                        |
| `http_429`       | 服务器返回代码为 429 的响应;                                                                                                                                        |
| `non_idempotent` | 通常,使用 [非幂等](https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.2) 方法<br/>(`POST`、`LOCK`、`PATCH`)的请求如果已发送到上游服务器,<br/>则不会传递给下一个服务器;启用此选项明确允许重试此类请求; |
| `off`            | 禁用将请求传递给下一个服务器。                                                                                                                                          |

#### NOTE
应该记住,只有在尚未向客户端发送任何内容时,才可能将请求传递给下一个服务器。也就是说,如果在传输响应的过程中发生错误或超时,则无法修复此问题。

该指令还定义了什么被视为与服务器通信的 [不成功尝试](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#max-fails)。

| `error`、`timeout`、`invalid_header`                     | 始终被视为不成功尝试,即使它们未在指令中指定   |
|--------------------------------------------------------|--------------------------|
| `http_500`、`http_502`、`http_503`、`http_504`、`http_429` | 仅在指令中指定时才被视为不成功尝试        |
| `http_403`、`http_404`                                  | 从不被视为不成功尝试               |

将请求传递给下一个服务器可以受 [尝试次数](#grpc-next-upstream-tries) 和 [时间](#grpc-next-upstream-timeout) 的限制。

<a id="index-8"></a>

<a id="grpc-next-upstream-timeout"></a>

### grpc_next_upstream_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_next_upstream_timeout` time;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `grpc_next_upstream_timeout 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

限制可以将请求传递给 [下一个服务器](#grpc-next-upstream) 的时间。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-9"></a>

<a id="grpc-next-upstream-tries"></a>

### grpc_next_upstream_tries

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_next_upstream_tries` number;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `grpc_next_upstream_tries 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

限制将请求传递到 [下一个](#grpc-next-upstream) 服务器的可能尝试次数。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-10"></a>

<a id="grpc-pass"></a>

### grpc_pass

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_pass` address;     |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | —                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location, if in location |

设置 gRPC 服务器地址。地址可以指定为域名或 IP 地址,以及端口:

```nginx
grpc_pass localhost:9000;
```

或作为 UNIX 域套接字路径:

```nginx
grpc_pass unix:/tmp/grpc.socket;
```

或者,可以使用 `grpc://` 方案:

```nginx
grpc_pass grpc://127.0.0.1:9000;
```

要使用基于 SSL 的 gRPC,应使用 `grpcs://` 方案:

```nginx
grpc_pass grpcs://127.0.0.1:443;
```

如果域名解析为多个地址,则所有地址都将以轮询方式使用。此外,地址可以指定为 [服务器组](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream)。

参数值可以包含变量。在这种情况下,如果地址指定为域名,则在所描述的服务器组中搜索该名称,如果未找到,则使用 [解析器](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 确定。

#### NOTE
如果在带有前缀尾部斜杠的 `location` 中指定 `grpc_pass`
(例如,:samp:location /name/),
并且 [auto_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#auto-redirect) 指令设置为 `default`,
则不带尾部斜杠的请求将被重定向(`/name -> /name/`)。

<a id="index-11"></a>

<a id="grpc-pass-header"></a>

### grpc_pass_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_pass_header` field;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

允许将 [原本禁用的](#grpc-hide-header) 头字段从 gRPC 服务器传递到客户端。

<a id="index-12"></a>

<a id="grpc-read-timeout"></a>

### grpc_read_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_read_timeout` time;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `grpc_read_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

定义从 gRPC 服务器读取响应的超时时间。超时仅在两次连续的读取操作之间设置,而不是针对整个响应的传输。如果 gRPC 服务器在此时间内未传输任何内容,则连接将关闭。

<a id="index-13"></a>

<a id="grpc-send-timeout"></a>

### grpc_send_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_send_timeout` time;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `grpc_send_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

设置向 gRPC 服务器传输请求的超时时间。超时仅在两次连续的写操作之间设置,而不是针对整个请求的传输。如果 gRPC 服务器在此时间内未接收到任何内容,则连接将关闭。

<a id="index-14"></a>

<a id="grpc-set-header"></a>

### grpc_set_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_set_header` field value;                    |
|--------------------------------------------------------------------------------------|---------------------------------------------------|
| 默认值                                                                                  | `grpc_set_header Content-Length $content_length;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                            |

允许重新定义或追加字段到 [传递](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass-request-headers) 给 gRPC 服务器的请求头。值可以包含文本、变量及其组合。当且仅当当前级别未定义 grpc_set_header 指令时,这些指令才从上一级配置继承。

如果头字段的值为空字符串,则该字段将不会传递给 gRPC 服务器:

```nginx
grpc_set_header Accept-Encoding "";
```

<a id="index-15"></a>

<a id="grpc-socket-keepalive"></a>

### grpc_socket_keepalive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_socket_keepalive` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `grpc_socket_keepalive off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

配置到 gRPC 服务器的出站连接的"TCP keepalive"行为。

| `off`   | 默认情况下,套接字使用操作系统的设置。        |
|---------|----------------------------|
| `on`    | 为套接字启用 SO_KEEPALIVE 套接字选项。 |

<a id="index-16"></a>

<a id="grpc-ssl-certificate"></a>

### grpc_ssl_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_certificate` file;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | —                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

指定一个 PEM 格式的证书文件,用于向 gRPC SSL 服务器进行身份验证。文件名中可以使用变量。

<a id="index-17"></a>

<a id="grpc-ssl-certificate-cache"></a>

### grpc_ssl_certificate_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_certificate_cache` `off`;<br/><br/>`grpc_ssl_certificate_cache` `max=`N [`inactive=`time] [`valid=`time];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `grpc_ssl_certificate_cache off;`                                                                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                |

定义一个缓存,用于存储使用变量指定的 [SSL 证书](#grpc-ssl-certificate) 和 [密钥](#grpc-ssl-certificate-key)。

该指令支持以下参数:

- `max` — 设置缓存中的最大元素数。当缓存溢出时,将删除最近最少使用 (LRU) 的元素。
- `inactive` — 定义元素在未被访问后被删除的时间。默认为 10 秒。
- `valid` — 定义缓存元素被视为有效并可重用的时间。默认为 60 秒。在此期间之后,
  证书将被重新加载或重新验证。
- `off` — 禁用缓存。

示例:

```nginx
grpc_ssl_certificate       $grpc_ssl_server_name.crt;
grpc_ssl_certificate_key   $grpc_ssl_server_name.key;
grpc_ssl_certificate_cache max=1000 inactive=20s valid=1m;
```

<a id="index-18"></a>

<a id="grpc-ssl-certificate-key"></a>

### grpc_ssl_certificate_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_certificate_key` file;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | —                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

指定一个 PEM 格式的密钥文件,用于向 gRPC SSL 服务器进行身份验证。

可以指定值 `engine:`name`:id` 来代替文件,这将从 OpenSSL 引擎 name 中加载具有指定 id 的密钥。

可以指定值 `store:scheme:id` 来代替文件,用于从 OpenSSL 提供程序注册的 URI [scheme\`(如 \`pkcs11](https://datatracker.ietf.org/doc/html/rfc7512))中加载具有指定 id 的密钥。

文件名中可以使用变量。

<a id="index-19"></a>

<a id="grpc-ssl-ciphers"></a>

### grpc_ssl_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_ciphers` ciphers;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `grpc_ssl_ciphers DEFAULT;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

指定向 gRPC SSL 服务器发送请求时启用的密码套件。密码套件以 OpenSSL 库理解的格式指定。

密码套件列表取决于安装的 OpenSSL 版本。
可以使用 `openssl ciphers` 命令查看完整列表。

#### WARNING
使用 OpenSSL 时,:samp:grpc_ssl_ciphers 指令  *不* 配置 TLS 1.3 的密码套件。
要使用 OpenSSL 调整 TLS 1.3 密码套件,请使用 [grpc_ssl_conf_command](#grpc-ssl-conf-command) 指令,
该指令是为支持高级 SSL 配置而添加的。

- 在 LibreSSL 中,TLS 1.3 密码套件  *可以* 使用 `grpc_ssl_ciphers` 配置。
- 在 BoringSSL 中,TLS 1.3 密码套件完全无法配置。

<a id="index-20"></a>

<a id="grpc-ssl-conf-command"></a>

### grpc_ssl_conf_command

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_conf_command` name value;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | —                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

在与 gRPC SSL 服务器建立连接时设置任意 OpenSSL 配置 [命令](https://docs.openssl.org/master/man3/SSL_CONF_cmd/)。

#### NOTE
使用 OpenSSL 1.0.2 或更高版本时支持该指令。
要使用 OpenSSL 配置 TLS 1.3 密码套件,请使用 `ciphersuites` 命令。

可以在同一级别指定多个 grpc_ssl_conf_command 指令。当且仅当当前级别未定义 grpc_ssl_conf_command 指令时,这些指令才会从上一级配置继承。

#### WARNING
请注意,直接配置 OpenSSL 可能会导致意外行为。

<a id="index-21"></a>

<a id="grpc-ssl-crl"></a>

### grpc_ssl_crl

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_crl` file;   |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | —                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

指定一个包含 PEM 格式吊销证书 (CRL) 的文件,用于 [验证](#grpc-ssl-verify) gRPC SSL 服务器的证书。

<a id="index-22"></a>

<a id="grpc-ssl-name"></a>

### grpc_ssl_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_name` name;                 |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `grpc_ssl_name `来自 grpc_pass 的主机名`;\` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

允许覆盖用于 [验证](#grpc-ssl-verify) gRPC SSL 服务器证书的服务器名称,以及在与 gRPC SSL 服务器建立连接时 [通过 SNI 传递](#grpc-ssl-server-name) 的服务器名称。

默认情况下,使用 [grpc_pass](#grpc-pass) 中的主机名。

<a id="index-23"></a>

<a id="grpc-ssl-password-file"></a>

### grpc_ssl_password_file

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_password_file` file;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

指定一个包含 [密钥](#grpc-ssl-certificate-key) 密码短语的文件,每个密码短语单独占一行。加载密钥时会依次尝试这些密码短语。

<a id="index-24"></a>

<a id="grpc-ssl-protocols"></a>

### grpc_ssl_protocols

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_protocols` [`SSLv2`] [`SSLv3`] [`TLSv1`] [`TLSv1.1`] [`TLSv1.2`] [`TLSv1.3`];   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `grpc_ssl_protocols TLSv1.2 TLSv1.3;`                                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                    |

#### Versionchanged
在 1.2.0 版本发生变更: 默认集合中添加了 `TLSv1.3` 参数。

为向 gRPC SSL 服务器发送的请求启用指定的协议。

<a id="index-25"></a>

<a id="grpc-ssl-server-name"></a>

### grpc_ssl_server_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_server_name` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `grpc_ssl_server_name off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

启用或禁用在与 gRPC SSL 服务器建立连接时,通过 [服务器名称指示](http://en.wikipedia.org/wiki/Server_Name_Indication) TLS 扩展 (SNI,\`RFC 6066 <[https://datatracker.ietf.org/doc/html/rfc6066.html](https://datatracker.ietf.org/doc/html/rfc6066.html)>\`_) 传递由 [grpc_ssl_name](#grpc-ssl-name) 指令设置的服务器名称。

<a id="index-26"></a>

<a id="grpc-ssl-session-reuse"></a>

### grpc_ssl_session_reuse

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_session_reuse` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `grpc_ssl_session_reuse on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

确定在与 gRPC 服务器通信时是否可以重用 SSL 会话。如果日志中出现 "SSL3_GET_FINISHED:digest check failed" 错误,请尝试禁用会话重用。

<a id="index-27"></a>

<a id="grpc-ssl-trusted-certificate"></a>

### grpc_ssl_trusted_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_trusted_certificate` file;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

指定一个包含 PEM 格式受信任 CA 证书的文件,用于 [验证](#grpc-ssl-verify) gRPC SSL 服务器的证书。

<a id="index-28"></a>

<a id="grpc-ssl-verify"></a>

### grpc_ssl_verify

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_verify` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `grpc_ssl_verify off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

启用或禁用对 gRPC SSL 服务器证书的验证。

<a id="index-29"></a>

<a id="grpc-ssl-verify-depth"></a>

### grpc_ssl_verify_depth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `grpc_ssl_verify_depth` number;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `grpc_ssl_verify_depth 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

设置 gRPC SSL 服务器证书链的验证深度。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_gunzip.md

<!-- review: finished -->

<a id="http-gunzip"></a>

# GunZIP

该模块是一个过滤器，用于为不支持"gzip"编码方法的客户端解压缩带有:samp:Content-Encoding: gzip 的响应。当需要存储压缩数据以节省空间和减少 I/O 成本时，该模块将非常有用。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，默认情况下不会构建此模块；应通过 `‑‑with‑http_gunzip_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用。

在来自 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中，构建中已包含该模块。

<a id="configuration-example-19"></a>

## 配置示例

```nginx
location /storage/ {
    gunzip on;
#    ...
}
```

<a id="directives-20"></a>

## 指令

<a id="index-0"></a>

<a id="gunzip"></a>

### gunzip

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gunzip` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | `gunzip off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location   |

启用或禁用对缺乏 gzip 支持的客户端的压缩响应解压缩。如果启用，还会考虑以下指令以确定客户端是否支持 gzip：[gzip_http_version](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#gzip-http-version)、[gzip_proxied](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#gzip-proxied) 和 [gzip_disable](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#gzip-disable)。另请参阅 [gzip_vary](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#gzip-vary) 指令。

<a id="index-1"></a>

<a id="gunzip-buffers"></a>

### gunzip_buffers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gunzip_buffers` 数量 大小;         |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `gunzip_buffers 32 4k | 16 8k;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

设置用于解压缩响应的缓冲区的数量和大小。默认情况下，缓冲区大小等于一个内存页大小。这取决于平台，可能是 4K 或 8K。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_gzip.md

<!-- review: finished -->

<a id="http-gzip"></a>

# GZip

该模块是一个使用 gzip 方法压缩响应的过滤器，可以将传输数据的大小减少 2 倍或更多。

#### WARNING
使用 SSL/TLS 协议时，压缩响应可能会受到 [BREACH](https://en.wikipedia.org/wiki/BREACH) 攻击。

<a id="configuration-example-20"></a>

## 配置示例

```nginx
gzip            on;
gzip_min_length 1000;
gzip_proxied    expired no-cache no-store private auth;
gzip_types      text/plain application/xml;
```

可以使用 [$gzip_ratio](#v-gzip-ratio) 变量来记录达到的压缩比率。

<a id="directives-21"></a>

## 指令

<a id="index-0"></a>

<a id="gzip"></a>

### gzip

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gzip` `on` | `off`;                   |
|------------------------------------------------------------------------------------------|----------------------------------------|
| 默认                                                                                       | `gzip off;`                            |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

启用或禁用响应的 gzip 压缩。

<a id="index-1"></a>

<a id="gzip-buffers"></a>

### gzip_buffers

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gzip_buffers` number size;   |
|------------------------------------------------------------------------------------------|-------------------------------|
| 默认                                                                                       | `gzip_buffers 32 4k | 16 8k;` |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

设置用于压缩响应的缓冲区数量和大小。默认情况下，缓冲区大小等于一个内存页大小，这取决于平台，通常是 4K 或 8K。

<a id="index-2"></a>

<a id="gzip-comp-level"></a>

### gzip_comp_level

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gzip_comp_level` level;   |
|------------------------------------------------------------------------------------------|----------------------------|
| 默认                                                                                       | `gzip_comp_level 1;`       |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

设置响应的 gzip 压缩级别。可接受的值范围从 1 到 9。

<a id="index-3"></a>

<a id="gzip-disable"></a>

### gzip_disable

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gzip_disable` regex ...;   |
|------------------------------------------------------------------------------------------|-----------------------------|
| 默认                                                                                       | —                           |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

禁止对 `User-Agent` 请求头字段与指定正则表达式匹配的请求进行 gzip 压缩。

特殊的掩码 `msie6` 对应于正则表达式 "MSIE [4-6]."，但工作速度更快。"MSIE 6.0; ... SV1" 被排除在该掩码之外。

<a id="index-4"></a>

<a id="gzip-http-version"></a>

### gzip_http_version

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gzip_http_version` `1.0` | `1.1`;   |
|------------------------------------------------------------------------------------------|--------------------------------------|
| 默认                                                                                       | `gzip_http_version 1.1;`             |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

设置请求所需的最低 HTTP 版本以压缩响应。

<a id="index-5"></a>

<a id="gzip-min-length"></a>

### gzip_min_length

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gzip_min_length` length;   |
|------------------------------------------------------------------------------------------|-----------------------------|
| 默认                                                                                       | `gzip_min_length 20;`       |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

设置将被 gzip 压缩的响应的最小长度。长度仅从 `Content-Length` 响应头字段中确定。

<a id="index-6"></a>

<a id="gzip-proxied"></a>

### gzip_proxied

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gzip_proxied` `off` | `expired` | `no-cache` | `no-store` | `private` | `no_last_modified` | `no_etag` | `auth` | `any` ...;   |
|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------|
| 默认                                                                                       | `gzip_proxied off;`                                                                                                             |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                          |

根据请求和响应的情况启用或禁用对代理请求的响应进行 gzip 压缩。请求是代理请求的事实由请求头字段 `Via` 的存在来确定。该指令接受多个参数：

| `off`              | 禁用对所有代理请求的压缩，忽略其他参数；                               |
|--------------------|----------------------------------------------------|
| `expired`          | 如果响应头包含 `Expires` 字段且值禁止缓存，则启用压缩；                  |
| `no-cache`         | 如果响应头包含 `Cache-Control` 字段且具有 "no-cache" 参数，则启用压缩； |
| `no-store`         | 如果响应头包含 `Cache-Control` 字段且具有 "no-store" 参数，则启用压缩； |
| `private`          | 如果响应头包含 `Cache-Control` 字段且具有 "private" 参数，则启用压缩；  |
| `no_last_modified` | 如果响应头不包含 `Last-Modified` 字段，则启用压缩；                 |
| `no_etag`          | 如果响应头不包含 `ETag` 字段，则启用压缩；                          |
| `auth`             | 如果请求头包含 `Authorization` 字段，则启用压缩；                  |
| `any`              | 对所有代理请求启用压缩。                                       |

<a id="index-7"></a>

<a id="gzip-types"></a>

### gzip_types

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gzip_types` mime-type ...;   |
|------------------------------------------------------------------------------------------|-------------------------------|
| 默认                                                                                       | `gzip_types text/html;`       |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

启用对指定 MIME 类型的响应进行 gzip 压缩，除了 `text/html` 之外。特殊值 "\*" 匹配任何 MIME 类型。`text/html` 类型的响应始终被压缩。

<a id="index-8"></a>

<a id="gzip-vary"></a>

### gzip_vary

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gzip_vary` `on` | `off`;   |
|------------------------------------------------------------------------------------------|-----------------------------|
| 默认                                                                                       | `gzip_vary off;`            |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

启用或禁用在响应头中插入 "Vary: Accept-Encoding" 字段，如果指令 [gzip](#id3)、[gzip_static](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip_static.md#id3) 或 [gunzip](https://cn.angie.software//angie/docs/configuration/modules/http/http_gunzip.md#id3) 激活。

<a id="built-in-variables-1"></a>

## 内置变量

<a id="v-gzip-ratio"></a>

### `$gzip_ratio`

达到的压缩比率，计算为原始响应大小与压缩响应大小的比率。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_gzip_static.md

<!-- review: finished -->

<a id="http-gzip-static"></a>

# GZip Static

允许发送带有".gz"文件扩展名的预压缩文件，而不是常规文件。

当从源码 [构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，该模块默认未构建；它应通过 `‑‑with‑http_gzip_static_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用。

在从 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 中的包和镜像中，该模块已包含在构建中。

<a id="configuration-example-21"></a>

## 配置示例

```nginx
gzip_static  on;
gzip_proxied expired no-cache no-store private auth;
```

<a id="directives-22"></a>

## 指令

<a id="index-0"></a>

<a id="gzip-static"></a>

### gzip_static

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `gzip_static` `on` | `off` | `always`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `gzip_static off;`                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

启用 (`on`) 或禁用 (`off`) 检查预压缩文件的存在。以下指令也会被考虑：[gzip_http_version](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#gzip-http-version)、[gzip_proxied](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#gzip-proxied)、[gzip_disable](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#gzip-disable) 和 [gzip_vary](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#gzip-vary)。

使用 `always` 时，压缩文件在所有情况下都会被使用，而无需检查客户端是否支持。这在磁盘上没有未压缩文件或者使用了 [GunZIP](https://cn.angie.software//angie/docs/configuration/modules/http/http_gunzip.md#http-gunzip) 模块时很有用。

文件可以通过 gzip 命令或任何其他兼容命令进行压缩。建议原始文件和压缩文件的修改日期和时间相同。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_headers.md

<!-- review: finished -->

<a id="http-headers"></a>

# Headers

允许在响应头中添加 `Expires` 和 `Cache-Control` 头字段,以及任意字段。

<a id="configuration-example-22"></a>

## 配置示例

```nginx
expires    24h;
expires    modified +24h;
expires    @24h;
expires    0;
expires    -1;
expires    epoch;
expires    $expires;
add_header Cache-Control private;
```

<a id="directives-23"></a>

## 指令

<a id="index-0"></a>

<a id="add-header"></a>

### add_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `add_header` name value [`always`];    |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

在响应码为 200、201 (1.3.10)、204、206、301、302、303、304、307 或 308 时,添加指定字段到响应头。参数值可以包含变量。

可以有多个 `add_header` 指令。只有在当前级别未定义任何 `add_header` 指令时,这些指令才会从上一级配置继承。

如果指定了 `always` 参数,则无论响应码如何,都会添加该头字段。

<a id="index-1"></a>

<a id="add-trailer"></a>

### add_trailer

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `add_trailer` name value [`always`];   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

在响应码为 200、201、206、301、302、303、307 或 308 时,添加指定字段至响应的末尾。参数值可以包含变量。

可以有多个 `add_trailer` 指令。只有在当前级别未定义任何 `add_trailer` 指令时,这些指令才会从上一级配置继承。

如果指定了 `always` 参数,则无论响应码如何,都会添加该字段。

<a id="index-2"></a>

<a id="expires"></a>

### expires

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `expires` [`modified`] time;<br/><br/>`expires` `epoch` | `max` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------|
| 默认值                                                                                  | `expires off;`                                                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location                                     |

启用或禁用在响应码为 200、201、204、206、301、302、303、304、307 或 308 时添加或修改 `Expires` 和 `Cache-Control` 响应头字段。参数可以是正或负的 [时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)。

`Expires` 字段中的时间是当前时间与指令中指定时间的总和。如果使用了 `modified` 参数,则时间是文件修改时间与指令中指定时间的总和。

此外,可以使用 "@" 前缀指定一天中的某个时间:

```nginx
expires @15h30m;
```

`Cache-Control` 字段的内容取决于指定时间的符号:

* 时间为负 — "Cache-Control: no-cache"。
* 时间为正或零 — "Cache-Control: max-age=\`t\`",其中 t 是指令中指定的时间,以秒为单位。

| `epoch`   | 将 `Expires` 设置为 "Thu, 01 Jan 1970 00:00:01 GMT",:samp:Cache-Control 设置为 "no-cache"。   |
|-----------|---------------------------------------------------------------------------------------|
| `max`     | 将 `Expires` 设置为 "Thu, 31 Dec 2037 23:55:55 GMT",:samp:Cache-Control 设置为 10 年。         |
| `off`     | 禁止添加或修改 `Expires` 和 `Cache-Control` 响应头字段。                                            |

最后的参数值可以包含变量:

```nginx
map $sent_http_content_type $expires {
    default         off;
    application/pdf 42d;
    ~image/         max;
}

expires $expires;
```


# https://cn.angie.software/angie/docs/configuration/modules/http/http_image_filter.md

<!-- review: finished -->

<a id="http-image-filter"></a>

# Image Filter

该模块是一个过滤器,用于转换 JPEG、GIF、PNG、WebP、HEIC 和 AVIF 格式的图像。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时,默认不会构建此模块;需要使用 `‑‑with‑http_image_filter_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用。

在我们的代码库中,该模块是 [动态构建](https://cn.angie.software//angie/docs/installation/index.md#install-dynamicmodules) 的,并作为名为 `angie-module-image-filter` 或 `angie-pro-module-image-filter` 的单独软件包提供。

#### NOTE
此模块利用 [libgd](http://libgd.org/) 库。建议使用库的最新可用版本。

要转换 WebP、HEIC 或 AVIF 格式的图像,:samp:libgd 库必须编译时启用对这些格式的支持。

<a id="configuration-example-23"></a>

## 配置示例

```nginx
location /img/ {
    proxy_pass   http://backend;
    image_filter resize 150 100;
    image_filter rotate 90;
    error_page   415 = /empty;
}

location = /empty {
    empty_gif;
}
```

<a id="directives-24"></a>

## 指令

<a id="index-0"></a>

<a id="image-filter"></a>

### image_filter

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | - `image_filter` `off`;<br/>- `image_filter` `test`;<br/>- `image_filter` `size`;<br/>- `image_filter` rotate `90` | `180` | `270`;<br/>- `image_filter` resize width height;<br/>- `image_filter` crop width height;<br/>- `image_filter` convert type;   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认                                                                                   | `image_filter off;`                                                                                                                                                                                                                                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location                                                                                                                                                                                                                                                   |

设置要对图像执行的转换类型:

| `off`                 | 在周围位置关闭模块处理。                                                                                                                        |
|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------|
| `test`                | 确保响应为 JPEG、GIF、PNG、WebP、HEIC 或 AVIF 格式的图像。否则,将返回 415(不支持的媒体类型)错误。                                                                   |
| `size`                | 以 JSON 格式输出图像的信息,例如:<br/>` *"img" : { "width": 100, "height": 100, "type": "gif"*  }`<br/>如果发生错误,输出如下:`{}`                          |
| `rotate 90|180|270`   | 逆时针旋转图像指定的度数。参数值可以包含变量。此模式可以单独使用或与 `resize` 和 `crop` 转换一起使用。                                                                        |
| `resize` width height | 按照指定的大小按比例缩小图像。要仅在一个维度上缩小,可以将另一个维度指定为 "-"。如果发生错误,服务器将返回 415(不支持的媒体类型)代码。参数值可以包含变量。当与 `rotate` 参数一起使用时,旋转在缩小 **之后** 发生。              |
| `crop` width height   | 按照更大边的大小按比例缩小图像,并裁剪另一边的多余边缘。要仅在一个维度上缩小,可以将另一个维度指定为 "-"。如果发生错误,服务器将返回 415(不支持的媒体类型)代码。参数值可以包含变量。当与 `rotate` 参数一起使用时,旋转在缩小 **之前** 发生。 |
| `convert` type        | 将图像转换为指定的输出格式。有效值为 `jpeg`、`gif`、`png`、`webp`、`heic` 和 `avif`。参数值可以包含变量。                                                             |

<a id="index-1"></a>

<a id="image-filter-buffer"></a>

### image_filter_buffer

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `image_filter_buffer` size;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认                                                                                   | `image_filter_buffer 1M;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

设置用于读取图像的缓冲区的最大大小。当超出该大小时,服务器返回 415(不支持的媒体类型)错误。

<a id="index-2"></a>

<a id="image-filter-interlace"></a>

### image_filter_interlace

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `image_filter_interlace` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认                                                                                   | `image_filter_interlace off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

如果启用,最终图像将会交错。对于 JPEG,最终图像将为"渐进式 JPEG"格式。

<a id="index-3"></a>

<a id="image-filter-jpeg-quality"></a>

### image_filter_jpeg_quality

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `image_filter_jpeg_quality` quality;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认                                                                                   | `image_filter_jpeg_quality 75;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

设置转换后的 JPEG 图像的期望质量。可接受的值范围为 1 到 100。较小的值通常意味着图像质量较低和传输的数据较少。建议的最大值为 95。参数值可以包含变量。

<a id="index-4"></a>

<a id="image-filter-sharpen"></a>

### image_filter_sharpen

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `image_filter_sharpen` percent;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认                                                                                   | `image_filter_sharpen 0;`         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

增加最终图像的锐度。锐度百分比可以超过 100。`0` 值禁用锐化。参数值可以包含变量。

<a id="index-5"></a>

<a id="image-filter-transparency"></a>

### image_filter_transparency

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `image_filter_transparency` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认                                                                                   | `image_filter_transparency on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

定义在转换 GIF 图像或具有调色板指定颜色的 PNG 图像时是否应保留透明度。透明度的丧失会导致图像质量更好。PNG 中的 alpha 通道透明度始终保留。

<a id="index-6"></a>

<a id="image-filter-webp-quality"></a>

### image_filter_webp_quality

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `image_filter_webp_quality` quality;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认                                                                                   | `image_filter_webp_quality 80;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

设置转换后的 WebP 图像的期望质量。可接受的值范围为 1 到 100。较小的值通常意味着图像质量较低和传输的数据较少。参数值可以包含变量。

<a id="index-7"></a>

<a id="image-filter-heic-quality"></a>

### image_filter_heic_quality

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `image_filter_heic_quality` quality;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认                                                                                   | `image_filter_heic_quality 80;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

设置转换后的 HEIC 图像的期望质量。可接受的值为正数。参数值可以包含变量。

<a id="index-8"></a>

<a id="image-filter-avif-quality"></a>

### image_filter_avif_quality

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `image_filter_avif_quality` quality [speed];   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认                                                                                   | `image_filter_avif_quality 80 6;`              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                         |

设置转换后的 AVIF 图像的期望质量。可选的 `speed` 参数控制编码器速度;两个值都必须为正数。参数值可以包含变量。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_index.md

<!-- review: finished -->

<a id="http-index"></a>

# Index

该模块处理以斜杠字符 (`/`) 结尾的请求。这类请求也可以由 [http_autoindex](https://cn.angie.software//angie/docs/configuration/modules/http/http_autoindex.md#http-autoindex) 和 [http_random_index](https://cn.angie.software//angie/docs/configuration/modules/http/http_random_index.md#http-random-index) 模块处理。

<a id="configuration-example-24"></a>

## 配置示例

```nginx
location / {
    index index.$geo.html index.html;
}
```

<a id="directives-25"></a>

## 指令

<a id="index-0"></a>

<a id="index"></a>

### index

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `index` file ...;      |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | `index index.html;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

定义将用作索引的文件。文件名可以包含变量。文件按照指定的顺序进行检查。列表的最后一个元素可以是一个具有绝对路径的文件。示例：

```nginx
index index.$geo.html index.0.html /index.html;
```

需要注意的是，使用索引文件会导致内部重定向，并且请求可以在不同的位置进行处理。例如，使用以下配置：

```nginx
location = / {
    index index.html;
}

location / {
    #    ...
}
```

一个 `"/"` 请求实际上将在第二个位置作为 `"/index.html"` 进行处理。


# https://cn.angie.software/angie/docs/installation/external-modules/http_js.md

<!-- review: finished -->

<a id="http-js"></a>

# JS

该模块用于在 njs 中实现处理程序——这是 JavaScript 语言的一个子集。

在我们的代码库中,该模块是
[动态构建](https://cn.angie.software//angie/docs/installation/index.md#install-dynamicmodules)
并作为名为 `angie-module-njs` 或 `angie-pro-module-njs` 的单独包提供。

#### NOTE
此软件包还提供一个轻量级版本,名为 `...-njs-light`;但它无法与常规版本
同时使用。

<a id="configuration-example-90"></a>

## 配置示例

```nginx
http {
    js_import http.js;

    js_set $foo     http.foo;
    js_set $summary http.summary;
    js_set $hash    http.hash;

    resolver 127.0.0.53;

    server {
        listen 8000;

        location / {
            add_header X-Foo $foo;
            js_content http.baz;
        }

        location = /summary {
            return 200 $summary;
        }

        location = /hello {
            js_content http.hello;
        }

        location = /fetch {
            js_content                   http.fetch;
            js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
        }

        location = /crypto {
            add_header Hash $hash;
            return     200;
        }
    }
}
```

`http.js` 文件:

```javascript
function foo(r) {
    r.log("hello from foo() handler");
    return "foo";
}

function summary(r) {
    var a, s, h;

    s = "JS summary\n\n";

    s += "Method: " + r.method + "\n";
    s += "HTTP version: " + r.httpVersion + "\n";
    s += "Host: " + r.headersIn.host + "\n";
    s += "Remote Address: " + r.remoteAddress + "\n";
    s += "URI: " + r.uri + "\n";

    s += "Headers:\n";
    for (h in r.headersIn) {
        s += "  header '" + h + "' is '" + r.headersIn[h] + "'\n";
    }

    s += "Args:\n";
    for (a in r.args) {
        s += "  arg '" + a + "' is '" + r.args[a] + "'\n";
    }

    return s;
}

function baz(r) {
    r.status = 200;
    r.headersOut.foo = 1234;
    r.headersOut['Content-Type'] = "text/plain; charset=utf-8";
    r.headersOut['Content-Length'] = 15;
    r.sendHeader();
    r.send("nginx");
    r.send("java");
    r.send("script");

    r.finish();
}

function hello(r) {
    r.return(200, "Hello world!");
}

async function fetch(r) {
    let results = await Promise.all([ngx.fetch('https://google.com/'),
                                     ngx.fetch('https://google.ru/')]);

    r.return(200, JSON.stringify(results, undefined, 4));
}

async function hash(r) {
    let hash = await crypto.subtle.digest('SHA-512', r.headersIn.host);
    r.setReturnValue(Buffer.from(hash).toString('hex'));
}

export default {foo, summary, baz, hello, fetch, hash};
```

<a id="directives-87"></a>

## 指令

<a id="index-0"></a>

<a id="js-body-filter"></a>

### js_body_filter

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_body_filter` function | module.function [`buffer_type=``string` | `buffer`];   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------|
| 默认                                                                                   | —                                                                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location, if in location, limit_except                                             |

将 njs 函数设置为响应体过滤器。过滤函数在响应体的每个数据块上被调用,具有以下参数:

| `r`     | [HTTP 请求](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-http-request) 对象   |
|---------|-------------------------------------------------------------------------------------------------------|
| `data`  | 输入的数据块,可以是字符串或 Buffer,具体取决于 buffer_type 值,默认是字符串。                                                     |
| `flags` | 具有以下属性的对象:<br/>- `last` — 布尔值,:samp:true 如果数据是最后一个缓冲区                                                 |

过滤函数可以通过调用 [r.sendBuffer()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#r-sendbuffer) 将其修改后的输入数据块传递给下一个体过滤器。例如,要将响应体中的所有小写字母转换为小写:

```javascript
function filter(r, data, flags) {
    r.sendBuffer(data.toLowerCase(), flags);
}
```

要停止过滤(后续数据块将直接传递给客户端,而不调用 js_body_filter),可以使用 [r.done()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#r-done)。

如果过滤函数更改了响应体的长度,则需要在 [js_header_filter](#js-header-filter) 中清除 `Content-Length` 响应头(如果有的话),以强制使用分块传输编码。

#### NOTE
由于 js_body_filter 处理程序立即返回其结果,因此仅支持同步操作。因此,不支持异步操作,例如 [r.subrequest()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#r-subrequest) 或 [setTimeout()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-timers)。

<a id="index-1"></a>

<a id="js-content"></a>

### js_content

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_content` function | module.function;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认                                                                                   | —                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location, if in location, limit_except     |

将 njs 函数设置为位置内容处理程序。可以引用模块函数。

<a id="index-2"></a>

<a id="js-context-reuse"></a>

### js_context_reuse

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_context_reuse` number;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认                                                                                   | `js_context_reuse 128;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

设置 QuickJS 引擎可重用的 JS 上下文的最大数量。每个上下文用于单个请求。完成的上下文被放入可重用上下文池中。如果池已满,则销毁上下文。

<a id="index-3"></a>

<a id="js-engine"></a>

### js_engine

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_engine` `njs` | `qjs`;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认                                                                                   | `js_engine njs;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

设置用于 njs 脚本的 JavaScript 引擎。`njs` 参数设置 njs 引擎,也是默认使用的。`qjs` 参数设置 QuickJS 引擎。

<a id="index-4"></a>

<a id="js-fetch-buffer-size"></a>

### js_fetch_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_buffer_size` size;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认                                                                                   | `js_fetch_buffer_size 16k;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

设置用于 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 读取和写入的缓冲区大小。

<a id="index-5"></a>

<a id="js-fetch-ciphers"></a>

### js_fetch_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_ciphers` ciphers;          |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认                                                                                   | `js_fetch_ciphers HIGH:!aNULL:!MD5;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

指定与 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 的 HTTPS 连接启用的密码。密码的格式与 OpenSSL 库理解的格式相同。

密码列表取决于已安装的 OpenSSL 版本。可以使用 `openssl ciphers` 命令查看完整列表。

<a id="index-6"></a>

<a id="js-fetch-max-response-buffer-size"></a>

### js_fetch_max_response_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_max_response_buffer_size` size;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认                                                                                   | `js_fetch_max_response_buffer_size 1m;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

设置通过 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 接收到的响应的最大大小。

<a id="index-7"></a>

<a id="js-fetch-protocols"></a>

### js_fetch_protocols

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_protocols` [`TLSv1`] [`TLSv1.1`] [`TLSv1.2`] [`TLSv1.3`];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| 默认                                                                                   | `js_fetch_protocols TLSv1 TLSv1.1 TLSv1.2;`                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                |

启用与 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 的 HTTPS 连接的指定协议。

<a id="index-8"></a>

<a id="js-fetch-timeout"></a>

### js_fetch_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_timeout` time;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认                                                                                   | `js_fetch_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

定义 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 的读取和写入超时。超时仅在两个连续的读/写操作之间设置,而不是针对整个响应。如果在此时间内没有传输数据,连接将被关闭。

<a id="index-9"></a>

<a id="js-fetch-trusted-certificate"></a>

### js_fetch_trusted_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_trusted_certificate` file;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认                                                                                   | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

指定一个包含 PEM 格式的受信任 CA 证书的文件,用于通过 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 验证 HTTPS 证书。

<a id="index-10"></a>

<a id="js-fetch-verify"></a>

### js_fetch_verify

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_verify` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认                                                                                   | `js_fetch_verify on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

启用或禁用使用 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 验证 HTTPS 服务器证书。

<a id="index-11"></a>

<a id="js-fetch-verify-depth"></a>

### js_fetch_verify_depth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_verify_depth` number;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认                                                                                   | `js_fetch_verify_depth 100;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

设置与 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 的 HTTPS 证书链中的验证深度。

<a id="index-12"></a>

<a id="js-fetch-keepalive"></a>

### js_fetch_keepalive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_keepalive` connections;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认                                                                                   | `js_fetch_keepalive 0;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

激活到目标服务器的连接缓存。当值大于 `0` 时,为 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 启用 keepalive 连接。

connections 参数设置每个工作进程的缓存中保留的到目标服务器的空闲 keepalive 连接的最大数量。当超过此数量时,将关闭最近最少使用的连接。

示例:

```nginx
location /fetch {
    js_fetch_keepalive 32;
    js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
    js_content main.fetch_handler;
}
```

<a id="index-13"></a>

<a id="js-fetch-keepalive-requests"></a>

### js_fetch_keepalive_requests

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_keepalive_requests` number;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认                                                                                   | `js_fetch_keepalive_requests 1000;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

设置通过 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 的一个 keepalive 连接可以处理的最大请求数。在达到最大请求数后,连接将被关闭。

定期关闭连接对于释放每个连接的内存分配是必要的。因此,使用过高的最大请求数可能会导致内存使用过多,不建议这样做。

<a id="index-14"></a>

<a id="js-fetch-keepalive-time"></a>

### js_fetch_keepalive_time

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_keepalive_time` time;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认                                                                                   | `js_fetch_keepalive_time 1h;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

限制通过 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 的一个 keepalive 连接可以处理请求的最长时间。达到此时间后,连接将在后续请求处理后关闭。

<a id="index-15"></a>

<a id="js-fetch-keepalive-timeout"></a>

### js_fetch_keepalive_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_keepalive_timeout` time;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认                                                                                   | `js_fetch_keepalive_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

设置与 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 的到目标服务器的空闲 keepalive 连接保持打开的超时时间。

<a id="index-16"></a>

<a id="js-header-filter"></a>

### js_header_filter

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_header_filter` function | module.function;   |
|--------------------------------------------------------------------------------------|--------------------------------------------------|
| 默认                                                                                   | —                                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location, if in location, limit_except           |

将 njs 函数设置为响应头过滤器。该指令允许更改响应头的任意字段。

#### NOTE
由于 js_header_filter 处理程序立即返回其结果,因此仅支持同步操作。因此,不支持异步操作,例如 [r.subrequest()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#r-subrequest) 或 [setTimeout()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-timers)。

<a id="index-17"></a>

<a id="js-import"></a>

### js_import

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_import` module.js | export_name from module.js;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------|
| 默认                                                                                   | —                                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                |

导入实现 njs 中位置和变量处理程序的模块。export_name 用作访问模块函数的命名空间。如果未指定 export_name,则将使用模块名称作为命名空间。

```nginx
js_import http.js;
```

在这里,模块名称 `http` 被用作访问
导出的命名空间。如果导入的模块导出 `foo()`,则使用
`http.foo` 来引用它。

可以指定多个 `js_import` 指令。

<a id="index-18"></a>

<a id="js-path"></a>

### js_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_path` path;        |
|--------------------------------------------------------------------------------------|------------------------|
| 默认                                                                                   | —                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

为 njs 模块设置额外的路径。

<a id="index-19"></a>

<a id="js-periodic"></a>

### js_periodic

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_periodic` module.function [`interval=`\\ time] [`jitter=`\\ number] [`worker_affinity=`\\ mask];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| 默认                                                                                   | —                                                                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location                                                                                               |

指定定期运行的内容处理程序。该处理程序接收会话对象作为其第一个参数,它还可以访问全局对象,如 ngx。

可选的 `interval` 参数设置两次连续运行之间的间隔,默认为 5 秒。

可选的 `jitter` 参数设置位置内容处理程序将被随机延迟的时间,默认情况下没有延迟。

默认情况下,:samp:js_handler 在工作进程 0 上执行。可选的 `worker_affinity` 参数允许指定应在其中执行位置内容处理程序的特定工作进程。每个工作进程集由允许的工作进程的位掩码表示。`all` 掩码允许处理程序在所有工作进程中执行。

示例:

```nginx
example.conf:

location @periodics {
    # 在工作进程 0 中以 1 分钟间隔运行
    js_periodic main.handler interval=60s;

    # 在所有工作进程中以 1 分钟间隔运行
    js_periodic main.handler interval=60s worker_affinity=all;

    # 在工作进程 1 和 3 中以 1 分钟间隔运行
    js_periodic main.handler interval=60s worker_affinity=0101;

    resolver 10.0.0.1;
    js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
}
```

```javascript
example.js:

async function handler(s) {
    let reply = await ngx.fetch('https://example.com/');
    let body = await reply.text();

    ngx.log(ngx.INFO, body);
}
```

<a id="index-20"></a>

<a id="js-preload-object"></a>

### js_preload_object

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_preload_object` name.json | name from file.json;   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------|
| 默认                                                                                   | —                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                 |

在配置时预加载一个不可变对象。name 用作全局变量的名称,通过该变量可以在 njs 代码中访问对象。如果未指定 name,则将使用文件名。

```nginx
js_preload_object map.json;
```

在这里,\`map\` 被用作访问预加载对象时的名称。

可以指定多个 js_preload_object 指令。

<a id="index-21"></a>

<a id="js-set"></a>

### js_set

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_set` $variable function | module.function [`nocache`];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------|
| 默认                                                                                   | —                                                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                       |

为指定变量设置一个 njs 函数。可以引用模块函数。

当变量在给定请求中首次被引用时,该函数会被调用。确切的时刻取决于引用变量的 [阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions)。这可以用于执行一些与变量求值无关的逻辑。例如,如果变量仅在 [log_format](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#log-format) 指令中被引用,其处理程序将不会执行,直到日志阶段。此处理程序可用于在请求被释放之前进行一些清理工作。

从 njs 0.8.6 开始,如果指定了可选参数 `nocache`,则处理程序在每次被引用时都会被调用。由于 rewrite 模块当前的限制,当 `nocache` 变量被 set 指令引用时,其处理程序应始终返回固定长度的值。

#### NOTE
由于 js_set 处理程序立即返回其结果,因此仅支持同步操作。因此,不支持异步操作,如 [r.subrequest()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#r-subrequest) 或 [setTimeout()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-timers)。

<a id="index-22"></a>

<a id="js-shared-dict-zone"></a>

### js_shared_dict_zone

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_shared_dict_zone` `zone=`name:size [`timeout=`time] [`type=``string` | `number`] [`evict`] [`state=`file];   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
| 默认                                                                                   | —                                                                                                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                                                                                             |

设置共享内存区域的 name 和 size,该区域保存在工作进程之间共享的键值字典。

| `type`    | 可选参数,允许将值类型重定义为 `number`;<br/>默认情况下,共享字典使用 `string` 作为键和值   |
|-----------|-------------------------------------------------------------|
| `timeout` | 可选参数,设置从区域中删除所有共享字典条目的时间                                    |
| `evict`   | 可选参数,当区域存储耗尽时删除最旧的键值对                                       |
| `state`   | 可选参数,指定一个以 JSON 格式保存共享字典状态的文件,使其在 nginx 重启后保持持久化            |

示例:

```nginx
example.conf:
    # 创建一个 1MB 的字典,值为字符串,
    # 在 60 秒不活动后删除键值对:
    js_shared_dict_zone zone=foo:1M timeout=60s;

    # 创建一个 512KB 的字典,值为字符串,
    # 当区域溢出时强制删除最旧的键值对:
    js_shared_dict_zone zone=bar:512K timeout=30s evict;

    # 创建一个 32KB 的数字值持久字典:
    js_shared_dict_zone zone=num:32k type=number;

    # 创建一个 1MB 的字符串值字典并具有持久化状态:
    js_shared_dict_zone zone=persistent:1M state=/tmp/dict.json;
```

```javascript
example.js:
    function get(r) {
        r.return(200, ngx.shared.foo.get(r.args.key));
    }

    function set(r) {
        r.return(200, ngx.shared.foo.set(r.args.key, r.args.value));
    }

    function delete(r) {
        r.return(200, ngx.shared.bar.delete(r.args.key));
    }

    function increment(r) {
        r.return(200, ngx.shared.num.incr(r.args.key, 2));
    }
```

<a id="index-23"></a>

<a id="js-var"></a>

### js_var

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_var` $variable [value];   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认                                                                                   | —                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

声明一个 [可写](https://cn.angie.software//angie/docs/configuration/njs-reference.md#r-variables) 变量。
值可以包含文本、变量及其组合。
该变量在重定向后不会被覆盖,不像通过 set 指令创建的变量。

<a id="request-argument"></a>

## 请求参数

每个 HTTP njs 处理程序接收一个参数,即 [请求](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-http-request) 对象。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_limit_conn.md

<!-- review: finished -->

<a id="http-limit-conn"></a>

# Limit Conn

该模块用于限制每个定义的关键字的连接数量，特别是来自单个 IP 地址的连接数量。

并非所有连接都会被计数。仅在请求被服务器处理且整个请求头已被读取的情况下，才会计数连接。

<a id="configuration-example-25"></a>

## 配置示例

```nginx
http {
    limit_conn_zone $binary_remote_addr zone=addr:10m;

    ...

    server {

        ...

        location /download/ {
            limit_conn addr 1;
        }
```

<a id="directives-26"></a>

## 指令

<a id="index-0"></a>

<a id="limit-conn-1"></a>

### limit_conn

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_conn` zone number;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认                                                                                   | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

为给定的键值设置共享内存区和最大允许的连接数。当超过此限制时，服务器将返回 [错误](#limit-conn-status) 作为请求的回复。例如，以下指令

```nginx
limit_conn_zone $binary_remote_addr zone=addr:10m;

server {
    location /download/ {
        limit_conn addr 1;
    }
```

仅允许每个 IP 地址同时建立一个连接。

#### NOTE
在 HTTP/2 和 HTTP/3 中，每个并发请求被视为一个单独的连接。

可以有多个 `limit_conn` 指令。例如，以下配置将限制每个客户端 IP 地址对服务器的连接数量，同时限制对虚拟服务器的总连接数量：

```nginx
limit_conn_zone $binary_remote_addr zone=perip:10m;
limit_conn_zone $server_name zone=perserver:10m;

server {
    ...
    limit_conn perip 10;
    limit_conn perserver 100;
}
```

这些指令仅在当前级别没有定义 `limit_conn` 指令时，从上一级配置级别继承。

<a id="index-1"></a>

<a id="limit-conn-dry-run"></a>

### limit_conn_dry_run

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_conn_dry_run` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认                                                                                   | `limit_conn_dry_run off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

启用干运行模式。在此模式下，连接数量没有限制，但是在 [共享内存区](#limit-conn-zone) 中，超出连接的数量仍然会被正常统计。

<a id="index-2"></a>

<a id="limit-conn-log-level"></a>

### limit_conn_log_level

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_conn_log_level` `info` | `notice` | `warn` | `error`;   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------|
| 默认                                                                                   | `limit_conn_log_level error;`                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                         |

设置服务器限制连接数量时所需的日志记录级别。

<a id="index-3"></a>

<a id="limit-conn-status"></a>

### limit_conn_status

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_conn_status` code;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认                                                                                   | `limit_conn_status 503;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

设置对被拒绝请求的响应状态码。

<a id="index-4"></a>

<a id="limit-conn-zone"></a>

### limit_conn_zone

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_conn_zone` key zone = name:size;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认                                                                                   | —                                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                      |

为共享内存区设置参数，该区域将保留各种键的状态。特别是，状态包括当前的连接数量。键可以包含文本、变量及其组合。键值为空的请求不被计数。

使用示例：

```nginx
limit_conn_zone $binary_remote_addr zone=addr:10m;
```

在这里，客户端 IP 地址作为键。请注意，这里使用的是 `$binary_remote_addr` 变量，而不是 `$remote_addr`。

变量 `$remote_addr` 的大小可以从 7 到 15 字节不等。存储的状态在 32 位平台上占用 32 或 64 字节的内存，在 64 位平台上始终占用 64 字节。

变量 `$binary_remote_addr` 的大小对于 IPv4 地址始终为 4 字节，或对于 IPv6 地址始终为 16 字节。存储的状态在 32 位平台上始终占用 32 或 64 字节，在 64 位平台上始终占用 64 字节。

一个兆字节的区域可以保存大约 32000 个 32 字节的状态或大约 16000 个 64 字节的状态。如果区域存储空间耗尽，服务器将对所有进一步的请求返回 [错误](#limit-conn-status)。

<a id="built-in-variables-2"></a>

## 内置变量

<a id="v-limit-conn-status"></a>

### `$limit_conn_status`

保存连接数量限制的结果：`PASSED` 、`REJECTED` 或 `REJECTED_DRY_RUN`


# https://cn.angie.software/angie/docs/configuration/modules/http/http_limit_req.md

<!-- review: finished -->

<a id="http-limit-req"></a>

# Limit Req

该模块用于限制每个定义键的请求处理速率，特别是来自单个 IP 地址的请求处理速率。该限制是使用"漏桶"方法实现的。

<a id="configuration-example-26"></a>

## 配置示例

```nginx
http {
    limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

    ...

    server {

        ...

        location /search/ {
            limit_req zone=one burst=5;
        }
```

<a id="directives-27"></a>

## 指令

<a id="index-0"></a>

<a id="limit-req-1"></a>

### limit_req

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_req` `zone=`name [`burst=`number] [nodelay | `delay=`number];   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------|
| 默认                                                                                   | —                                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                 |

设置共享内存区域和请求的最大突发大小。如果请求速率超过为区域配置的速率，则其处理将被延迟，以使请求以定义的速率进行处理。过多的请求会被延迟，直到其数量超过最大突发大小，此时请求将以 [错误](#limit-req-status) 终止。默认情况下，最大突发大小等于零。例如，以下指令

```nginx
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;

server {
    location /search/ {
        limit_req zone=one burst=5;
    }
```

平均允许每秒不超过 1 个请求，突发不超过 5 个请求。

如果不希望在请求受到限制时延迟过多的请求，则应使用参数 `nodelay`：

```nginx
limit_req zone=one burst=5 nodelay;
```

`delay` 参数指定过多请求变为延迟的限制。默认值为零，即所有过多的请求都将被延迟。

可以有多个 `limit_req` 指令。例如，以下配置将限制来自单个 IP 地址的请求处理速率，同时限制虚拟服务器的请求处理速率：

```nginx
limit_req_zone $binary_remote_addr zone=perip:10m rate=1r/s;
limit_req_zone $server_name zone=perserver:10m rate=10r/s;

server {
    ...
    limit_req zone=perip burst=5 nodelay;
    limit_req zone=perserver burst=10;
}
```

这些指令仅在当前级别没有定义 `limit_req` 指令时，从上一级配置级别继承。

<a id="index-1"></a>

<a id="limit-req-dry-run"></a>

### limit_req_dry_run

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_req_dry_run` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认                                                                                   | `limit_req_dry_run off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

启用干运行模式。在此模式下，请求处理速率不受限制，但在 [共享内存区域](#limit-req-zone) 中，过多请求的数量仍然会被正常记录。

<a id="index-2"></a>

<a id="limit-req-log-level"></a>

### limit_req_log_level

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_req_log_level` `info` | `notice` | `warn` | `error`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------------|
| 默认                                                                                   | `limit_req_log_level error;`                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                        |

设置服务器由于速率超限而拒绝处理请求或延迟请求处理的日志记录级别。延迟的日志记录级别比拒绝的日志记录级别低一级；例如，如果指定了 `limit_req_log_level notice`，则延迟将以 `info` 级别记录。

<a id="index-3"></a>

<a id="limit-req-status"></a>

### limit_req_status

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_req_status` code;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认                                                                                   | `limit_req_status 503;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

设置拒绝请求时返回的状态码。

<a id="index-4"></a>

<a id="limit-req-zone"></a>

### limit_req_zone

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_req_zone` key `zone=`name:size `rate=`rate;   |
|--------------------------------------------------------------------------------------|------------------------------------------------------|
| 默认                                                                                   | —                                                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                                 |

设置共享内存区域的参数，该区域将为各种键保留状态。特别是，状态存储当前的过多请求数量。键可以包含文本、变量及其组合。键值为空的请求不被计入。

使用示例：

```nginx
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
```

在这里，状态保存在 10 兆字节的区域 `one` 中，该区域的平均请求处理速率不得超过每秒 1 个请求。

客户端 IP 地址作为键。请注意，这里使用的是 `$binary_remote_addr` 变量，而不是 `$remote_addr`。

对于 IPv4 地址，变量 `$binary_remote_addr` 的大小始终为 4 字节，对于 IPv6 地址，大小为 16 字节。存储的状态在 32 位平台上始终占用 64 字节，在 64 位平台上占用 128 字节。

一个兆字节的区域可以保存大约 16000 个 64 字节的状态或大约 8000 个 128 字节的状态。

如果区域存储已耗尽，将删除最近最少使用的状态。如果即便如此仍无法创建新状态，则请求将以 [错误](#limit-req-status) 终止。

`rate` 以每秒请求数（r/s）表示。如果希望速率低于每秒一个请求，则以每分钟请求数（r/m）表示。例如，每秒半个请求表示为 30r/m。

<a id="built-in-variables-3"></a>

## 内置变量

<a id="v-limit-req-status"></a>

### `$limit_req_status`

保持限制请求处理速率的结果：`PASSED`、`DELAYED`、`REJECTED`、`DELAYED_DRY_RUN` 或 `REJECTED_DRY_RUN`


# https://cn.angie.software/angie/docs/configuration/modules/http/http_log.md

<!-- review: finished -->

<a id="http-log"></a>

# Log

该模块以指定格式写入请求日志。

日志在请求处理结束的 `location` 上下文中写入。如果在请求处理过程中发生了 [内部重定向](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#internal),这可能是与原始位置不同的 `location`。

<a id="configuration-example-27"></a>

## 配置示例

```nginx
log_format compression '$remote_addr - $remote_user [$time_local] '
                       '"$request" $status $bytes_sent '
                       '"$http_referer" "$http_user_agent" "$gzip_ratio"';

access_log /spool/logs/angie-access.log compression buffer=32k;
```

<a id="directives-28"></a>

## 指令

<a id="index-0"></a>

<a id="access-log"></a>

### access_log

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `access_log` path [format [`buffer=`size] [`gzip=`level]] [`flush=`time] [`if=`condition];<br/><br/>`access_log` `off`;                              |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `access_log logs/access.log combined;`<br/>(路径取决于 [构建参数](https://cn.angie.software//angie/docs/installation/sourcebuild.md#paths) `--http-log-path`) |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location, limit_except                                                                                                 |

设置日志的路径、格式和缓冲写入设置。可以在同一配置级别使用多个日志。通过在第一个参数中指定 "syslog:" 前缀来配置记录到 [syslog](https://cn.angie.software//angie/docs/configuration/processing.md#syslog-logging)。特殊值 off 取消当前级别的所有 access_log 指令。如果未指定格式,则使用预定义的 "combined" 格式。

如果使用 `buffer` 参数指定了缓冲区大小或指定了 `gzip` 参数,则写入将被缓冲。

#### WARNING
缓冲区大小不得超过对磁盘文件的原子写入大小。对于 FreeBSD,此大小是无限的。

启用缓冲时,数据在以下情况下写入文件:

* 如果下一条日志行无法放入缓冲区;
* 如果缓冲区中的数据存在时间超过 flush 参数指定的时间间隔;
* 当 [重新打开日志文件](https://cn.angie.software//angie/docs/configuration/runtime.md#log-rotation) 或终止工作进程时。

如果指定了 `gzip` 参数,缓冲区将在写入文件之前被压缩。压缩级别可以设置在 1(更快,但压缩效果较差)到 9(较慢,但压缩效果更好)的范围内。默认情况下,使用 64K 字节的缓冲区大小和压缩级别 1。数据以原子块的形式压缩,并且可以随时使用 **zcat** 实用程序解压缩或读取日志文件。

示例:

```nginx
access_log /path/to/log.gz combined gzip flush=5m;
```

#### NOTE
要支持日志的 gzip 压缩,Angie 必须使用 zlib 库构建。

文件路径中可以使用变量,但此类日志有一些限制:

* 工作进程运行所使用的凭据的 [用户](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 必须具有在包含此类日志的目录中创建文件的权限;
* 缓冲不起作用;
* 每次日志写入时打开文件,写入后立即关闭。但是,由于常用文件的描述符可以存储在缓存中,因此在 [open_log_file_cache](#open-log-file-cache) 指令的 valid 参数指定的时间内进行日志轮换时,可能会继续写入旧文件。
* 对于每次日志写入,都会检查请求的根目录是否存在——如果该目录不存在,则不会创建日志。因此 [root](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#root) 和 [access_log](#access-log) 应该在同一配置级别描述:

```nginx
server {
    root       /spool/vhost/data/$host;
    access_log /spool/vhost/logs/$host;
    ...
```

`if` 参数启用条件日志记录。如果条件评估结果为 `"0"` 或空字符串,则不会记录请求。在以下示例中,响应代码为 2xx 和 3xx 的请求将不会被记录:

```nginx
map $status $loggable {
    ~^[23]  0;
    default 1;
}

access_log /path/to/access.log combined if=$loggable;
```

<a id="index-1"></a>

<a id="log-format"></a>

### log_format

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `log_format` name [`escape`=:samp:default | `json` | `none`] string ...;   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------|
| 默认值                                                                                  | `log_format combined "...";`                                               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                                                       |

指定日志格式。

`escape` 参数允许将变量中的字符转义设置为 `json` 或 `default`;默认使用 `default`。
`none` 值禁用字符转义。

使用 `default` 时,字符 """、"\\" 以及值小于 32 或大于 126 的字符将被转义为 "\\xXX"。如果未找到变量值,则将连字符 "-" 作为值写入日志。

使用 `json` 时,所有 JSON 字符串中不允许的字符都将被转义:字符 """ 和 "\\" 被转义为 "\\"" 和 "\\\\",值小于 32 的字符被转义为 "\\n"、"\\r"、"\\t"、"\\b"、"\\f" 或 "\\u00XX"。

发送到客户端的标头行以前缀 `sent_http_` 开头,例如 `$sent_http_content_range`。

预定义格式 `combined` 始终存在于配置中:

```nginx
log_format combined '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent"';
```

<a id="index-2"></a>

<a id="open-log-file-cache"></a>

### open_log_file_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `open_log_file_cache` `max=`N [`inactive=`time] [`min_uses=`N] [`valid=`time];<br/><br/>`open_log_file_cache` `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `open_log_file_cache off;`                                                                                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                 |

定义一个缓存,用于存储使用变量指定名称的常用日志的文件描述符。参数:

| `max`      | 设置缓存中描述符的最大数量;当缓存溢出时,最近最少使用 (LRU) 的描述符将被关闭。                     |
|------------|-----------------------------------------------------------------|
| `inactive` | 设置在此时间内未访问缓存描述符后关闭它的时间。<br/>默认为 10 秒。                           |
| `min_uses` | 设置在 `inactive` 参数指定的时间内文件使用的最小次数,之后文件描述符将在缓存中保持打开状态。<br/>默认为 1。 |
| `valid`    | 指定在多长时间后检查文件是否仍以相同名称存在。<br/>默认为 60 秒。                           |
| `off`      | 禁用缓存。                                                           |

使用示例:

```nginx
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
```


# https://cn.angie.software/angie/docs/configuration/modules/http/http_map.md

<!-- review: finished -->

<a id="http-map"></a>

# Map

该模块创建的变量值依赖于其他变量的值。

<a id="configuration-example-28"></a>

## 配置示例

```nginx
map $http_host $name {
    hostnames;

    default       0;

    example.com   1;
    *.example.com 1;
    example.org   2;
    *.example.org 2;
    .example.net  3;
    wap.*         4;
}

map $http_user_agent $mobile {
    default       0;
    "~Opera Mini" 1;
}
```

<a id="directives-29"></a>

## 指令

<a id="index-0"></a>

<a id="map"></a>

### map

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `map` string $variable { ... }   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认                                                                                   | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                             |

创建一个新变量。其值取决于第一个参数，该参数作为带变量的字符串指定，例如：

```nginx
set $var1 "foo";
set $var2 "bar";

map $var1$var2 $new_variable {
    default "foobar_value";
}
```

这里，变量 `$new_variable` 的值将由两个变量 `$var1` 和 `$var2` 组成，或者在这些变量未定义时使用默认值。

#### NOTE
由于变量仅在使用时被评估，因此即使声明大量的"map"变量也不会给请求处理增加额外的成本。

map 块中的参数指定源值和结果值之间的映射。

源值可以作为字符串或正则表达式指定。

字符串匹配时忽略大小写。

正则表达式应以 `~` 符号开头以进行区分大小写的匹配，或者以 `~*` 符号开头以进行不区分大小写的匹配。正则表达式可以包含命名和位置捕获，稍后可以在其他指令中与结果变量一起使用。

如果源值与下面描述的特殊参数之一匹配，则应以 `\` 符号为前缀。

结果值可以包含文本、变量及其组合。

还支持以下特殊参数：

| `default` value   | 如果源值与指定的变体都不匹配，则设置结果值。当未指定 default 时，默认结果值将为空字符串。   |
|-------------------|-----------------------------------------------------|
| `hostnames`       | 表示源值可以是带有前缀或后缀掩码的主机名。该参数应在值列表之前指定。                  |

例如，

```nginx
*.example.com 1;
example.*     1;
```

以下两个记录

```nginx
example.com   1;
*.example.com 1;
```

可以合并为：

```nginx
.example.com  1;
```

| `include` file   | 包含一个包含值的文件。可以有多个包含。   |
|------------------|-----------------------|
| `volatile`       | 表示该变量不可缓存。            |

如果源值与多个指定变体匹配，例如掩码和正则表达式都匹配，将选择第一个匹配的变体，优先顺序如下：

1. 没有掩码的字符串值
2. 带有前缀掩码的最长字符串值，例如 `*.example.com`
3. 带有后缀掩码的最长字符串值，例如 `mail.*`
4. 第一个匹配的正则表达式（按在配置文件中的出现顺序）
5. 默认值 (`default`)

<a id="index-1"></a>

<a id="map-hash-bucket-size"></a>

### map_hash_bucket_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `map_hash_bucket_size` size;      |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认                                                                                   | `map_hash_bucket_size 32|64|128;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                              |

设置 [map](#id3) 变量哈希表的桶大小。默认值取决于处理器的缓存行大小。设置哈希表的详细信息请参见 [单独](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes)。

<a id="index-2"></a>

<a id="map-hash-max-size"></a>

### map_hash_max_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `map_hash_max_size` size;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认                                                                                   | `map_hash_max_size 2048;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                        |

设置 [map](#id3) 变量哈希表的最大大小。设置哈希表的详细信息请参见 [单独](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes)。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_memcached.md

<!-- review: finished -->

<a id="http-memcached"></a>

# Memcached

该模块用于从 memcached 服务器获取响应。键在 [$memcached_key](#v-memcached-key) 变量中设置。响应应该通过 Angie 外部的方式预先放入 memcached。

<a id="configuration-example-29"></a>

## 配置示例

```nginx
server {
    location / {
        set            $memcached_key "$uri?$args";
        memcached_pass host:11211;
        error_page     404 502 504 = @fallback;
    }

    location @fallback {
        proxy_pass     http://backend;
    }
}
```

<a id="directives-30"></a>

## 指令

<a id="index-0"></a>

<a id="memcached-bind"></a>

### memcached_bind

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `memcached_bind` address [`transparent`] | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------|
| 默认值                                                                                  | —                                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                              |

使到 memcached 服务器的出站连接源自指定的本地 IP 地址和可选端口。参数值可以包含变量。特殊值 `off` 取消从上一配置级别继承的 memcached_bind 指令的效果,允许系统自动分配本地 IP 地址和端口。

`transparent` 参数允许到 memcached 服务器的出站连接源自非本地 IP 地址,例如来自客户端的真实 IP 地址:

```nginx
memcached_bind $remote_addr transparent;
```

为了使此参数生效,通常需要以 [超级用户](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 权限运行 Angie 工作进程。在 Linux 上不需要这样做,因为如果指定了 `transparent` 参数,工作进程会从主进程继承 CAP_NET_RAW 能力。

#### NOTE
需要配置内核路由表以拦截来自 memcached 服务器的网络流量。

<a id="index-1"></a>

<a id="memcached-buffer-size"></a>

### memcached_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `memcached_buffer_size` size;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `memcached_buffer_size 4k|8k;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

设置用于读取从 memcached 服务器接收的响应的第一部分的缓冲区大小。响应在接收后立即同步传递给客户端。

<a id="index-2"></a>

<a id="memcached-connect-timeout"></a>

### memcached_connect_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `memcached_connect_timeout` time;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `memcached_connect_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

定义与 memcached 服务器建立连接的超时时间。需要注意的是,此超时时间通常不能超过 75 秒。

<a id="index-3"></a>

<a id="memcached-gzip-flag"></a>

### memcached_gzip_flag

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `memcached_gzip_flag` flag;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | —                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

启用对 memcached 服务器响应中标志存在的测试,如果设置了该标志,则将 `Content-Encoding` 响应头字段设置为 "gzip"。

<a id="index-4"></a>

<a id="memcached-next-upstream"></a>

### memcached_next_upstream

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `memcached_next_upstream` `error` | `timeout` | `invalid_response` | `not_found` | `off` ...;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `memcached_next_upstream error timeout;`                                                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                          |

指定在哪些情况下应将请求传递给 [上游池](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 中的下一个服务器:

| `error`            | 与服务器建立连接、向其传递请求或读取响应头时发生错误;   |
|--------------------|-------------------------------|
| `timeout`          | 与服务器建立连接、向其传递请求或读取响应头时发生超时;   |
| `invalid_response` | 服务器返回空响应或无效响应;                |
| `not_found`        | 在服务器上未找到响应;                   |
| `off`              | 禁用将请求传递给下一个服务器。               |

#### NOTE
应该记住,只有在尚未向客户端发送任何内容时,才可能将请求传递给下一个服务器。也就是说,如果在传输响应的过程中发生错误或超时,则无法修复此问题。

该指令还定义了什么被视为与服务器通信的 [失败尝试](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#max-fails)。

| `error`、`timeout`、`invalid_response`   | 始终被视为失败尝试,即使未在指令中指定   |
|----------------------------------------|-----------------------|
| `not_found`                            | 从不被视为失败尝试             |

将请求传递给下一个服务器可以受到 [尝试次数](#memcached-next-upstream-tries) 和 [时间](#memcached-next-upstream-timeout) 的限制。

<a id="index-5"></a>

<a id="memcached-next-upstream-timeout"></a>

### memcached_next_upstream_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `memcached_next_upstream_timeout` time;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | `memcached_next_upstream_timeout 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                    |

限制可以将请求传递给 [下一个](#memcached-next-upstream) 服务器的时间。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-6"></a>

<a id="memcached-next-upstream-tries"></a>

### memcached_next_upstream_tries

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `memcached_next_upstream_tries` number;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | `memcached_next_upstream_tries 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                    |

限制将请求传递给 [下一个](#memcached-next-upstream) 服务器的可能尝试次数。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-7"></a>

<a id="memcached-pass"></a>

### memcached_pass

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `memcached_pass` address;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location, if in location    |

设置 memcached 服务器地址。地址可以指定为域名或 IP 地址以及端口:

```nginx
memcached_pass localhost:11211;
```

或作为 UNIX 域套接字路径:

```nginx
memcached_pass unix:/tmp/memcached.socket;
```

如果域名解析为多个地址,则所有地址都将以轮询方式使用。此外,地址可以指定为 [服务器组](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream)。

#### NOTE
If `memcached_pass` is placed in a `location` whose prefix ends with a slash
(for example, `location /name/`),
and the [auto_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#auto-redirect) directive is set to `default`,
requests without a trailing slash will be redirected (`/name -> /name/`).

<a id="index-8"></a>

<a id="memcached-read-timeout"></a>

### memcached_read_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `memcached_read_timeout` time;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `memcached_read_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

定义从 memcached 服务器读取响应的超时时间。超时仅在两次连续的读取操作之间设置,而不是用于整个响应的传输。如果 memcached 服务器在此时间内未传输任何内容,则连接将关闭。

<a id="index-9"></a>

<a id="memcached-send-timeout"></a>

### memcached_send_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `memcached_send_timeout` time;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `memcached_send_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

设置向 memcached 服务器传输请求的超时时间。超时仅在两次连续的写入操作之间设置,而不是用于整个请求的传输。如果 memcached 服务器在此时间内未接收任何内容,则连接将关闭。

<a id="index-10"></a>

<a id="memcached-socket-keepalive"></a>

### memcached_socket_keepalive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `memcached_socket_keepalive` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------------|
| 默认值                                                                                  | `memcached_socket_keepalive off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                       |

配置到 memcached 服务器的出站连接的 "TCP keepalive" 行为。

| `off`   | 默认情况下,套接字使用操作系统的设置。        |
|---------|----------------------------|
| `on`    | 为套接字启用 SO_KEEPALIVE 套接字选项。 |

<a id="built-in-variables-4"></a>

## 内置变量

<a id="v-memcached-key"></a>

### `$memcached_key`

定义用于从 memcached 服务器获取响应的键。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_metric.md

<a id="http-metric"></a>

# Metric

`ngx_http_metric_module` 模块允许创建任意的实时计算指标。这些指标值存储在共享内存中，并在 `/status/http/metric_zones/` API 分支中实时显示。
支持多种数据聚合类型（计数器、直方图、移动平均等），并可按任意键进行分组。

<a id="configuration-example-30"></a>

## 配置示例

统计 API 请求：

```nginx
http {
    metric_zone api_requests:1m count;

    server {
        listen 80;

        location /api/ {
            allow 127.0.0.1;
            deny all;
            api /status/;

            metric api_requests $http_user_agent on=request;
        }
    }
}
```

如果使用此配置向 `/api/` 发起请求：

```console
$ curl 127.0.0.1/api/ --user-agent "Firefox"
```

`api_requests` 指标会实时更新：

```json
{
    "http": {
       "metric_zones": {
           "api_requests": {
               "discarded": 0,
               "metrics": {
                   "Firefox": 1
               }
           }
       }
    }
}
```

<a id="directives-31"></a>

## 指令

<a id="index-0"></a>

<a id="metric-zone"></a>

### metric_zone

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `metric_zone` name:size [`expire`=`on`| `off`] [`discard_key`=`name`] mode [parameters];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                                                                       |

创建一个指定 size 大小和给定 name 名称的共享内存区域来存储指标。该区域名称作为 `/status/http/metric_zones/` 分支中的节点。

参数：

- `expire=<on|off>` — 区域满时的行为：
  - 如果为 `on`，则丢弃最旧的指标（按更新时间）以释放内存供新指标使用；
  - 如果为 `off` （默认）— 丢弃新传入的指标，保留现有条目。
- `discard_key=<name>` — 定义一个键为 name 的指标，用于累积被丢弃指标的值。默认情况下不创建此类指标。保留键不能手动更新。
- mode — 数据处理算法（参见 [操作模式](#metric-modes) 部分）；
- parameters — 所选模式的附加设置（例如，`average exp` 的 `factor`）。

使用示例：

```nginx
metric_zone request_time:1m max;
```

在 API 树中，共享内存区域模板如下所示：

```json
{
    "discarded": 0,
    "metrics": {
        "key1": 123,
        "key2": 10.5,
    }
}
```

| `discarded`   | 数字；共享内存区域中被丢弃的指标数量   |
|---------------|----------------------|
| `metrics`     | 对象；其成员是具有定义键和计算值的指标  |

#### NOTE
在 1 MB 区域中，键大小为 39 字节且单一指标模式时，大约可以存储 8,000 个唯一键条目。

<a id="index-1"></a>

<a id="metric-complex-zone"></a>

### metric_complex_zone

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `metric_complex_zone` name:size [`expire`=`on`| `off`] [`discard_key`=`name`] { ... }   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                                                                    |

定义一个 复合指标 — 一组具有独立模式的指标。
块体中的每一行定义一个 子指标名称、一个 模式 以及可选的模式 参数。

使用示例：

```nginx
metric_complex_zone requests:1m expire=on discard_key="old" {
    # 子指标名称      模式          参数
    min_time           min;
    avg_time           average exp   factor=60;
    max_time           max;
    total              count;
}
```

在 API 树中，这样的复合指标模板如下所示：

```json
{
    "discarded": 3,
    "metrics": {
        "key1": {
            "min_time": 20,
            "avg_time": 50,
            "max_time": 80,
            "total": 2
        },
        "old": {
             "min_time": 3,
             "avg_time": 40,
             "max_time": 152,
             "total": 80
        }
    }
}
```

| `discarded`   | 数字；共享内存区域中被丢弃的指标数量                    |
|---------------|---------------------------------------|
| `metrics`     | 对象；其成员是具有设定键的复合指标。它们是包含一组具有计算值的子指标的对象 |

<a id="index-2"></a>

<a id="metric"></a>

### metric

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `metric` name key=value [`on`=`request`| `response`| `end`];   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------|
| 默认值                                                                                  | —                                                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                         |

计算指定共享内存区域 name 的指标值。

参数：

- key — 任意字符串（通常是变量），用于对值进行分组。
  : 最大长度为 255 字节。如果键更长，将被截断为 255 字节并附加省略号 `...`；
- value — 由所选模式处理的数字（可以是变量）。
  : 如果省略，默认为 `0`。如果参数无法转换为数字，则默认为 `1`；
- `on` — 可选参数，指定何时计算指标：
  - 如果为 `on=request`，在接收到请求时计算；
  - 如果为 `on=response`，在准备响应期间计算；
  - 如果为 `on=end` （默认），在发送响应后计算。

#### NOTE
在内部重定向的情况下，`on=request` 阶段的指标在原始 `location` 中计算。但是，`on=response` 和 `on=end` 指标将在新的 `location` 中计算。

使用示例：

```nginx
metric requests $http_user_agent=$request_time;
```

#### NOTE
具有空键或无效 `key=value` 对的指标将被忽略。
省略的 value 被视为 `0`：

```nginx
metric foo $bar;  # 等同于 $bar=0
```

这对于 `count` 模式很有用，该模式忽略数值，只对指标被更新这一事实做出反应。

#### NOTE
请记住，变量在不同阶段进行求值。例如，无法在 `on=request` （接收请求时）使用 `$bytes_sent` （发送给客户端的字节数）。

<a id="metric-modes"></a>

## 操作模式

可用指标操作模式列表：

* `count` — 计数器；
* `gauge` — 仪表（增加/减少）；
* `last` — 最后接收到的值；
* `min` — 最小值；
* `max` — 最大值；
* `average exp` — 指数移动平均（EMA）（参数 `factor`）；
* `average mean` — 窗口内的平均值（参数 `window` 和 `count`）；
* `histogram` — 跨"桶"的分布（阈值列表）。

<a id="count"></a>

### count

计数器在每次指标更新时将其值增加 `1`。

默认值 — `0`。

#### NOTE
任何指标更新（使用任何值）都会单调地将计数器增加 `1`。

示例：

```nginx
metric_zone count:1m count;

# 作为复合指标的一部分：
#
# metric_complex_zone count:1m {
#     some_metric_name  count;
# }

server {
    listen 80;

    location /metric/ {
        metric count KEY;
    }

    location ~ ^/metric/set/(.+)$ {
        metric count KEY=$1;
    }

    location /api/ {
        api /status/http/metric_zones/count/metrics/;
    }
}
```

更新指标：

```console
$ curl 127.0.0.1/metric/
$ curl 127.0.0.1/metric/set/1
$ curl 127.0.0.1/metric/set/23
$ curl 127.0.0.1/metric/set/-32
```

API 中的预期指标值：

```json
{
    "KEY": 4
}
```

<a id="gauge"></a>

### gauge

gauge 根据传入数字的符号增加或减少其值。正值增加计数器,负值减少计数器。值为 `0` 时不改变计数器。

默认值 — `0`。

示例:

```nginx
metric_zone gauge:1m gauge;

# 作为复杂指标的一部分:
#
# metric_complex_zone gauge:1m {
#     some_metric_name  gauge;
# }

server {
    listen 80;

    location /metric/ {
        metric gauge KEY;
    }

    location ~ ^/metric/set/(.+)$ {
        metric gauge KEY=$1;
    }

    location /api/ {
        api /status/http/metric_zones/gauge/metrics/;
    }
}
```

更新指标:

```console
$ curl 127.0.0.1/metric/
```

API 中的预期指标值:

```json
{
    "KEY": 0
}
```

进一步更新:

```console
$ curl 127.0.0.1/metric/set/5
$ curl 127.0.0.1/metric/set/-5
$ curl 127.0.0.1/metric/set/8
```

API 中的预期指标值:

```json
{
    "KEY": 8
}
```

<a id="last"></a>

### last

存储最后接收到的值,不进行任何聚合。如果省略 value,则使用 `0`。

示例:

```nginx
metric_zone last:1m last;

# 作为复杂指标的一部分:
#
# metric_complex_zone last:1m {
#     some_metric_name  last;
# }

server {
    listen 80;

    location /metric/ {
        metric last KEY;
    }

    location ~ ^/metric/set/(.+)$ {
        metric last KEY=$1;
    }

    location /api/ {
        api /status/http/metric_zones/last/metrics/;
    }
}
```

更新指标:

```console
$ curl 127.0.0.1/metric/
```

API 中的预期指标值:

```json
{
    "KEY": 0
}
```

进一步更新:

```console
$ curl 127.0.0.1/metric/set/8000
$ curl 127.0.0.1/metric/set/37
$ curl 127.0.0.1/metric/set/-3.5
```

API 中的预期指标值:

```json
{
   "KEY": -3.5
}
```

<a id="min"></a>

### min

保存两个值中的最小值 — 当前存储的值和新值。

示例:

```nginx
metric_zone min:1m min;

# 作为复杂指标的一部分:
#
# metric_complex_zone min:1m {
#     some_metric_name  min;
# }

server {
    listen 80;

    location /metric/ {
        metric min KEY;
    }

    location ~ ^/metric/set/(.+)$ {
        metric min KEY=$1;
    }

    location /api/ {
        api /status/http/metric_zones/min/metrics/;
    }
}
```

更新指标:

```console
$ curl 127.0.0.1/metric/set/42.999
$ curl 127.0.0.1/metric/set/-512
$ curl 127.0.0.1/metric/set/1
$ curl 127.0.0.1/metric/
```

API 中的预期指标值:

```json
{
    "KEY": -512
}
```

<a id="max"></a>

### max

保存两个值中的最大值 — 当前存储的值和新值。

示例:

```nginx
metric_zone max:1m max;

# 作为复杂指标的一部分:
#
# metric_complex_zone max:1m {
#     some_metric_name  max;
# }

server {
    listen 80;

    location /metric/ {
        metric max KEY;
    }

    location ~ ^/metric/set/(.+)$ {
        metric max KEY=$1;
    }

    location /api/ {
        api /status/http/metric_zones/max/metrics/;
    }
}
```

更新指标:

```console
$ curl 127.0.0.1/metric/set/42.999
$ curl 127.0.0.1/metric/set/-512
$ curl 127.0.0.1/metric/set/1
$ curl 127.0.0.1/metric/
```

API 中的预期指标值:

```json
{
    "KEY": 42.999
}
```

<a id="average-exp"></a>

### average exp

使用 [指数平滑](https://en.wikipedia.org/wiki/Exponential_smoothing) 算法计算平均值。

接受可选参数 `factor=<number>` — 决定新值对平均值影响程度的系数。允许的整数值范围为 `0` 到 `99`。默认值为 `90`。

系数越高,新值的权重越大。如果指定 `90`,结果将是新值的 `90%` 加上先前平均值的 `10%`。

示例:

```nginx
metric_zone avg_exp:1m average exp factor=60;

# 作为复杂指标的一部分:
#
# metric_complex_zone avg_exp:1m {
#     some_metric_name  average exp  factor=60;
# }

server {
    listen 80;

    location ~ ^/metric/set/(.+)$ {
        metric avg_exp KEY=$1;
    }

    location /api/ {
        api /status/http/metric_zones/avg_exp/metrics/;
    }
}
```

更新指标:

```console
$ curl 127.0.0.1/metric/set/100
$ curl 127.0.0.1/metric/set/200
$ curl 127.0.0.1/metric/set/0
$ curl 127.0.0.1/metric/set/8
$ curl 127.0.0.1/metric/set/30
```

API 中的预期指标值:

```json
{
    "KEY": 30.16
}
```

<a id="average-mean"></a>

### average mean

计算算术平均值。接受可选参数 `window=<off|time>` 和 `count=<number>`,分别定义用于平均的时间间隔和样本大小。默认值:`window=off`(使用整个样本)和 :samp:`count=10`。

#### NOTE
例如,:samp:window=5s 将仅考虑最近 5 秒内的事件。`window` 参数不能为 `0`。`count=number` 参数控制样本大小(缓存值),以实现更平滑的平均值计算。

示例:

```nginx
metric_zone avg_mean:1m average mean window=5s count=8;

# 作为复杂指标的一部分:
#
# metric_complex_zone avg_mean:1m {
#     some_metric_name  average mean  window=5s count=8;
# }

server {
    listen 80;

    location ~ ^/metric/set/(.+)$ {
        metric avg_mean KEY=$1;
    }

    location /api/ {
        api /status/http/metric_zones/avg_mean/metrics/;
    }
}
```

更新指标:

```console
$ curl 127.0.0.1/metric/set/0.1
$ curl 127.0.0.1/metric/set/0.1
$ curl 127.0.0.1/metric/set/0.4
$ curl 127.0.0.1/metric/set/10
$ curl 127.0.0.1/metric/set/1
$ curl 127.0.0.1/metric/set/1
```

API 中的预期指标值:

```json
{
    "KEY": 2.1
}
```

如果从最后一次更新等待 5 秒,预期值将为:

```json
{
    "KEY": 0
}
```

<a id="histogram"></a>

### histogram

创建一组"桶",如果新值不超过桶的阈值,则递增相关计数器。参数以数值阈值列表的形式提供。对于分析分布(如响应时间)很有用。

必需参数是 numbers — 桶的阈值,按升序列出。

#### NOTE
桶值 `inf` 或 `+Inf` 可用于捕获所有超过最高指定桶的值。

示例:

```nginx
metric_zone hist:1m histogram 0.1 0.2 0.5 1 2 inf;

# 作为复杂指标的一部分:
#
# metric_complex_zone hist:1m {
#     some_metric_name  histogram  0.1 0.2 0.5 1 2 inf;
# }

server {
    listen 80;

    location ~ ^/metric/set/(.+)$ {
        metric histogram KEY=$1;
    }

    location /api/ {
        api /status/http/metric_zones/hist/metrics/;
    }
}
```

更新指标:

```console
$ curl 127.0.0.1/metric/set/0.25
```

API 中的预期指标值:

```json
{
    "KEY": {
        "0.1": 0,
        "0.2": 0,
        "0.5": 1,
        "1": 1,
        "2": 1,
        "inf": 1
    }
}
```

进一步更新:

```console
$ curl 127.0.0.1/metric/set/2
```

API 中的预期指标值:

```json
{
    "KEY": {
        "0.1": 0,
        "0.2": 0,
        "0.5": 1,
        "1": 1,
        "2": 2,
        "inf": 2
    }
}
```

进一步更新:

```console
$ curl 127.0.0.1/metric/set/1000
```

API 中的预期指标值:

```json
{
    "KEY": {
       "0.1": 0,
       "0.2": 0,
       "0.5": 1,
       "1": 1,
       "2": 2,
       "inf": 3
    }
}
```

<a id="built-in-variables-5"></a>

## 内置变量

为每个指标创建以下变量:

- `$metric_<name>`
- `$metric_<name>_key`
- `$metric_<name>_value`

对于复杂指标,会添加额外的变量:

- `$metric_<name>_value_<metric>`

<a id="v-metric-zone"></a>

### `$metric_<name>`

与 [metric](#id5) 指令类似，`$metric_<name>` 变量设置器可用于更新指标。计算发生在
[Rewrite](https://angie.software/angie/docs/configuration/modules/http/http_rewrite/) 阶段，
允许从 [njs](https://angie.software/angie/docs/configuration/modules/http/http_js/) 模块处理指标。

用于设置变量的值必须遵循 `key=value` 结构。
键和值都可以由文本、变量及其组合构成。
键是用于分组值的任意字符串。值是由所选模式处理的数字。
如果省略，则默认为 `0`。
如果参数无法转换为数字，则默认为 `1`。

使用示例：

```nginx
http {
    metric_zone counter:1m count;

    # 此时添加了 $metric_counter 变量

    server {
        listen 80;

        location /metric/ {
            set $metric_counter $http_user_agent;  # 等同于 $http_user_agent=0
        }

        location /api/ {
            allow 127.0.0.1;
            deny all;
            api /status/http/metric_zones/counter/;
        }
    }
}
```

使用 [njs](https://angie.software/angie/docs/configuration/modules/http/http_js/) 模块计算指标：

```nginx
http {
    js_import metrics.js;

    resolver 127.0.0.53;

    metric_complex_zone requests:1m {
        min_time        min;
        max_time        max;
        total           count;
    }

    location /metric/ {
        js_content metrics.js_request;
        js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
    }

    location /api/ {
        allow 127.0.0.1;
        deny all;
        api /static/http/metric_zones/requests/;
    }
}
```

文件 `metrics.js`：

```js
async function js_request(r) {
    let start_time = Date.now();

    let results = await Promise.all([ngx.fetch('https://google.com/'),
                                     ngx.fetch('https://google.ru/')]);

    // 使用 $metric_requests 变量设置器
    r.variables.metric_requests = `google={Date.now() - start_time}`;
}

export default {js_request};
```

在对 `location /metric/` 发起多次请求后，值可能如下所示：

```json
{
    "discarded": 0,
    "metrics": {
        "google": {
            "min_time": 70,
            "max_time": 432,
            "total": 6
        }
    }
}
```

#### NOTE
设置变量后，可以获取其值；它将等于
指定的 `key=value` 对。

此外，存储在 `$metric_<name>_key` 变量中的值
将更改为指定的键。

<a id="v-metric-zone-key"></a>

<a id="v-metric-zone-value"></a>

### `$metric_<name>_key` 和 `$metric_<name>_value`

`$metric_<name>_key` 和 `$metric_<name>_value` 变量
分别定义键和值。当设置 `$metric_<name>_value` 时会发生指标更新，
前提是 `$metric_<name>_key` 中的键已经定义。

#### NOTE
对于复杂指标，`$metric_<name>_value` 变量中的子指标值
使用 `", "` 分隔符连接。

使用示例：

```nginx
http {
    metric_zone gauge:1m gauge;

    # 此处添加了变量 $metric_gauge、$metric_gauge_key 和 $metric_gauge_value。

    metric_complex_zone complex:1m {
        hist histogram 1 2 3;
        avg  average exp;
    }

    # 此处添加了 $metric_complex、$metric_complex_key 和 $metric_complex_value。

    server {
        listen 80;

        location /gauge/ {
            set $metric_gauge_key "foo";
            set $metric_gauge_value 1;

            # 或者：set $metric_gauge foo=1;

            return 200 "Updated with '$metric_gauge'\nValue='$metric_gauge_value'\n";
        }

        location /complex/ {
            set $metric_complex_key "foo";
            set $metric_complex_value 3;

            # 或者：set $metric_complex foo=3;

            return 200 "Updated with '$metric_complex'\nValue='$metric_complex_value'\n";
        }
    }
}
```

使用此配置，对 `/gauge/` 的请求产生：

```console
$ curl 127.0.0.1/gauge/
Updated with 'foo=1'
Value='1'
```

对于 `/complex/`：

```console
$ curl 127.0.0.1/complex/
Updated with 'foo=3'
Value='0 0 1, 3'
```

#### NOTE
如果将空字符串赋值给 `$metric_<name>_value`，该值将被
识别为 `0`。如果字符串由无法转换为数字的字符组成，
则被识别为 `1`。

仅在 `$metric_<name>_key` 和
`$metric_<name>_value` 都已设置后才会进行计算。

在这种情况下，存储在 `$metric_<name>` 中的值将等于
新的 `key=value` 对。

`$metric_<name>_key` 中的值表示通过变量指定的最后一个键。

`$metric_<name>_value` 中的值表示为
`$metric_<name>_key` 中设置的键计算的最后一个值。

<a id="v-metric-zone-value-metric"></a>

### `$metric_<name>_value_<metric>`

对于复杂指标，可以使用 `$metric_<name>_value_<metric>` 变量获取
特定子指标的值，其中 <metric> 是子指标的名称。

使用示例：

```nginx
http {
    metric_complex_zone foo:1m {
        count count;
        min   min;
        avg   average exp;
    }

    # 添加 $metric_foo、$metric_foo_key、$metric_foo_value，
    # 以及 $metric_foo_value_count、$metric_foo_value_min、$metric_foo_value_avg。

    server {
        listen 80;

        location /foo/ {
            set $metric_foo_key   bar;
            set $metric_foo_value 9;

            # 或者：set $metric_foo bar=9;

            return 200 "Updated with '$metric_foo'\nValues='$metric_foo_value'\nCount='$metric_foo_value_count'\n";
        }
    }
}
```

使用此配置，对 `/foo/` 的请求产生：

```console
$ curl 127.0.0.1/foo/
Updated with 'bar=9'
Values='1, 9, 9'
Count='1'
```

<a id="additional-examples"></a>

## 其他示例

<a id="monitoring-http-methods"></a>

### 监控 HTTP 方法

```nginx
metric_zone http_methods:1m count;

server {
    listen 80;

    location / {
        metric http_methods $request_method;
    }

    location /metrics/ {
        allow 127.0.0.1;
        deny all;
        api /status/http/metric_zones/http_methods/metrics/;
    }
}
```

响应：

```json
{
    "GET": 65,
    "POST": 20,
    "PUT": 10,
    "DELETE": 5
}
```

<a id="upstream-response-time-distribution"></a>

### 上游响应时间分布

```nginx
metric_zone upstream_time:10m expire=on histogram
    0.05 0.1 0.3 0.5 1 2 5 10 inf;

server {
    listen 80;

    location /backend/ {
        proxy_pass http://backend;
        metric upstream_time $upstream_addr=$upstream_response_time on=end;
    }

    location /metrics/ {
        allow 127.0.0.1;
        deny all;
        api /status/http/metric_zones/upstream_time/;
    }
}
```

响应：

```json
{
    "discarded": 0,
    "metrics": {
        "backend1:8080": {
            "0.05": 12,
            "0.1": 28,
            "0.3": 56,
            "0.5": 78,
            "1": 92,
            "2": 97,
            "5": 99,
            "10": 100,
            "inf": 100
        }
    }
}
```

<a id="active-connections"></a>

### 活动连接数

```nginx
metric_zone active_connections:2m gauge;

server {
    listen 80;
    server_name site1.com;

    location / {
        # 连接时增加
        metric active_connections site1=1 on=request;

        # 结束时减少
        metric active_connections site1=-1 on=end;
    }
}

server {
    listen 80;
    server_name site2.com;

    location / {
        metric active_connections site2=1 on=request;
        metric active_connections site2=-1 on=end;
    }
}

server {
    listen 8080;

    location /connections/ {
        allow 127.0.0.1;
        deny all;
        api /status/http/metric_zones/active_connections/metrics;
    }
}
```

响应：

```json
{
    "site1": 42,
    "site2": 17
}
```

<a id="prometheus-support"></a>

## Prometheus 支持

Angie 包含一个 [内置模块](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#http-prometheus)，用于以
[Prometheus 格式](https://prometheus.io/docs/instrumenting/exposition_formats/)
显示指标，该模块支持自定义指标。

作为集成示例，请考虑以下配置：

```nginx
http {
    # 创建 "upload" 指标
    metric_complex_zone upload:1m discard_key="other" {
        stats    histogram 64 256 1024 4096 16384 +Inf;
        sum      gauge;
        count    count;
        avg_size average exp;
    }

    # 描述 "upload" 指标的 Prometheus 模板
    prometheus_template upload_metric {
        'stats{le="$1"}' $p8s_value
                         path=~^/http/metric_zones/upload/metrics/angie/stats/(.+)$
                         type=histogram;

        'stats_sum'      $p8s_value
                         path=/http/metric_zones/upload/metrics/angie/sum;
        'stats_count'    $p8s_value
                         path=/http/metric_zones/upload/metrics/angie/count;

        'avg_size'       $p8s_value
                         path=/http/metric_zones/upload/metrics/angie/avg_size;
    }

    server {
        listen 80;

        # 更新指标
        location ~ ^/upload/(.*)$ {
            api /status/http/metric_zones/upload/metrics/angie/;
            metric upload angie=$1 on=request;
        }

        # 指标抓取目标
        location /prometheus/upload_metric/ {
            prometheus upload_metric;
        }
    }
}
```

在对 `/upload/...` 发起多次请求后：

```console
$ curl 127.0.0.1/upload/16384
$ curl 127.0.0.1/upload/64448
$ curl 127.0.0.1/upload/64
$ curl 127.0.0.1/upload/1028
$ curl 127.0.0.1/upload/1028
```

指标值将为：

```json
{
    "stats": {
        "64": 1,
        "256": 1,
        "1024": 1,
        "4096": 3,
        "16384": 4,
        "+Inf": 5
    },

    "sum": 82952,
    "count": 5,
    "avg_size": 1077.9376
}
```

以 [Prometheus 格式](https://prometheus.io/docs/instrumenting/exposition_formats/)，
该指标可在 `/prometheus/upload_metric/` 获取：

```text
# Angie Prometheus template "upload_metric"
# TYPE stats histogram
stats{le="64"} 1
stats{le="256"} 1
stats{le="1024"} 1
stats{le="4096"} 3
stats{le="16384"} 4
stats{le="+Inf"} 5
stats_sum 82952
stats_count 5
avg_size 1077.9376
```


# https://cn.angie.software/angie/docs/configuration/modules/http/http_mirror.md

<!-- review: finished -->

<a id="http-mirror"></a>

# Mirror

该模块通过创建后台镜像子请求来实现对原始请求的镜像。对镜像子请求的响应将被忽略。

<a id="configuration-example-30-1"></a>

## 配置示例

```nginx
location / {
    mirror /mirror;
    proxy_pass http://backend;
}

location = /mirror {
    internal;
    proxy_pass http://test_backend$request_uri;
}
```

<a id="directives-31-1"></a>

## 指令

<a id="index-0"></a>

<a id="mirror"></a>

### mirror

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `mirror` uri | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | `mirror off;`           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location  |

设置原始请求将被镜像到的 URI。可以在同一配置级别指定多个镜像。

<a id="index-1"></a>

<a id="mirror-request-body"></a>

### mirror_request_body

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `mirror_request_body` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `mirror_request_body on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

指示客户端请求体是否被镜像。当启用时,客户端请求体将在创建镜像子请求之前被读取。在这种情况下,由 [proxy_request_buffering](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-request-buffering)、[fastcgi_request_buffering](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-request-buffering)、[scgi_request_buffering](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-request-buffering) 和 [uwsgi_request_buffering](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-request-buffering) 指令设置的非缓冲客户端请求体代理将被禁用。

```nginx
location / {
    mirror /mirror;
    mirror_request_body off;
    proxy_pass http://backend;
}

location = /mirror {
    internal;
    proxy_pass http://log_backend;
    proxy_pass_request_body off;
    proxy_set_header Content-Length "";
    proxy_set_header X-Original-URI $request_uri;
}
```


# https://cn.angie.software/angie/docs/configuration/modules/http/http_mp4.md

<!-- review: finished -->

<a id="http-mp4"></a>

# MP4

该模块为 MP4 文件提供伪流媒体的服务器端支持。这类文件通常具有 .mp4、.m4v 或 .m4a 文件扩展名。

伪流媒体与兼容的媒体播放器协同工作。播放器向服务器发送一个 HTTP 请求，请求中指定查询字符串参数的开始时间（简单命名为 start，单位为秒），服务器则回应以使其起始位置对应于请求的时间，例如：

```none
http://example.com/elephants_dream.mp4?start=238.88
```

这允许在任意时间进行随机寻址，或从时间轴中间开始播放。

为了支持寻址，基于 H.264 的格式在所谓的 "moov atom" 中存储元数据。它是文件的一部分，包含整个文件的索引信息。

为了开始播放，播放器首先需要读取元数据。这是通过发送一个带有 `start=0` 参数的特殊请求来完成的。许多编码软件将元数据插入到文件的末尾。这对于伪流媒体来说是不理想的，因为播放器必须在开始播放之前下载整个文件。如果元数据位于文件的开头，对于 Angie 来说，只需开始发送文件内容即可。如果元数据位于文件的末尾，Angie 必须读取整个文件并准备一个新的流，以便元数据在媒体数据之前。这涉及一些 CPU、内存和磁盘 I/O 的开销，因此最好提前 [准备](https://github.com/flowplayer/flowplayer/wiki/7.1.1-video-file-correction) 原始文件以进行伪流媒体，而不是让 Angie 在每个这样的请求上都执行此操作。

该模块还支持 HTTP 请求的 `end` 参数，该参数设置播放的结束点。`end` 参数可以与 start 参数一起指定，也可以单独指定：

```none
http://example.com/elephants_dream.mp4?start=238.88&end=555.55
```

对于包含非零 `start` 或 `end` 参数的匹配请求，Angie 将从文件中读取元数据，准备请求时间范围的流，并将其发送给客户端。这与上述描述的开销相同。

如果 `start` 参数指向非关键视频帧，则视频的开头将会损坏。为了解决此问题，视频 [可以](#mp4-start-key-frame) 在 `start` 点之前添加关键帧以及它们之间的所有中间帧。这些帧将通过编辑列表从播放中隐藏。

如果匹配请求不包含 `start` 和 `end` 参数，则没有开销，文件将简单地作为静态资源发送。一些播放器也支持字节范围请求，因此不需要此模块。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，该模块默认并不构建；应通过 `‑‑with‑http_mp4_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用它。在来自 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中，该模块已包含在构建中。

#### WARNING
如果之前使用了第三方的 `mp4` 模块，则应将其禁用。

对于 FLV 文件，提供了类似的伪流媒体支持：[FLV](https://cn.angie.software//angie/docs/configuration/modules/http/http_flv.md#http-flv) 模块。

<a id="configuration-example-31"></a>

## 配置示例

```nginx
location /video/ {
    mp4;
    mp4_buffer_size     1m;
    mp4_max_buffer_size 5m;
}
```

<a id="directives-32"></a>

## 指令

<a id="index-0"></a>

<a id="mp4"></a>

### mp4

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `mp4`;   |
|--------------------------------------------------------------------------------------|----------|
| 默认                                                                                   | —        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location |

在周围位置启用模块处理。

<a id="index-1"></a>

<a id="mp4-buffer-size"></a>

### mp4_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `mp4_buffer_size` size;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认                                                                                   | `mp4_buffer_size 512K;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location    |

设置用于处理 MP4 文件的缓冲区的初始大小。

<a id="index-2"></a>

<a id="mp4-max-buffer-size"></a>

### mp4_max_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `mp4_max_buffer_size` size;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认                                                                                   | `mp4_max_buffer_size 10M;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

在元数据处理期间，可能需要更大的缓冲区。其大小不得超过指定大小，否则 Angie 将返回 500（内部服务器错误）服务器错误，并记录以下消息：

> "/some/movie/file.mp4" mp4 moov atom is too large:
> 12583268, you may want to increase mp4_max_buffer_size

<a id="index-3"></a>

<a id="mp4-limit-rate"></a>

### mp4_limit_rate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `mp4_limit_rate` `on` | `off` | factor;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认                                                                                   | `mp4_limit_rate off;`                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                    |

对请求的 MP4 文件向客户端的传输进行速率限制。要计算限制，将 factor 乘以文件的平均比特率。

- `off` 值禁用速率限制。
- `on` 值设置 factor 为 `1.1`。
- 限制在达到由 [mp4_limit_rate_after](#mp4-limit-rate-after) 设置的值后应用。

请求是单独进行速率限制的：如果客户端打开两个连接，结果速率翻倍。因此，考虑使用 [limit_conn](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#limit-conn) 和相关指令。

<a id="index-4"></a>

<a id="mp4-limit-rate-after"></a>

### mp4_limit_rate_after

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `mp4_limit_rate_after` time;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认                                                                                   | `mp4_limit_rate_after 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

设置（以 [播放时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax) 为单位）传输的媒体数据量，达到该数据量后触发由 [mp4_limit_rate](#mp4-limit-rate) 设置的速率限制。

<a id="index-5"></a>

<a id="mp4-start-key-frame"></a>

### mp4_start_key_frame

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `mp4_start_key_frame` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认                                                                                   | `mp4_start_key_frame off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

强制输出视频始终以关键视频帧开始。如果 start 参数不指向关键帧，则初始帧将通过 mp4 编辑列表隐藏。编辑列表受到主要播放器和浏览器的支持，如 Chrome、Safari、QuickTime 和 ffmpeg，Firefox 部分支持。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_perl.md

<!-- review: finished -->

<a id="http-perl"></a>

# Perl

该模块允许在 Perl 中编写位置和变量处理器，以及将 Perl 调用插入到 SSI 中。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，
该模块默认不构建；
应通过
`‑‑with‑http_perl_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用。

在我们的代码库中，该模块是
[动态构建](https://cn.angie.software//angie/docs/installation/index.md#install-dynamicmodules)
并作为一个名为 `angie-module-perl` 或 `angie-pro-module-perl` 的单独软件包提供；
可以使用 [load_module](https://cn.angie.software//angie/docs/configuration/modules/core.md#load-module) 指令加载。

#### NOTE
此模块需要 Perl 版本 5.6.1 或更高版本。C 编译器应与用于构建 Perl 的编译器兼容。

<a id="known-issues"></a>

## 已知问题

该模块是实验性的，因此任何情况都可能发生。

为了让 Perl 在重新配置期间重新编译修改过的模块，
应使用 `-Dusemultiplicity=yes` 或
`-Dusethreads=yes` 参数构建。此外，为了减少 Perl 在运行时的内存泄漏，应使用 `-Dusemymalloc=no` 参数进行构建。要检查已构建 Perl 的这些参数的值（示例中指定了首选值），请运行：

```console
$ perl -V:usemultiplicity -V:usemymalloc
usemultiplicity='define';
usemymalloc='n';
```

请注意，在使用新的 `-Dusemultiplicity=yes` 或
`-Dusethreads=yes` 参数重新构建 Perl 后，所有二进制 Perl 模块也必须重新构建——它们将不再与新的 Perl 兼容。

主进程和工作进程的大小在每次重新配置后可能会增长。如果主进程增长到不可接受的大小，可以在不更改可执行文件的情况下应用 [实时升级](https://cn.angie.software//angie/docs/configuration/runtime.md#service-upgrade) 程序。

当 Perl 模块执行长时间运行的操作时，例如解析域名、连接到其他服务器或查询数据库，分配给当前工作进程的其他请求将不会被处理。因此，建议仅执行具有可预测且短执行时间的操作，例如访问本地文件系统。

<a id="configuration-example-32"></a>

## 配置示例

```nginx
http {

    perl_modules perl/lib;
    perl_require hello.pm;

    perl_set $msie6 '

        sub {
            my $r = shift;
            my $ua = $r->header_in("User-Agent");

            return "" if $ua =~ /Opera/;
            return "1" if $ua =~ / MSIE [6-9]\.\d+/;
            return "";
        }

    ';

    server {
        location / {
            perl hello::handler;
        }
    }
```

perl/lib/hello.pm 模块：

```perl
package hello;

use nginx;

sub handler {
    my $r = shift;

    $r->send_http_header("text/html");
    return OK if $r->header_only;

    $r->print("hello!\n<br/>");

    if (-f $r->filename or -d _) {
        $r->print($r->uri, " exists!\n");
    }

    return OK;
}

1;
__END__
```

<a id="directives-33"></a>

## 指令

<a id="index-0"></a>

<a id="perl"></a>

### perl

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `perl` module :: function | 'sub { ... }';   |
|--------------------------------------------------------------------------------------|----------------------------------------------|
| 默认                                                                                   | —                                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location, limit_except                       |

为给定位置设置一个 Perl 处理器。

<a id="index-1"></a>

<a id="perl-modules"></a>

### perl_modules

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `perl_modules` path;   |
|--------------------------------------------------------------------------------------|------------------------|
| 默认                                                                                   | —                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                   |

为 Perl 模块设置额外路径。

<a id="index-2"></a>

<a id="perl-require"></a>

### perl_require

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `perl_require` module;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认                                                                                   | —                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                     |

定义将在每次重新配置时加载的模块名称。可以存在多个 perl_require 指令。

<a id="index-3"></a>

<a id="perl-set"></a>

### perl_set

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `perl_set` $variable module :: function | 'sub { ... }';   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------|
| 默认                                                                                   | —                                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                                       |

为指定变量设置一个 Perl 处理器。

<a id="calling-perl-from-ssi"></a>

## 从 SSI 调用 Perl

调用 Perl 的 SSI 命令具有以下格式：

```html
<!--# perl sub="module::function" arg="parameter1" arg="parameter2" ...
-->
```

<a id="the-r-request-object-methods"></a>

## $r 请求对象方法

<a id="samp-r-args"></a>

### `$r->args`

返回请求参数。

<a id="samp-r-filename"></a>

### `$r->filename`

返回与请求 URI 对应的文件名。

<a id="samp-r-has-request-body-handler"></a>

### `$r->has_request_body` (handler)

如果请求中没有主体，则返回 0。如果有主体，则为请求设置指定的处理器并返回 1。在读取请求主体后，Angie 将调用指定的处理器。请注意，处理器函数应以引用方式传递。示例：

```perl
package hello;

use nginx;

sub handler {
    my $r = shift;

    if ($r->request_method ne "POST") {
        return DECLINED;
    }

    if ($r->has_request_body(\&post)) {
        return OK;
    }

    return HTTP_BAD_REQUEST;
}

sub post {
    my $r = shift;

    $r->send_http_header;

    $r->print("request_body: \"", $r->request_body, "\"<br/>");
    $r->print("request_body_file: \"", $r->request_body_file, "\"<br/>\n");

    return OK;
}

1;

__END__
```

<a id="samp-r-allow-ranges"></a>

### `$r->allow_ranges`

启用在发送响应时使用字节范围。

<a id="samp-r-discard-request-body"></a>

### `$r->discard_request_body`

指示 Angie 丢弃请求主体。

<a id="samp-r-header-in-field"></a>

### `$r->header_in` (field)

返回指定客户端请求头字段的值。

<a id="samp-r-header-only"></a>

### `$r->header_only`

确定是否应将整个响应或仅其头部发送到客户端。

<a id="samp-r-header-out-field-value"></a>

### `$r->header_out` (field, value)

为指定响应头字段设置一个值。

<a id="samp-r-internal-redirect-uri"></a>

### `$r->internal_redirect` (uri)

对指定的 uri 进行内部重定向。实际重定向在 Perl 处理器执行完成后发生。该方法接受转义的 URI，并支持重定向到 [命名位置](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#named-location)。

<a id="samp-r-log-error-errno-message"></a>

### `$r->log_error` (errno, message)

将指定消息写入 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log)。如果 errno 非零，错误代码及其描述将附加到消息中。

<a id="samp-r-print-text"></a>

### `$r->print` (text, ...)

将数据传递给客户端。

<a id="samp-r-request-body"></a>

### `$r->request_body`

如果客户端请求主体尚未写入临时文件，则返回客户端请求主体。为了确保客户端请求主体在内存中，其大小应通过 [client_max_body_size](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-max-body-size) 限制，并使用 [client_body_buffer_size](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-body-buffer-size) 设置足够的缓冲区大小。

<a id="p-r-request-body-file"></a>

### `$r->request_body_file`

返回包含客户端请求主体的文件名称。处理后，应删除该文件。要始终将请求主体写入文件，应启用 [client_body_in_file_only](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-body-in-file-only)。

<a id="samp-r-request-method"></a>

### `$r->request_method`

返回客户端请求的 HTTP 方法。

<a id="samp-r-remote-addr"></a>

### `$r->remote_addr`

返回客户端 IP 地址。

<a id="samp-r-flush"></a>

### `$r->flush`

立即将数据发送给客户端。

<a id="samp-r-sendfile-name-offset-length"></a>

### `$r->sendfile` (name [, offset [, length ]])

将指定文件内容发送给客户端。可选参数指定数据传输的初始偏移量和长度。实际数据传输在 Perl 处理器完成后发生。

<a id="samp-r-send-http-header-type"></a>

### `$r->send_http_header` ([type])

将响应头发送给客户端。可选的类型参数设置 `Content-Type` 响应头字段的值。如果值为空字符串，则将不发送 `Content-Type` 头字段。

<a id="samp-r-status-code"></a>

### `$r->status` (code)

设置响应代码。

<a id="samp-r-sleep-milliseconds-handler"></a>

### `$r->sleep` (milliseconds, handler)

设置指定的处理器，并在指定时间内停止请求处理。在此期间，Angie 继续处理其他请求。在指定时间经过后，Angie 将调用安装的处理器。请注意，处理器函数应以引用方式传递。为了在处理器之间传递数据，应使用 [$r‑>variable()](#p-r-variable)。示例：

```nginx
package hello;

use nginx;

sub handler {
    my $r = shift;

    $r->discard_request_body;
    $r->variable("var", "OK");
    $r->sleep(1000, \&next);

    return OK;
}

sub next {
    my $r = shift;

    $r->send_http_header;
    $r->print($r->variable("var"));

    return OK;
}

1;

__END__
```

<a id="samp-r-unescape-text"></a>

### `$r->unescape` (text)

解码以 "%XX" 形式编码的文本。

<a id="samp-r-uri"></a>

### `$r->uri`

返回请求 URI。

<a id="p-r-variable"></a>

### `$r->variable` (name [, value ])

返回或设置指定变量的值。变量对每个请求都是本地的。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_prometheus.md

<!-- review: finished -->

<a id="http-prometheus"></a>

# Prometheus

收集 Angie [统计信息](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics)，
基于配置中定义的模板，
并以 [Prometheus 格式](https://prometheus.io/docs/instrumenting/exposition_formats/) 返回从这些模板生成的指标。

#### WARNING
要收集统计信息，
请在相应的上下文中使用以下指令启用共享内存区：

- [http_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-zone) 或 [stream_upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-zone) 中的 `zone` 指令；
- [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令；
- [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 指令中的 `status_zone` 参数。

<a id="configuration-example-33"></a>

## 配置示例

三个用于收集服务器共享内存区请求统计信息的指标，
组合到 `custom` 模板中并在 `/p8s` 路径发布：

```nginx
http {

    prometheus_template custom {
        'angie_http_server_zones_requests_total{zone="$1"}' $p8s_value
            path=~^/http/server_zones/([^/]+)/requests/total$
            type=counter;

        'angie_http_server_zones_requests_processing{zone="$1"}' $p8s_value
            path=~^/http/server_zones/([^/]+)/requests/processing$
            type=gauge;

        'angie_http_server_zones_requests_discarded{zone="$1"}' $p8s_value
            path=~^/http/server_zones/([^/]+)/requests/discarded$
            type=counter;
    }

    # ...

    server {

        listen 80;

        location =/p8s {
            prometheus custom;
        }

        # ...

    }
}
```

<a id="prometheus-all"></a>

Angie 包含一个辅助文件 `prometheus_all.conf`，
其中包含一组常用指标，组合到 `all` 模板中：

### 文件内容（Angie）

```nginx

prometheus_template all {

angie_connections_accepted $p8s_value
    path=/connections/accepted
    type=counter
    'help=The total number of accepted client connections.';

angie_connections_dropped $p8s_value
    path=/connections/dropped
    type=counter
    'help=The total number of dropped client connections.';

angie_connections_active $p8s_value
    path=/connections/active
    type=gauge
    'help=The current number of active client connections.';

angie_connections_idle $p8s_value
    path=/connections/idle
    type=gauge
    'help=The current number of idle client connections.';


'angie_slabs_pages_used{zone="$1"}' $p8s_value
    path=~^/slabs/([^/]+)/pages/used$
    type=gauge
    'help=The number of currently used memory pages in a slab zone.';

'angie_slabs_pages_free{zone="$1"}' $p8s_value
    path=~^/slabs/([^/]+)/pages/free$
    type=gauge
    'help=The number of currently free memory pages in a slab zone.';


'angie_slabs_pages_slots_used{zone="$1",size="$2"}' $p8s_value
    path=~^/slabs/([^/]+)/slots/([^/]+)/used$
    type=gauge
    'help=The number of currently used memory slots of a specific size in a slab zone.';

'angie_slabs_pages_slots_free{zone="$1",size="$2"}' $p8s_value
    path=~^/slabs/([^/]+)/slots/([^/]+)/free$
    type=gauge
    'help=The number of currently free memory slots of a specific size in a slab zone.';

'angie_slabs_pages_slots_reqs{zone="$1",size="$2"}' $p8s_value
    path=~^/slabs/([^/]+)/slots/([^/]+)/reqs$
    type=counter
    'help=The total number of attempts to allocate a memory slot of a specific size in a slab zone.';

'angie_slabs_pages_slots_fails{zone="$1",size="$2"}' $p8s_value
    path=~^/slabs/([^/]+)/slots/([^/]+)/fails$
    type=counter
    'help=The number of unsuccessful attempts to allocate a memory slot of a specific size in a slab zone.';


'angie_resolvers_queries{zone="$1",type="$2"}' $p8s_value
    path=~^/resolvers/([^/]+)/queries/([^/]+)$
    type=counter
    'help=The number of queries of a specific type to resolve in a resolver zone.';

'angie_resolvers_sent{zone="$1",type="$2"}' $p8s_value
    path=~^/resolvers/([^/]+)/sent/([^/]+)$
    type=counter
    'help=The number of sent DNS queries of a specific type to resolve in a resolver zone.';

'angie_resolvers_responses{zone="$1",status="$2"}' $p8s_value
    path=~^/resolvers/([^/]+)/responses/([^/]+)$
    type=counter
    'help=The number of resolution results with a specific status in a resolver zone.';


'angie_http_server_zones_ssl_handshaked{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/ssl/handshaked$
    type=counter
    'help=The total number of successful SSL handshakes in an HTTP server zone.';

'angie_http_server_zones_ssl_reuses{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/ssl/reuses$
    type=counter
    'help=The total number of session reuses during SSL handshakes in an HTTP server zone.';

'angie_http_server_zones_ssl_timedout{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/ssl/timedout$
    type=counter
    'help=The total number of timed-out SSL handshakes in an HTTP server zone.';

'angie_http_server_zones_ssl_failed{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/ssl/failed$
    type=counter
    'help=The total number of failed SSL handshakes in an HTTP server zone.';


'angie_http_server_zones_requests_total{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/requests/total$
    type=counter
    'help=The total number of client requests received in an HTTP server zone.';

'angie_http_server_zones_requests_processing{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/requests/processing$
    type=gauge
    'help=The number of client requests currently being processed in an HTTP server zone.';

'angie_http_server_zones_requests_discarded{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/requests/discarded$
    type=counter
    'help=The total number of client requests completed in an HTTP server zone without sending a response.';


'angie_http_server_zones_responses{zone="$1",code="$2"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/responses/([^/]+)$
    type=counter
    'help=The number of responses with a specific status in an HTTP server zone.';


'angie_http_server_zones_data_received{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/data/received$
    type=counter
    'help=The total number of bytes received from clients in an HTTP server zone.';

'angie_http_server_zones_data_sent{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/data/sent$
    type=counter
    'help=The total number of bytes sent to clients in an HTTP server zone.';


'angie_http_location_zones_requests_total{zone="$1"}' $p8s_value
    path=~^/http/location_zones/([^/]+)/requests/total$
    type=counter
    'help=The total number of client requests in an HTTP location zone.';

'angie_http_location_zones_requests_discarded{zone="$1"}' $p8s_value
    path=~^/http/location_zones/([^/]+)/requests/discarded$
    type=counter
    'help=The total number of client requests completed in an HTTP location zone without sending a response.';


'angie_http_location_zones_responses{zone="$1",code="$2"}' $p8s_value
    path=~^/http/location_zones/([^/]+)/responses/([^/]+)$
    type=counter
    'help=The number of responses with a specific status in an HTTP location zone.';


'angie_http_location_zones_data_received{zone="$1"}' $p8s_value
    path=~^/http/location_zones/([^/]+)/data/received$
    type=counter
    'help=The total number of bytes received from clients in an HTTP location zone.';

'angie_http_location_zones_data_sent{zone="$1"}' $p8s_value
    path=~^/http/location_zones/([^/]+)/data/sent$
    type=counter
    'help=The total number of bytes sent to clients in an HTTP location zone.';


'angie_http_upstreams_peers_state{upstream="$1",peer="$2"}' $p8st_all_ups_state
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/state$
    type=gauge
    'help=The current state of an upstream peer in "HTTP": 1 - up, 2 - down, 3 - unavailable, or 4 - recovering.';


'angie_http_upstreams_peers_selected_current{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/selected/current$
    type=gauge
    'help=The number of requests currently being processed by an upstream peer in "HTTP".';

'angie_http_upstreams_peers_selected_total{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/selected/total$
    type=counter
    'help=The total number of attempts to use an upstream peer in "HTTP".';


'angie_http_upstreams_peers_responses{upstream="$1",peer="$2",code="$3"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/responses/([^/]+)$
    type=counter
    'help=The number of responses with a specific status received from an upstream peer in "HTTP".';


'angie_http_upstreams_peers_data_sent{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/data/sent$
    type=counter
    'help=The total number of bytes sent to an upstream peer in "HTTP".';

'angie_http_upstreams_peers_data_received{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/data/received$
    type=counter
    'help=The total number of bytes received from an upstream peer in "HTTP".';


'angie_http_upstreams_peers_health_fails{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/health/fails$
    type=counter
    'help=The total number of unsuccessful attempts to communicate with an upstream peer in "HTTP".';

'angie_http_upstreams_peers_health_unavailable{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/health/unavailable$
    type=counter
    'help=The number of times when an upstream peer in "HTTP" became "unavailable" due to reaching the max_fails limit.';

'angie_http_upstreams_peers_health_downtime{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/health/downtime$
    type=counter
    'help=The total time (in milliseconds) that an upstream peer in "HTTP" was "unavailable".';


'angie_http_upstreams_keepalive{upstream="$1"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/keepalive$
    type=gauge
    'help=The number of currently cached keepalive connections for an HTTP upstream.';


'angie_http_caches_responses{zone="$1",status="$2"}' $p8s_value
    path=~^/http/caches/([^/]+)/([^/]+)/responses$
    type=counter
    'help=The total number of responses processed in an HTTP cache zone with a specific cache status.';

'angie_http_caches_bytes{zone="$1",status="$2"}' $p8s_value
    path=~^/http/caches/([^/]+)/([^/]+)/bytes$
    type=counter
    'help=The total number of bytes processed in an HTTP cache zone with a specific cache status.';

'angie_http_caches_responses_written{zone="$1",status="$2"}' $p8s_value
    path=~^/http/caches/([^/]+)/([^/]+)/responses_written$
    type=counter
    'help=The total number of responses written to an HTTP cache zone with a specific cache status.';

'angie_http_caches_bytes_written{zone="$1",status="$2"}' $p8s_value
    path=~^/http/caches/([^/]+)/([^/]+)/bytes_written$
    type=counter
    'help=The total number of bytes written to an HTTP cache zone with a specific cache status.';


'angie_http_caches_size{zone="$1"}' $p8s_value
    path=~^/http/caches/([^/]+)/size$
    type=gauge
    'help=The current size (in bytes) of cached responses in an HTTP cache zone.';


'angie_http_caches_shards_size{zone="$1",path="$2"}' $p8s_value
    path=~^/http/caches/([^/]+)/shards/([^/]+)/size$
    type=gauge
    'help=The current size (in bytes) of cached responses in a shard path of an HTTP cache zone.';


'angie_http_limit_conns{zone="$1",status="$2"}' $p8s_value
    path=~^/http/limit_conns/([^/]+)/([^/]+)$
    type=counter
    'help=The number of requests processed by an HTTP limit_conn zone with a specific result.';

'angie_http_limit_reqs{zone="$1",status="$2"}' $p8s_value
    path=~^/http/limit_reqs/([^/]+)/([^/]+)$
    type=counter
    'help=The number of requests processed by an HTTP limit_reqs zone with a specific result.';


'angie_stream_server_zones_ssl_handshaked{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/ssl/handshaked$
    type=counter
    'help=The total number of successful SSL handshakes in a stream server zone.';

'angie_stream_server_zones_ssl_reuses{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/ssl/reuses$
    type=counter
    'help=The total number of session reuses during SSL handshakes in a stream server zone.';

'angie_stream_server_zones_ssl_timedout{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/ssl/timedout$
    type=counter
    'help=The total number of timed-out SSL handshakes in a stream server zone.';

'angie_stream_server_zones_ssl_failed{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/ssl/failed$
    type=counter
    'help=The total number of failed SSL handshakes in a stream server zone.';


'angie_stream_server_zones_connections_total{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/connections/total$
    type=counter
    'help=The total number of client connections received in a stream server zone.';

'angie_stream_server_zones_connections_processing{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/connections/processing$
    type=gauge
    'help=The number of client connections currently being processed in a stream server zone.';

'angie_stream_server_zones_connections_discarded{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/connections/discarded$
    type=counter
    'help=The total number of client connections completed in a stream server zone without establishing a session.';

'angie_stream_server_zones_connections_passed{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/connections/passed$
    type=counter
    'help=The total number of client connections in a stream server zone passed for handling to a different listening socket.';


'angie_stream_server_zones_sessions{zone="$1",status="$2"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/sessions/([^/]+)$
    type=counter
    'help=The number of sessions finished with a specific status in a stream server zone.';


'angie_stream_server_zones_data_received{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/data/received$
    type=counter
    'help=The total number of bytes received from clients in a stream server zone.';

'angie_stream_server_zones_data_sent{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/data/sent$
    type=counter
    'help=The total number of bytes sent to clients in a stream server zone.';


'angie_stream_upstreams_peers_state{upstream="$1",peer="$2"}' $p8st_all_ups_state
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/state$
    type=gauge
    'help=The current state of an upstream peer in "stream": 1 - up, 2 - down, 3 - unavailable, or 4 - recovering.';


'angie_stream_upstreams_peers_selected_current{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/selected/current$
    type=gauge
    'help=The number of sessions currently being processed by an upstream peer in "stream".';

'angie_stream_upstreams_peers_selected_total{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/selected/total$
    type=counter
    'help=The total number of attempts to use an upstream peer in "stream".';


'angie_stream_upstreams_peers_data_sent{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/data/sent$
    type=counter
    'help=The total number of bytes sent to an upstream peer in "stream".';

'angie_stream_upstreams_peers_data_received{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/data/received$
    type=counter
    'help=The total number of bytes received from an upstream peer in "stream".';


'angie_stream_upstreams_peers_health_fails{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/health/fails$
    type=counter
    'help=The total number of unsuccessful attempts to communicate with an upstream peer in "stream".';

'angie_stream_upstreams_peers_health_unavailable{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/health/unavailable$
    type=counter
    'help=The number of times when an upstream peer in "stream" became "unavailable" due to reaching the max_fails limit.';

'angie_stream_upstreams_peers_health_downtime{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/health/downtime$
    type=counter
    'help=The total time (in milliseconds) that an upstream peer in "stream" was "unavailable".';
}


'angie_http_acme_clients_state{client="$1"}' $p8st_acme_cert_state
    path=~^/http/acme_clients/([^/]+)/state$
    type=gauge
    'help=The current state of an ACME client: 1 - ready, 2 - requesting, 3 - disabled, or 4 - failed.';

'angie_http_acme_certs_state{client="$1"}' $p8st_acme_cli_state
    path=~^/http/acme_clients/([^/]+)/certificate$
    type=gauge
    'help=The current state of an ACME client certificate: 1 - valid, 2 - mismatch, 3 - expired, 4 - missing, or 5 - error.';


map $p8s_value $p8st_all_ups_state {
    volatile;
    "up"           1;
    "down"         2;
    "unavailable"  3;
    "recovering"   4;
#    "unhealthy"    5;
#    "checking"     6;
#    "draining"     7;
    "busy"         8;
    default        0;
}


map $p8s_value $p8st_acme_cli_state {
    volatile;
    "ready"        1;
    "requesting"   2;
    "disabled"     3;
    "failed"       4;
}


map $p8s_value $p8st_acme_cert_state {
    volatile;
    "valid"        1;
    "mismatch"     2;
    "expired"      3;
    "missing"      4;
    "error"        5;
}
```

### 文件内容（Angie PRO）

```nginx

prometheus_template all {

angie_connections_accepted $p8s_value
    path=/connections/accepted
    type=counter
    'help=The total number of accepted client connections.';

angie_connections_dropped $p8s_value
    path=/connections/dropped
    type=counter
    'help=The total number of dropped client connections.';

angie_connections_active $p8s_value
    path=/connections/active
    type=gauge
    'help=The current number of active client connections.';

angie_connections_idle $p8s_value
    path=/connections/idle
    type=gauge
    'help=The current number of idle client connections.';


'angie_slabs_pages_used{zone="$1"}' $p8s_value
    path=~^/slabs/([^/]+)/pages/used$
    type=gauge
    'help=The number of currently used memory pages in a slab zone.';

'angie_slabs_pages_free{zone="$1"}' $p8s_value
    path=~^/slabs/([^/]+)/pages/free$
    type=gauge
    'help=The number of currently free memory pages in a slab zone.';


'angie_slabs_pages_slots_used{zone="$1",size="$2"}' $p8s_value
    path=~^/slabs/([^/]+)/slots/([^/]+)/used$
    type=gauge
    'help=The number of currently used memory slots of a specific size in a slab zone.';

'angie_slabs_pages_slots_free{zone="$1",size="$2"}' $p8s_value
    path=~^/slabs/([^/]+)/slots/([^/]+)/free$
    type=gauge
    'help=The number of currently free memory slots of a specific size in a slab zone.';

'angie_slabs_pages_slots_reqs{zone="$1",size="$2"}' $p8s_value
    path=~^/slabs/([^/]+)/slots/([^/]+)/reqs$
    type=counter
    'help=The total number of attempts to allocate a memory slot of a specific size in a slab zone.';

'angie_slabs_pages_slots_fails{zone="$1",size="$2"}' $p8s_value
    path=~^/slabs/([^/]+)/slots/([^/]+)/fails$
    type=counter
    'help=The number of unsuccessful attempts to allocate a memory slot of a specific size in a slab zone.';


'angie_resolvers_queries{zone="$1",type="$2"}' $p8s_value
    path=~^/resolvers/([^/]+)/queries/([^/]+)$
    type=counter
    'help=The number of queries of a specific type to resolve in a resolver zone.';

'angie_resolvers_sent{zone="$1",type="$2"}' $p8s_value
    path=~^/resolvers/([^/]+)/sent/([^/]+)$
    type=counter
    'help=The number of sent DNS queries of a specific type to resolve in a resolver zone.';

'angie_resolvers_responses{zone="$1",status="$2"}' $p8s_value
    path=~^/resolvers/([^/]+)/responses/([^/]+)$
    type=counter
    'help=The number of resolution results with a specific status in a resolver zone.';


'angie_http_server_zones_ssl_handshaked{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/ssl/handshaked$
    type=counter
    'help=The total number of successful SSL handshakes in an HTTP server zone.';

'angie_http_server_zones_ssl_reuses{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/ssl/reuses$
    type=counter
    'help=The total number of session reuses during SSL handshakes in an HTTP server zone.';

'angie_http_server_zones_ssl_timedout{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/ssl/timedout$
    type=counter
    'help=The total number of timed-out SSL handshakes in an HTTP server zone.';

'angie_http_server_zones_ssl_failed{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/ssl/failed$
    type=counter
    'help=The total number of failed SSL handshakes in an HTTP server zone.';


'angie_http_server_zones_requests_total{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/requests/total$
    type=counter
    'help=The total number of client requests received in an HTTP server zone.';

'angie_http_server_zones_requests_processing{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/requests/processing$
    type=gauge
    'help=The number of client requests currently being processed in an HTTP server zone.';

'angie_http_server_zones_requests_discarded{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/requests/discarded$
    type=counter
    'help=The total number of client requests completed in an HTTP server zone without sending a response.';


'angie_http_server_zones_responses{zone="$1",code="$2"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/responses/([^/]+)$
    type=counter
    'help=The number of responses with a specific status in an HTTP server zone.';


'angie_http_server_zones_data_received{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/data/received$
    type=counter
    'help=The total number of bytes received from clients in an HTTP server zone.';

'angie_http_server_zones_data_sent{zone="$1"}' $p8s_value
    path=~^/http/server_zones/([^/]+)/data/sent$
    type=counter
    'help=The total number of bytes sent to clients in an HTTP server zone.';


'angie_http_location_zones_requests_total{zone="$1"}' $p8s_value
    path=~^/http/location_zones/([^/]+)/requests/total$
    type=counter
    'help=The total number of client requests in an HTTP location zone.';

'angie_http_location_zones_requests_discarded{zone="$1"}' $p8s_value
    path=~^/http/location_zones/([^/]+)/requests/discarded$
    type=counter
    'help=The total number of client requests completed in an HTTP location zone without sending a response.';


'angie_http_location_zones_responses{zone="$1",code="$2"}' $p8s_value
    path=~^/http/location_zones/([^/]+)/responses/([^/]+)$
    type=counter
    'help=The number of responses with a specific status in an HTTP location zone.';


'angie_http_location_zones_data_received{zone="$1"}' $p8s_value
    path=~^/http/location_zones/([^/]+)/data/received$
    type=counter
    'help=The total number of bytes received from clients in an HTTP location zone.';

'angie_http_location_zones_data_sent{zone="$1"}' $p8s_value
    path=~^/http/location_zones/([^/]+)/data/sent$
    type=counter
    'help=The total number of bytes sent to clients in an HTTP location zone.';


'angie_http_upstreams_peers_backup{upstream="$1",peer="$2"}' $p8st_all_ups_backup
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/backup$
    type=gauge
    'help=The HTTP upstream peer backup group level.';


'angie_http_upstreams_peers_state{upstream="$1",peer="$2"}' $p8st_all_ups_state
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/state$
    type=gauge
    'help=The current state of an upstream peer in "HTTP": 1 - up, 2 - down, 3 - unavailable, 4 - recovering, 5 - unhealthy, 6 - checking, or 7 - draining.';


'angie_http_upstreams_peers_selected_current{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/selected/current$
    type=gauge
    'help=The number of requests currently being processed by an upstream peer in "HTTP".';

'angie_http_upstreams_peers_selected_total{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/selected/total$
    type=counter
    'help=The total number of attempts to use an upstream peer in "HTTP".';


'angie_http_upstreams_peers_responses{upstream="$1",peer="$2",code="$3"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/responses/([^/]+)$
    type=counter
    'help=The number of responses with a specific status received from an upstream peer in "HTTP".';


'angie_http_upstreams_peers_data_sent{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/data/sent$
    type=counter
    'help=The total number of bytes sent to an upstream peer in "HTTP".';

'angie_http_upstreams_peers_data_received{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/data/received$
    type=counter
    'help=The total number of bytes received from an upstream peer in "HTTP".';


'angie_http_upstreams_peers_health_fails{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/health/fails$
    type=counter
    'help=The total number of unsuccessful attempts to communicate with an upstream peer in "HTTP".';

'angie_http_upstreams_peers_health_unavailable{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/health/unavailable$
    type=counter
    'help=The number of times when an upstream peer in "HTTP" became "unavailable" due to reaching the max_fails limit.';

'angie_http_upstreams_peers_health_downtime{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/health/downtime$
    type=counter
    'help=The total time (in milliseconds) that an upstream peer in "HTTP" was "unavailable".';

'angie_http_upstreams_peers_health_header_time{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/health/header_time$
    type=gauge
    'help=Average time (in milliseconds) to receive the response headers from an upstream peer in "HTTP".';

'angie_http_upstreams_peers_health_response_time{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/health/response_time$
    type=gauge
    'help=Average time (in milliseconds) to receive the complete response from an upstream peer in "HTTP".';

'angie_http_upstreams_peers_health_probes_count{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/health/probes/count$
    type=counter
    'help=The total number of probes for this peer.';

'angie_http_upstreams_peers_health_probes_fails{upstream="$1",peer="$2"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/peers/([^/]+)/health/probes/fails$
    type=counter
    'help=The total number of failed probes for this peer.';


'angie_http_upstreams_keepalive{upstream="$1"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/keepalive$
    type=gauge
    'help=The number of currently cached keepalive connections for an HTTP upstream.';


'angie_http_upstreams_backup_switch_active{upstream="$1"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/backup_switch/active$
    type=gauge
    'help=The currently active HTTP upstream servers backup group level.';


'angie_http_upstreams_queue_queued{upstream="$1"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/queue/queued$
    type=counter
    'help=The total number of queued requests for an HTTP upstream.';

'angie_http_upstreams_queue_waiting{upstream="$1"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/queue/waiting$
    type=gauge
    'help=The number of requests currently waiting in an HTTP upstream queue.';

'angie_http_upstreams_queue_dropped{upstream="$1"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/queue/dropped$
    type=counter
    'help=The total number of requests dropped from an HTTP upstream queue because the client had prematurely closed the connection.';

'angie_http_upstreams_queue_timedout{upstream="$1"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/queue/timedout$
    type=counter
    'help=The total number of requests timed out from an HTTP upstream queue.';

'angie_http_upstreams_queue_overflows{upstream="$1"}' $p8s_value
    path=~^/http/upstreams/([^/]+)/queue/overflows$
    type=counter
    'help=The total number of requests rejected by an HTTP upstream queue because the size limit had been reached.';


'angie_http_caches_responses{zone="$1",status="$2"}' $p8s_value
    path=~^/http/caches/([^/]+)/([^/]+)/responses$
    type=counter
    'help=The total number of responses processed in an HTTP cache zone with a specific cache status.';

'angie_http_caches_bytes{zone="$1",status="$2"}' $p8s_value
    path=~^/http/caches/([^/]+)/([^/]+)/bytes$
    type=counter
    'help=The total number of bytes processed in an HTTP cache zone with a specific cache status.';

'angie_http_caches_responses_written{zone="$1",status="$2"}' $p8s_value
    path=~^/http/caches/([^/]+)/([^/]+)/responses_written$
    type=counter
    'help=The total number of responses written to an HTTP cache zone with a specific cache status.';

'angie_http_caches_bytes_written{zone="$1",status="$2"}' $p8s_value
    path=~^/http/caches/([^/]+)/([^/]+)/bytes_written$
    type=counter
    'help=The total number of bytes written to an HTTP cache zone with a specific cache status.';


'angie_http_caches_size{zone="$1"}' $p8s_value
    path=~^/http/caches/([^/]+)/size$
    type=gauge
    'help=The current size (in bytes) of cached responses in an HTTP cache zone.';


'angie_http_caches_shards_size{zone="$1",path="$2"}' $p8s_value
    path=~^/http/caches/([^/]+)/shards/([^/]+)/size$
    type=gauge
    'help=The current size (in bytes) of cached responses in a shard path of an HTTP cache zone.';


'angie_http_limit_conns{zone="$1",status="$2"}' $p8s_value
    path=~^/http/limit_conns/([^/]+)/([^/]+)$
    type=counter
    'help=The number of requests processed by an HTTP limit_conn zone with a specific result.';

'angie_http_limit_reqs{zone="$1",status="$2"}' $p8s_value
    path=~^/http/limit_reqs/([^/]+)/([^/]+)$
    type=counter
    'help=The number of requests processed by an HTTP limit_reqs zone with a specific result.';


'angie_stream_server_zones_ssl_handshaked{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/ssl/handshaked$
    type=counter
    'help=The total number of successful SSL handshakes in a stream server zone.';

'angie_stream_server_zones_ssl_reuses{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/ssl/reuses$
    type=counter
    'help=The total number of session reuses during SSL handshakes in a stream server zone.';

'angie_stream_server_zones_ssl_timedout{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/ssl/timedout$
    type=counter
    'help=The total number of timed-out SSL handshakes in a stream server zone.';

'angie_stream_server_zones_ssl_failed{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/ssl/failed$
    type=counter
    'help=The total number of failed SSL handshakes in a stream server zone.';


'angie_stream_server_zones_connections_total{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/connections/total$
    type=counter
    'help=The total number of client connections received in a stream server zone.';

'angie_stream_server_zones_connections_processing{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/connections/processing$
    type=gauge
    'help=The number of client connections currently being processed in a stream server zone.';

'angie_stream_server_zones_connections_discarded{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/connections/discarded$
    type=counter
    'help=The total number of client connections completed in a stream server zone without establishing a session.';

'angie_stream_server_zones_connections_passed{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/connections/passed$
    type=counter
    'help=The total number of client connections in a stream server zone passed for handling to a different listening socket.';


'angie_stream_server_zones_sessions{zone="$1",status="$2"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/sessions/([^/]+)$
    type=counter
    'help=The number of sessions finished with a specific status in a stream server zone.';


'angie_stream_server_zones_data_received{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/data/received$
    type=counter
    'help=The total number of bytes received from clients in a stream server zone.';

'angie_stream_server_zones_data_sent{zone="$1"}' $p8s_value
    path=~^/stream/server_zones/([^/]+)/data/sent$
    type=counter
    'help=The total number of bytes sent to clients in a stream server zone.';


'angie_stream_upstreams_peers_backup{upstream="$1",peer="$2"}' $p8st_all_ups_backup
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/backup$
    type=gauge
    'help=The "stream" upstream peer backup group level.';


'angie_stream_upstreams_peers_state{upstream="$1",peer="$2"}' $p8st_all_ups_state
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/state$
    type=gauge
    'help=The current state of an upstream peer in "stream": 1 - up, 2 - down, 3 - unavailable, 4 - recovering, 5 - unhealthy, 6 - checking, or 7 - draining.';


'angie_stream_upstreams_peers_selected_current{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/selected/current$
    type=gauge
    'help=The number of sessions currently being processed by an upstream peer in "stream".';

'angie_stream_upstreams_peers_selected_total{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/selected/total$
    type=counter
    'help=The total number of attempts to use an upstream peer in "stream".';


'angie_stream_upstreams_peers_data_sent{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/data/sent$
    type=counter
    'help=The total number of bytes sent to an upstream peer in "stream".';

'angie_stream_upstreams_peers_data_received{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/data/received$
    type=counter
    'help=The total number of bytes received from an upstream peer in "stream".';

'angie_stream_upstreams_peers_data_pkt_sent{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/data/pkt_sent$
    type=counter
    'help=The total number of packets sent to an upstream peer in "stream".';

'angie_stream_upstreams_peers_data_pkt_received{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/data/pkt_received$
    type=counter
    'help=The total number of packets received from an upstream peer in "stream".';


'angie_stream_upstreams_peers_health_fails{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/health/fails$
    type=counter
    'help=The total number of unsuccessful attempts to communicate with an upstream peer in "stream".';

'angie_stream_upstreams_peers_health_unavailable{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/health/unavailable$
    type=counter
    'help=The number of times when an upstream peer in "stream" became "unavailable" due to reaching the max_fails limit.';

'angie_stream_upstreams_peers_health_downtime{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/health/downtime$
    type=counter
    'help=The total time (in milliseconds) that an upstream peer in "stream" was "unavailable".';

'angie_stream_upstreams_peers_health_connect_time{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/health/connect_time$
    type=gauge
    'help=Average time (in milliseconds) to connect to an upstream peer in "stream".';

'angie_stream_upstreams_peers_health_first_byte_time{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/health/first_byte_time$
    type=gauge
    'help=Average time (in milliseconds) to receive the first byte from an upstream peer in "stream".';

'angie_stream_upstreams_peers_health_last_byte_time{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/health/last_byte_time$
    type=gauge
    'help=Average time (in milliseconds) of the whole communication session with an upstream peer in "stream".';


'angie_stream_upstreams_peers_health_probes_count{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/health/probes/count$
    type=counter
    'help=The total number of probes for this peer.';

'angie_stream_upstreams_peers_health_probes_fails{upstream="$1",peer="$2"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/peers/([^/]+)/health/probes/fails$
    type=counter
    'help=The total number of failed probes for this peer.';


'angie_stream_upstreams_backup_switch_active{upstream="$1"}' $p8s_value
    path=~^/stream/upstreams/([^/]+)/backup_switch/active$
    type=gauge
    'help=The currently active "stream" upstream servers backup group level.';
}


'angie_http_acme_clients_state{client="$1"}' $p8st_acme_cert_state
    path=~^/http/acme_clients/([^/]+)/state$
    type=gauge
    'help=The current state of an ACME client: 1 - ready, 2 - requesting, 3 - disabled, or 4 - failed.';

'angie_http_acme_certs_state{client="$1"}' $p8st_acme_cli_state
    path=~^/http/acme_clients/([^/]+)/certificate$
    type=gauge
    'help=The current state of an ACME client certificate: 1 - valid, 2 - mismatch, 3 - expired, 4 - missing, or 5 - error.';


map $p8s_value $p8st_all_ups_state {
    volatile;
    "up"           1;
    "down"         2;
    "unavailable"  3;
    "recovering"   4;
    "unhealthy"    5;
    "checking"     6;
    "draining"     7;
    "busy"         8;
    default        0;
}

map $p8s_value $p8st_acme_cli_state {
    volatile;
    "ready"        1;
    "requesting"   2;
    "disabled"     3;
    "failed"       4;
}


map $p8s_value $p8st_acme_cert_state {
    volatile;
    "valid"        1;
    "mismatch"     2;
    "expired"      3;
    "missing"      4;
    "error"        5;
}


map $p8s_value $p8st_all_ups_backup {
    volatile;
    "false"        0;
    "true"         1;
    default        $p8s_value;
}
```

用法：

```nginx
http {

    include prometheus_all.conf;

    # ...

    server {

        listen 80;

        location =/p8s {
            prometheus all;
        }

        # ...

    }
}
```

```console
$ curl localhost/p8s

    # Angie Prometheus template "all"
    ...
```

<a id="directives-34"></a>

## 指令

<a id="index-0"></a>

<a id="prometheus"></a>

### prometheus

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `prometheus` template_name;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | —                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location                      |

为 `location` 上下文指定一个模板处理器，
由 [prometheus_template](#prometheus-template) 指令定义。
当被请求时，此 `location` 计算并以 Prometheus 格式返回模板指标。

```nginx
location =/p8s {
    prometheus custom;
}
```

```console
$ curl localhost/p8s

    # Angie Prometheus template "custom"
    ...
```

<a id="index-1"></a>

<a id="prometheus-template"></a>

### prometheus_template

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `prometheus_template` template_name { ... }   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | —                                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                          |

定义一个由 Angie 收集和导出的指标的命名模板，
供 [prometheus](#id3) 指令使用。

#### NOTE
Angie 还包含一个现成的 [all](#prometheus-all) 模板，
其中包含一组最常用的指标。

可以包含任意数量的指标定义，
每个定义具有以下结构：
<metric_name> <variable> [`path=`<match_string>] [`type=`<type>] [`help=`<help>]。

| `metric_name`   | 设置指标名称，<br/>该名称将以 Prometheus 格式添加到响应中。<br/>可以包含可选的标签部分（` *...*`），例如：<br/><br/>```none<br/>http_requests_total{method="$1",code="$2"}<br/>```<br/><br/>标签值可以使用 Angie 变量；<br/>如果 match_string 定义为正则表达式，<br/>您还可以使用该表达式中定义的捕获组。<br/>这些变量和组在获取指标值时进行求值，<br/>指标值由 variable 设置。   |
|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `variable`      | 设置将被求值并作为指标值添加到响应中的变量名称。<br/>如果变量不存在或求值结果为空（`""`），<br/>则不添加该指标。                                                                                                                                                                                                             |

指标使用 variable 设置的值进行计算；
成功求值后，指标将添加到响应中，例如：

```nginx
'angie_time{version="$angie_version"}' $msec;
```

```console
$ curl localhost/p8s

    angie_time{version="|version|"} 1695119820.562
```

| `path=match_string`   | 与 Angie [/status](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics) API 子树中指标的所有端点路径进行匹配，<br/>允许一次将指标的多个实例添加到响应中。   |
|-----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|

在匹配期间，路径带有前导斜杠但不带尾部斜杠，
例如 `/angie/generation`；匹配不区分大小写。
有两种匹配方法：

| `path=exact_match`         | 通过逐字符比较进行检查。                                      |
|----------------------------|---------------------------------------------------|
| `path=~regular_expression` | 使用 PCRE 库进行检查；可以定义捕获组，<br/>用于 metric_name 字段的标签中。 |

如果 match_string 匹配任何路径，
该路径处的 Angie 指标值将存储在
[$p8s_value](#v-p8s-value) 变量中，
该变量可在指定 `path=` 时在 variable 字段中使用。

如果 match_string 以尾部斜杠结尾，指标值为相应列表或对象中的项目数。例如：

```nginx
'angie_http_server_zones_count' $p8s_value
    path=/http/server_zones/;
```

对于正则表达式，可能有多个匹配路径；
指标将针对\*每个\*匹配添加到响应中。
结合捕获组，这允许获取一系列具有相同名称和不同标签的指标，例如：

```nginx
'angie_slabs_slots_free{zone="$1",size="$2"}' $p8s_value
    path=~^/slabs/([^/]+)/slots/([^/]+)/free$;
```

此定义为配置中当前存在的所有区域和所有大小添加指标：

```none
angie_slabs_slots_free{zone="one",size="8"} 502
angie_slabs_slots_free{zone="one",size="16"} 249
angie_slabs_slots_free{zone="one",size="32"} 122
angie_slabs_slots_free{zone="one",size="128"} 22
angie_slabs_slots_free{zone="one",size="512"} 4
angie_slabs_slots_free{zone="two",size="8"} 311
...
```

如果没有匹配（使用任何匹配方法），
则不添加该指标。

#### NOTE
`path=` 参数仅在
使用 [API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#http-api) 模块构建 Angie 时可用。

| `type=type`、`help=help`   | 分别以 [Prometheus 格式](https://prometheus.io/docs/instrumenting/exposition_formats/#comments-help-text-and-type-information) 设置指标的类型和帮助字符串，<br/>它们与指标一起添加到响应中，不进行更改或验证。   |
|---------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

<a id="built-in-variables-5-1"></a>

## 内置变量

`http_prometheus` 模块有一个内置变量，
当将 Angie API [/status](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics) 部分的指标路径
与 [prometheus_template](#prometheus-template) 指令定义的指标的 match_string 参数匹配时，
该变量接收其值。

<a id="v-p8s-value"></a>

### `$p8s_value`

如果 [prometheus_template](#prometheus-template) 中定义的指标的 match_string
匹配任何路径，
位于该路径的 Angie 指标值将存储在 `$p8s_value` 变量中。
它旨在用于基于 `path=` 参数计算的指标定义中的 variable 字段。

存储在 `$p8s_value` 变量中的 Angie 指标值
并不总是满足 Prometheus 格式的要求。
在这种情况下，您可以使用 [map](https://cn.angie.software//angie/docs/configuration/modules/http/http_map.md#id3) 指令，
例如将字符串转换为数字：

```nginx
map $p8s_value $ups_state_n {
    up           0;
    unavailable  1;
    down         2;
    default      3;
}

prometheus_template main {
    'angie_http_upstreams_state{upstream="$1",peer="$2"}' $ups_state_n
        path=~^/http/upstreams/([^/]+)/peers/([^/]+)/state$;
}
```

如果 Angie 指标具有布尔值，即 `true` 或 `false`，
变量将接收值 `"1"` 或 `"0"`；
如果指标值为 `null`，变量将为 `"(null)"`。
对于日期，使用整数 UNIX 纪元格式。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_proxy.md

<!-- review: finished -->

<a id="http-proxy"></a>

# 代理

允许将请求传递到另一个(被代理的)服务器。

<a id="configuration-example-34"></a>

## 配置示例

```nginx
location / {
    proxy_pass       http://localhost:8000;
    proxy_set_header Host      $host;
    proxy_set_header X-Real-IP $remote_addr;

    proxy_cache       cache_zone;
    proxy_cache_valid 200 302 10m;
    proxy_cache_valid 404      1m;
}
```

<a id="directives-35"></a>

## 指令

<a id="index-0"></a>

<a id="proxy-bind"></a>

### proxy_bind

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_bind` address [`transparent`] | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------|
| 默认值                                                                                  | —                                               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                          |

使到被代理服务器的出站连接从指定的本地 IP 地址(可选端口)发起。参数值可以包含变量。特殊值 `off` 取消从上一级配置继承的 proxy_bind 指令的效果,允许系统自动分配本地 IP 地址和端口。

`transparent` 参数允许到被代理服务器的出站连接从非本地 IP 地址发起,例如,从客户端的真实 IP 地址:

```nginx
proxy_bind $remote_addr transparent;
```

为了使此参数生效,通常需要以 [超级用户](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 权限运行 Angie 工作进程。在 Linux 上不需要这样做,因为如果指定了 `transparent` 参数,工作进程会从主进程继承 CAP_NET_RAW 能力。

#### NOTE
需要配置内核路由表以拦截来自被代理服务器的网络流量。

<a id="index-1"></a>

<a id="proxy-buffer-size"></a>

### proxy_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_buffer_size` size;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `proxy_buffer_size 4k|8k;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

设置用于读取从被代理服务器接收的响应的第一部分的缓冲区大小。这部分通常包含一个小的响应头。默认情况下,缓冲区大小等于一个内存页。根据平台不同,这可能是 4K 或 8K。但可以设置得更小。

<a id="index-2"></a>

<a id="proxy-buffering"></a>

### proxy_buffering

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_buffering` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `proxy_buffering on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

启用或禁用来自被代理服务器的响应的缓冲。

| `on`   | Angie 尽快从被代理服务器接收响应,将其保存到由 [proxy_buffer_size](#proxy-buffer-size) 和 [proxy_buffers](#proxy-buffers) 指令设置的缓冲区中。向客户端发送会并行进行: 已填满的缓冲区会被交给发送,但总量不超过 [proxy_busy_buffers_size](#proxy-busy-buffers-size)。如果缓冲区未被完全填满,则不会被送去发送,除非这是响应的最后一部分。因此,当需要即时传输每隔几个字节时,缓冲读取模式并不适合。如果整个响应无法放入内存,则可以将其一部分保存到磁盘上的 [临时文件](#proxy-temp-path) 中。写入临时文件由 [proxy_max_temp_file_size](#proxy-max-temp-file-size) 和 [proxy_temp_file_write_size](#proxy-temp-file-write-size) 指令控制。   |
|--------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 响应在接收时立即传递给客户端。Angie 以"读取 — 发送"的循环工作,不会等待缓冲区被填满: 例如从 4K 缓冲区读取到 10 字节时就会立即发送。同时,如果整个响应可以放入缓冲区,Angie 也可能一次读完整。Angie 一次可以从服务器接收的数据的最大大小由 [proxy_buffer_size](#proxy-buffer-size) 指令设置。使用 `off` 时,Angie 不会缓存响应,并且 [proxy_limit_rate](#proxy-limit-rate) 不生效。                                                                                                                                                                                                      |

也可以通过在 `X-Accel-Buffering` 响应头字段中传递 "yes" 或 "no" 来启用或禁用缓冲。可以使用 [proxy_ignore_headers](#proxy-ignore-headers) 指令禁用此功能。

<a id="index-3"></a>

<a id="proxy-buffers"></a>

### proxy_buffers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_buffers` number size;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `proxy_buffers 8 4k | 8k;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

设置用于从被代理服务器读取响应的缓冲区的数量和大小,针对单个连接。

默认情况下,缓冲区大小等于一个内存页。根据平台不同,这可能是 4K 或 8K。

<a id="index-4"></a>

<a id="proxy-busy-buffers-size"></a>

### proxy_busy_buffers_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_busy_buffers_size` size;     |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `proxy_busy_buffers_size 8k | 16k;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

当启用来自被代理服务器的响应的 [缓冲](#proxy-buffering) 时,限制在响应尚未完全读取时可以忙于向客户端发送响应的缓冲区的总大小。同时,其余的缓冲区可用于读取响应,如果需要,还可以将部分响应缓冲到临时文件中。

默认情况下,大小受 [proxy_buffer_size](#proxy-buffer-size) 和 [proxy_buffers](#proxy-buffers) 指令设置的两个缓冲区大小的限制。

<a id="index-5"></a>

<a id="proxy-cache"></a>

### proxy_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache` zone | `off` [`path=`path];   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `proxy_cache off;`                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

定义用于缓存的共享内存区域。
同一个区域可以在多个地方使用。
参数值可以包含变量。

| `off`   | 禁用从上一级配置继承的缓存。   |
|---------|------------------|

在 Angie PRO 中,您可以指定多个使用相同 `keys_zone` 值的 [proxy_cache_path](#proxy-cache-path) 指令来启用\`缓存分片\`。这样做时,您应该设置使用此 `keys_zone` 值的 [proxy_cache](#proxy-cache) 指令的 `path` 参数:

| `path=`path   | 该值在从后端\*缓存\*响应时进行评估,预期使用变量,包括那些包含来自响应的信息的变量。<br/><br/>如果响应从缓存中获取,则不会重新评估 path;<br/>因此,缓存的响应保留其原始 path,<br/>直到它从缓存中删除。   |
|---------------|-------------------------------------------------------------------------------------------------------------------------|

这允许通过将 [map](https://cn.angie.software//angie/docs/configuration/modules/http/http_map.md#id3) 指令或脚本应用于来自后端的响应来选择所需的缓存路径。`Content-Type` 的示例:

```nginx
proxy_cache_path /cache/one keys_zone=zone:10m;
proxy_cache_path /cache/two keys_zone=zone;

map $upstream_http_content_type $cache {
   ~^text/  one;
   default  two;
}

server {
   ...
   location / {
       proxy_pass http://backend;
       proxy_cache zone path=/cache/$cache;
       proxy_cache_valid 200 10m;
   }
}
```

这里有两个缓存路径和一个用于区分它们的变量映射。
如果 `Content-Type` 以 `text/` 开头,将选择第一个路径,
否则选择第二个。

#### NOTE
使用 [proxy_cache](#proxy-cache) 时,
通常还需要设置 [proxy_cache_valid](#proxy-cache-valid) 指令
来明确指定响应的缓存时间。
如果未设置,Angie 不使用默认值,
而是根据来自服务器的 HTTP 响应头
按以下优先级顺序确定响应缓存时间:

1. `X-Accel-Expires` 头(最高优先级)。
2. 带有 `max-age` 或 `s-maxage` 参数的 `Cache-Control` 头。
3. `Expires` 头。

如果这些头都不包含有效值或根本不存在,
响应将不会被缓存,因为无法确定其过期时间。

<a id="index-6"></a>

<a id="proxy-cache-background-update"></a>

### proxy_cache_background_update

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_background_update` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------|
| 默认值                                                                                  | `proxy_cache_background_update off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                          |

允许启动后台子请求来更新过期的缓存项,同时将陈旧的缓存响应返回给客户端。

#### WARNING
在更新陈旧缓存响应时使用它必须被 [允许](#proxy-cache-use-stale-updating)。

<a id="index-7"></a>

<a id="proxy-cache-bypass"></a>

### proxy_cache_bypass

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_bypass` ...;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

定义不从缓存中获取响应的条件。如果字符串参数中至少有一个值不为空且不等于 "0",则不会从缓存中获取响应:

```nginx
proxy_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
proxy_cache_bypass $http_pragma    $http_authorization;
```

可以与 [proxy_no_cache](#proxy-no-cache) 指令一起使用。

<a id="index-8"></a>

<a id="proxy-cache-convert-head"></a>

### proxy_cache_convert_head

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_convert_head` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | `proxy_cache_convert_head on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                     |

启用或禁用将 "HEAD" 方法转换为 "GET" 以进行缓存。如果禁用转换,:ref:缓存键 <proxy_cache_key> 必须包含 [$request_method](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-method)。

<a id="index-9"></a>

<a id="proxy-cache-key"></a>

### proxy_cache_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_key` string;                         |
|--------------------------------------------------------------------------------------|---------------------------------------------------|
| 默认值                                                                                  | `proxy_cache_key $scheme$proxy_host$request_uri;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                            |

定义缓存的键,例如:

```nginx
proxy_cache_key "$host$request_uri $cookie_user";
```

默认情况下,该指令的值接近于以下字符串

```nginx
proxy_cache_key $scheme$proxy_host$uri$is_args$args;
```

<a id="index-10"></a>

<a id="proxy-cache-lock"></a>

### proxy_cache_lock

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_lock` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `proxy_cache_lock off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

启用后,一次只允许一个请求通过向被代理服务器传递请求来填充根据 [proxy_cache_key](#proxy-cache-key) 指令标识的新缓存元素。对于相同缓存元素的其他请求将等待响应出现在缓存中,或者等待该元素的缓存锁被释放,最长等待时间由 [proxy_cache_lock_timeout](#proxy-cache-lock-timeout) 指令设置。

<a id="index-11"></a>

<a id="proxy-cache-lock-age"></a>

### proxy_cache_lock_age

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_lock_age` time;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `proxy_cache_lock_age 5s;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

如果传递给被代理服务器以填充新缓存元素的最后一个请求在指定时间内未完成,则可以再向被代理服务器传递一个请求。

<a id="index-12"></a>

<a id="proxy-cache-lock-timeout"></a>

### proxy_cache_lock_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_lock_timeout` time;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `proxy_cache_lock_timeout 5s;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

设置 [proxy_cache_lock](#proxy-cache-lock) 的超时时间。当超时时间到期时,请求将被传递给被代理服务器,但响应不会被缓存。

<a id="index-13"></a>

<a id="proxy-cache-max-range-offset"></a>

### proxy_cache_max_range_offset

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_max_range_offset` number;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | —                                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

为字节范围请求设置偏移量（以字节为单位）。如果范围超出指定的偏移量，范围请求将被传递到代理服务器，并且响应将不会被缓存。

<a id="index-14"></a>

<a id="proxy-cache-methods"></a>

### proxy_cache_methods

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_methods` `GET` | `HEAD` | `POST` ...;   |
|--------------------------------------------------------------------------------------|------------------------------------------------------|
| 默认值                                                                                  | `proxy_cache_methods GET HEAD;`                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                               |

如果客户端请求方法在此指令中列出，则响应将被缓存。"GET" 和 "HEAD" 方法始终会添加到列表中，但建议显式指定它们。另请参阅 [proxy_no_cache](#proxy-no-cache) 指令。

<a id="index-15"></a>

<a id="proxy-cache-min-uses"></a>

### proxy_cache_min_uses

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_min_uses` number;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `proxy_cache_min_uses 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

设置在多少次请求后响应将被缓存。

#### WARNING
缓存元数据存储在共享内存中。手动删除缓存文件不会重置计数器，可能导致不可预测的行为。要完全重置，请停止服务器，删除缓存目录，然后重新启动。

#### NOTE
第三方缓存清除模块（例如 [缓存清除](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge)）仅删除文件，但不会重置 proxy_cache_min_uses 计数器。该指令旨在保护缓存免受不频繁请求的污染，在清除时重置计数器可能会对性能产生负面影响。

<a id="index-16"></a>

<a id="proxy-cache-path"></a>

### proxy_cache_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_path` path [`levels=`levels] [`use_temp_path=``on` | `off`] `keys_zone=`name:size[:`file=`file] [`inactive=`time] [`max_size=`size] [`min_free=`size] [`manager_files=`number] [`manager_sleep=`time] [`manager_threshold=`time] [`loader_files=`number] [`loader_sleep=`time] [`loader_threshold=`time];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                                                                                                                                                                                                                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                                                                                                                                                                                                                                                                                                     |

设置缓存的 path 和其他参数。缓存数据存储在文件中。缓存中的文件名是对 [缓存键](#proxy-cache-key) 应用 MD5 函数的结果。

| `levels`   | 定义缓存的层次结构级别：从 1 到 3，每个级别接受值 1 或 2。   |
|------------|--------------------------------------|

例如，在以下配置中：

```nginx
proxy_cache_path /data/angie/cache levels=1:2 keys_zone=one:10m;
```

缓存中的文件名将如下所示：

```nginx
/data/angie/cache/c/29/b7f54b2df7773722d382f4809d65029c
```

缓存的响应首先写入临时文件，然后重命名该文件。临时文件和缓存可以放在不同的文件系统上。但是，请注意，在这种情况下，文件将在两个文件系统之间复制，而不是执行廉价的重命名操作。因此，建议对于任何给定位置，将缓存和存放临时文件的目录放在同一文件系统上。

| `use_temp_path=on` | `off`   | 确定用于临时文件的目录                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
|------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `on`                         | 如果未指定该参数或设置为 `on`，将使用给定 location 的 [proxy_temp_path](#proxy-temp-path) 指令指定的目录                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `off`                        | 临时文件将直接放置在缓存目录中                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `keys_zone`                  | 设置用于存储所有活动键和数据信息的共享内存区域的名称和大小。缓存元数据存储在共享内存中。<br/><br/>1 兆字节的区域足以存储约 8000 个键。<br/><br/>当使用 `keys_zone` 指定可选的 file 时，<br/>Angie 会在主进程终止时将该区域的内容转储到磁盘，<br/>并在下次 [启动](https://cn.angie.software//angie/docs/configuration/runtime.md#runtime) 或 [二进制升级](https://cn.angie.software//angie/docs/configuration/runtime.md#service-upgrade) 后<br/>尝试在相同的内存地址恢复它，<br/>以确保更可靠的数据持久性并减少缓存加载时间。<br/><br/>如果由于区域大小更改、二进制版本不兼容或其他原因而无法恢复该区域，<br/>Angie 将记录警告（`failed to restore zone at address`）<br/>并且不会使用区域恢复机制。<br/>相反，不兼容的文件将被重命名为 `.old`；<br/>您可以删除它，<br/>或恢复其名称并将 Angie 还原到最初创建此文件的配置和版本。<br/><br/>#### WARNING<br/>确保正确指定 file 的路径，<br/>并具有 Angie 使用所需的访问权限，<br/>并受到保护以防止未经授权的访问；<br/>相对路径基于 [prefix](https://cn.angie.software//angie/docs/installation/sourcebuild.md#paths)。 |
| `inactive`                   | 如果在此参数指定的时间内未访问缓存数据，则无论其新鲜度如何，数据都将被删除。<br/><br/>默认情况下，`inactive` 为 10 分钟。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |

#### NOTE
#### Versionadded
Added in version 1.2.0: PRO

在 Angie PRO 中，可以使用相同的 `keys_zone` 值指定多个 proxy_cache_path 指令。共享内存区域大小只能在第一个指令中指定。将根据相应 [proxy_cache](#proxy-cache) 指令的 `path` 参数在指令之间进行选择。

一个特殊的\*\*缓存管理器\*\*进程会监控最大缓存大小和缓存所在文件系统的最小可用空间，当超过最大缓存大小或可用空间不足时，会删除最近最少使用的数据。数据删除以迭代方式进行。

| `max_size`          | 缓存大小的最大阈值                           |
|---------------------|-------------------------------------|
| `min_free`          | 缓存所在文件系统可用空间的最小阈值                   |
| `manager_files`     | 一次迭代中要删除的最大缓存项数<br/><br/>默认值：`100`。 |
| `manager_threshold` | 限制一次迭代的持续时间<br/><br/>默认值：`200` 毫秒。  |
| `manager_sleep`     | 配置迭代之间的暂停时间<br/><br/>默认值：`50` 毫秒。   |

Angie 启动一分钟后，会激活一个特殊的\*\*缓存加载器\*\*进程。
它扫描文件系统中先前缓存的数据，
并将这些信息加载到缓存区域中。
此进程以迭代方式工作；
每次迭代处理由 `loader_files` 参数指定的有限数量的项，
确保不超过 `loader_threshold`，
然后进行由 `loader_sleep` 定义的短暂暂停，
再继续处理下一批。
迭代会持续进行，
直到加载器处理完磁盘上所有现有的缓存条目：

| `loader_files`     | 一次迭代中要加载的最大缓存项数<br/><br/>默认值：`100`   |
|--------------------|--------------------------------------|
| `loader_threshold` | 限制一次迭代的持续时间<br/><br/>默认值：`200` 毫秒    |
| `loader_sleep`     | 配置迭代之间的暂停时间<br/><br/>默认值：`50` 毫秒     |

#### NOTE
为 `keys_zone` 参数指定 file 不会影响缓存加载器的操作。

<a id="index-17"></a>

<a id="proxy-cache-revalidate"></a>

### proxy_cache_revalidate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_revalidate` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `proxy_cache_revalidate off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

启用使用带有 `If-Modified-Since` 和 `If-None-Match` 头字段的条件请求来重新验证过期的缓存项。

<a id="index-18"></a>

<a id="proxy-cache-use-stale"></a>

### proxy_cache_use_stale

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_use_stale` `error` | `timeout` | `invalid_header` | `updating` | `http_500` | `http_502` | `http_503` | `http_504` | `http_403` | `http_404` | `http_429` | `off` ...;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `proxy_cache_use_stale off;`                                                                                                                                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                                                                |

确定在哪些情况下可以使用过期的缓存响应。该指令的参数与 [proxy_next_upstream](#proxy-next-upstream) 指令的参数相匹配。

| `error`    | 如果无法选择代理服务器来处理请求，则允许使用过期的缓存响应。                            |
|------------|-----------------------------------------------------------|
| `updating` | 附加参数，如果缓存响应当前正在更新，则允许使用过期的缓存响应。这可以在更新缓存数据时最小化对代理服务器的访问次数。 |

也可以直接在响应头中启用使用过期的缓存响应，指定响应过期后的秒数：

* `Cache-Control` 头字段的 [stale-while-revalidate](https://datatracker.ietf.org/doc/html/rfc5861#section-3) 扩展允许在缓存响应当前正在更新时使用过期的缓存响应。
* `Cache-Control` 头字段的 [stale-if-error](https://datatracker.ietf.org/doc/html/rfc5861#section-4) 扩展允许在发生错误时使用过期的缓存响应。

#### NOTE
这比使用指令参数的优先级更低。

要在填充新缓存元素时最小化对代理服务器的访问次数，可以使用 [proxy_cache_lock](#proxy-cache-lock) 指令。

<a id="index-19"></a>

<a id="proxy-cache-valid"></a>

### proxy_cache_valid

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cache_valid` [code ...] time;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

为不同的响应代码设置缓存时间。例如，以下指令

```nginx
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404      1m;
```

为代码 200 和 302 的响应设置 10 分钟的缓存时间，为代码 404 的响应设置 1 分钟的缓存时间。

如果只指定了缓存时间，

```nginx
proxy_cache_valid 5m;
```

则只缓存 200、301 和 302 响应。

此外，可以指定 `any` 参数来缓存任何响应：

```nginx
proxy_cache_valid 200 302 10m;
proxy_cache_valid 301      1h;
proxy_cache_valid any      1m;
```

#### NOTE
缓存参数也可以直接在响应头中设置。这比使用指令设置缓存时间具有更高的优先级。

* `X-Accel-Expires` 头字段以秒为单位设置响应的缓存时间。零值会禁用响应的缓存。如果值以 `@` 前缀开头，则设置自 Epoch 以来的绝对时间（以秒为单位），直到该时间响应可以被缓存。
* 如果头中不包含 `X-Accel-Expires` 字段，则可以在 `Expires` 或 `Cache-Control` 头字段中设置缓存参数。
* 如果头中包含 `Set-Cookie` 字段，则不会缓存此类响应。
* 如果头中包含值为 "`*`" 的 `Vary` 字段，则不会缓存此类响应。如果头中包含其他值的 `Vary` 字段，则会考虑相应的请求头字段来缓存此类响应。

可以使用 [proxy_ignore_headers](#proxy-ignore-headers) 指令禁用对这些响应头字段中一个或多个的处理。

<a id="index-20"></a>

<a id="proxy-connect-timeout"></a>

### proxy_connect_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_connect_timeout` time;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `proxy_connect_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

定义与被代理服务器建立连接的超时时间。需要注意的是，此超时时间通常不能超过 75 秒。

<a id="index-21"></a>

<a id="proxy-connection-drop"></a>

### proxy_connection_drop

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_connection_drop` time | `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | `proxy_connection_drop off;`                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                         |

启用在被代理服务器从组中移除或被 [reresolve](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve) 进程或 [API 命令](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config-methods) `DELETE` 标记为永久不可用后，终止到该服务器的所有连接。

当为客户端或被代理服务器处理下一个读取或写入事件时，连接将被终止。

设置 time 启用连接终止 [超时](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)；
设置为 `on` 时，连接将立即断开。

<a id="index-22"></a>

<a id="proxy-cookie-domain"></a>

### proxy_cookie_domain

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cookie_domain` `off`;<br/><br/>`proxy_cookie_domain` domain replacement;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------|
| 默认值                                                                                  | `proxy_cookie_domain off;`                                                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                            |

设置应在被代理服务器响应的 `Set-Cookie` 头字段的 domain 属性中更改的文本。假设被代理服务器返回的 `Set-Cookie` 头字段带有属性 "domain=localhost"。指令

```nginx
proxy_cookie_domain localhost example.org;
```

将把此属性重写为 "domain=example.org"。

domain 和 replacement 字符串以及 domain 属性中的前导点将被忽略。该值不区分大小写。

domain 和 replacement 字符串可以包含变量：

```nginx
proxy_cookie_domain www.$host $host;
```

该指令也可以使用正则表达式指定。在这种情况下，domain 应以 "~" 符号开头。正则表达式可以包含命名捕获和位置捕获，replacement 可以引用它们：

```nginx
proxy_cookie_domain ~\.(?P<sl_domain>[-0-9a-z]+\.[a-z]+)$ $sl_domain;
```

可以在同一级别指定多个 proxy_cookie_domain 指令：

```nginx
proxy_cookie_domain localhost example.org;
proxy_cookie_domain ~\.([a-z]+\.[a-z]+)$ $1;
```

如果多个指令可以应用于 cookie，将选择第一个。

`off` 参数取消从上一级配置继承的 proxy_cookie_domain 指令的效果。

<a id="index-23"></a>

<a id="proxy-cookie-flags"></a>

### proxy_cookie_flags

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cookie_flags` `off` | cookie [flag ...];   |
|--------------------------------------------------------------------------------------|---------------------------------------------------|
| 默认值                                                                                  | `proxy_cookie_flags off;`                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                            |

为 cookie 设置一个或多个标志。cookie 可以包含文本、变量及其组合。标志可以包含文本、变量及其组合。

`secure`、`httponly`、`samesite=strict`、
`samesite=lax`、`samesite=none` 参数添加相应的标志。

`nosecure`、`nohttponly`、`nosamesite` 参数删除相应的标志。

cookie 也可以使用正则表达式指定。在这种情况下，cookie 应以 "~" 符号开头。

可以在同一配置级别指定多个 `proxy_cookie_flags` 指令：

```nginx
proxy_cookie_flags one httponly;
proxy_cookie_flags ~ nosecure samesite=strict;
```

如果多个指令可以应用于 cookie，将选择第一个匹配的指令。在示例中，为 cookie `one` 添加 `httponly` 标志，对于所有其他 cookie 添加 `samesite=strict` 标志并删除 `secure` 标志。

`off` 参数取消从上一级配置继承的 proxy_cookie_flags 指令的效果。

<a id="index-24"></a>

<a id="proxy-cookie-path"></a>

### proxy_cookie_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_cookie_path` `off`;<br/><br/>`proxy_cookie_path` path replacement;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| 默认值                                                                                  | `proxy_cookie_path off;`                                                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                      |

设置应在被代理服务器响应的 `Set-Cookie` 头字段的 path 属性中更改的文本。假设被代理服务器返回的 `Set-Cookie` 头字段带有属性 "path=/two/some/uri/"。指令

```nginx
proxy_cookie_path /two/ /;
```

将把此属性重写为 "path=/some/uri/"。

path 和 replacement 字符串可以包含变量：

```nginx
proxy_cookie_path $uri /some$uri;
```

该指令也可以使用正则表达式指定。在这种情况下，path 应以 "~" 符号开头进行区分大小写的匹配，或以 "~\*" 符号开头进行不区分大小写的匹配。正则表达式可以包含命名捕获和位置捕获，replacement 可以引用它们：

```nginx
proxy_cookie_path ~*^/user/([^/]+) /u/$1;
```

可以在同一级别指定多个 proxy_cookie_path 指令：

```nginx
proxy_cookie_path /one/ /;
proxy_cookie_path / /two/;
```

如果多个指令可以应用于 cookie，将选择第一个匹配的指令。

`off` 参数取消从上一级配置继承的 proxy_cookie_path 指令的效果。

<a id="index-25"></a>

<a id="proxy-force-ranges"></a>

### proxy_force_ranges

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_force_ranges` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `proxy_force_ranges off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

无论被代理服务器响应中的 `Accept-Ranges` 字段如何，都为来自被代理服务器的缓存和非缓存响应启用字节范围支持。

<a id="index-26"></a>

<a id="proxy-headers-hash-bucket-size"></a>

### proxy_headers_hash_bucket_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_headers_hash_bucket_size` size;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `proxy_headers_hash_bucket_size 64;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

设置 [proxy_hide_header](#proxy-hide-header) 和 [proxy_set_header](#proxy-set-header) 指令使用的哈希表的桶大小。哈希表设置的详细信息在 [单独的文档](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes) 中提供。

<a id="index-27"></a>

<a id="proxy-headers-hash-max-size"></a>

### proxy_headers_hash_max_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_headers_hash_max_size` size;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `proxy_headers_hash_max_size 512;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

设置 [proxy_hide_header](#proxy-hide-header) 和 [proxy_set_header](#proxy-set-header) 指令使用的哈希表的最大大小。哈希表设置的详细信息在 [单独的文档](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes) 中提供。

<a id="index-28"></a>

<a id="proxy-hide-header"></a>

### proxy_hide_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_hide_header` field;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | —                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

默认情况下，Angie 不会将被代理服务器响应中的 `Date`、`Server`、`X-Pad` 和 `X-Accel-...` 头字段传递给客户端。proxy_hide_header 指令设置不会被传递的附加字段。相反，如果需要允许传递字段，可以使用 [proxy_pass_header](#proxy-pass-header) 指令。

<a id="index-29"></a>

<a id="proxy-http-version"></a>

### proxy_http_version

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_http_version` `1.0` | `1.1` | `3`;            |
|--------------------------------------------------------------------------------------|------------------------------------------------------|
| 默认值                                                                                  | `proxy_http_version 1.0;`                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location, limit_except |

设置代理的 HTTP 协议版本。
默认使用 1.0 版本。
建议使用 1.1 或更高版本
与 [keepalive 连接](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-keepalive) 一起使用。

<a id="index-30"></a>

<a id="proxy-http3-hq"></a>

### proxy_http3_hq

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_http3_hq` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `proxy_http3_hq off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                     |

切换特殊的 `hq-interop` 协商模式，
该模式用于 Angie 依赖的
[QUIC](#proxy-http-version)
[互操作性测试](https://github.com/marten-seemann/quic-interop-runner)。

#### WARNING
仅在运行明确需要此模式的专门测试时启用此模式。

<a id="index-31"></a>

<a id="proxy-http3-max-concurrent-streams"></a>

### proxy_http3_max_concurrent_streams

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_http3_max_concurrent_streams` number;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | `proxy_http3_max_concurrent_streams 128;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                                   |

初始化 HTTP/3 和 QUIC 设置，
并设置 [连接](#proxy-http-version) 中并发 HTTP/3 请求流的最大数量。
需要启用 [keepalive 连接](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-keepalive)。

<a id="index-32"></a>

<a id="proxy-http3-max-table-capacity"></a>

### proxy_http3_max_table_capacity

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_http3_max_table_capacity` number;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | `proxy_http3_max_table_capacity 4096;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                     |

设置代理连接的 [动态表](https://www.ietf.org/archive/id/draft-ietf-quic-qpack-20.html#name-dynamic-table)
容量。

#### NOTE
类似的指令 [http3_max_table_capacity](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#http3-max-table-capacity)
为服务器连接设置此值。
为避免错误，在代理模式下启用缓存时
会禁用动态表的使用。

<a id="index-33"></a>

<a id="proxy-http3-stream-buffer-size"></a>

### proxy_http3_stream_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_http3_stream_buffer_size` size;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `proxy_http3_stream_buffer_size 64k;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                             |

设置用于读取和写入 [QUIC 流](#proxy-http-version) 的缓冲区的 [大小](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)。

<a id="index-34"></a>

<a id="proxy-ignore-client-abort"></a>

### proxy_ignore_client_abort

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ignore_client_abort` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `proxy_ignore_client_abort off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

决定当客户端在未等待响应的情况下关闭连接时，是否应关闭与被代理服务器的连接。

<a id="index-35"></a>

<a id="proxy-ignore-headers"></a>

### proxy_ignore_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ignore_headers` field ...;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | —                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

禁用对来自代理服务器的某些响应头字段的处理。可以忽略以下字段：`X-Accel-Redirect`、`X-Accel-Expires`、`X-Accel-Limit-Rate`、`X-Accel-Buffering`、`X-Accel-Charset`、`Expires`、`Cache-Control`、`Set-Cookie` 和 `Vary`。

如果未禁用，处理这些头字段将产生以下效果：

* `X-Accel-Expires`、`Expires`、`Cache-Control`、`Set-Cookie` 和 `Vary` 设置响应 [缓存](#proxy-cache-valid) 的参数；
* `X-Accel-Redirect` 执行到指定 URI 的 [内部重定向](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#internal)；
* `X-Accel-Limit-Rate` 设置向客户端传输响应的 [速率限制](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#limit-rate)；
* `X-Accel-Buffering` 启用或禁用响应的 [缓冲](#proxy-buffering)；
* `X-Accel-Charset` 设置响应所需的 [字符集](https://cn.angie.software//angie/docs/configuration/modules/http/http_charset.md#id3)。

<a id="index-36"></a>

<a id="proxy-intercept-errors"></a>

### proxy_intercept_errors

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_intercept_errors` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `proxy_intercept_errors off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

确定状态码大于或等于 300 的代理响应应该传递给客户端，还是被拦截并重定向到 Angie 以使用 [error_page](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#error-page) 指令进行处理。

<a id="index-37"></a>

<a id="proxy-limit-rate"></a>

### proxy_limit_rate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_limit_rate` rate;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `proxy_limit_rate 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

限制从代理服务器读取响应的速度。
rate 以每秒字节数指定；允许使用变量。

| `0`   | 禁用速率限制   |
|-------|----------|

#### NOTE
该限制是针对每个请求设置的，因此如果 Angie 同时打开两个到代理服务器的连接，总速率将是指定限制的两倍。该限制仅在启用来自代理服务器的响应 [缓冲](#proxy-buffering) 时有效。

<a id="index-38"></a>

<a id="proxy-max-temp-file-size"></a>

### proxy_max_temp_file_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_max_temp_file_size` size;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `proxy_max_temp_file_size 1024m;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

当启用来自代理服务器的响应 [缓冲](#proxy-buffering) 时,如果整个响应无法放入 [proxy_buffer_size](#proxy-buffer-size) 和 [proxy_buffers](#proxy-buffers) 指令设置的缓冲区中,响应的一部分可以保存到临时文件中。此指令设置临时文件的最大大小。一次写入临时文件的数据大小由 [proxy_temp_file_write_size](#proxy-temp-file-write-size) 指令设置。

| `0`   | 禁用将响应缓冲到临时文件   |
|-------|----------------|

#### NOTE
此限制不适用于将被 [缓存](#proxy-cache) 或 [存储](#proxy-store) 到磁盘的响应。

<a id="index-39"></a>

<a id="proxy-method"></a>

### proxy_method

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_method` method;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | —                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location   |

指定在转发到代理服务器的请求中使用的 HTTP 方法,而不是来自客户端请求的方法。参数值可以包含变量。

<a id="index-40"></a>

<a id="proxy-next-upstream"></a>

### proxy_next_upstream

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_next_upstream` `error` | `timeout` | `invalid_header` | `http_500` | `http_502` | `http_503` | `http_504` | `http_403` | `http_404` | `http_429` | `non_idempotent` | `off` ...;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `proxy_next_upstream error timeout;`                                                                                                                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                                                                    |

指定在哪些情况下应将请求传递给 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 组中的下一个服务器：

| `error`          | 与服务器建立连接、向其传递请求或读取响应头时发生错误；                                                                                                                                  |
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `timeout`        | 与服务器建立连接、向其传递请求或读取响应头时发生超时；                                                                                                                                  |
| `invalid_header` | 服务器返回空响应或无效响应；                                                                                                                                               |
| `http_500`       | 服务器返回状态码为 500 的响应；                                                                                                                                           |
| `http_502`       | 服务器返回状态码为 502 的响应；                                                                                                                                           |
| `http_503`       | 服务器返回状态码为 503 的响应；                                                                                                                                           |
| `http_504`       | 服务器返回状态码为 504 的响应；                                                                                                                                           |
| `http_403`       | 服务器返回状态码为 403 的响应；                                                                                                                                           |
| `http_404`       | 服务器返回状态码为 404 的响应；                                                                                                                                           |
| `http_429`       | 服务器返回状态码为 429 的响应；                                                                                                                                           |
| `non_idempotent` | 通常,如果请求已发送到上游服务器,则不会将使用 [非幂等](https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.2) 方法<br/>（`POST`、`LOCK`、`PATCH`）的请求传递给下一个<br/>服务器；启用此选项将明确允许重试此类请求； |
| `off`            | 禁用将请求传递给下一个服务器。                                                                                                                                              |

#### NOTE
应该理解,只有在尚未向客户端发送任何内容时,才可能将请求传递给下一个服务器。也就是说,如果在传输响应的过程中发生错误或超时,则无法修复此问题。

该指令还定义了什么被视为与服务器通信的 [不成功尝试](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#max-fails)。

| `error`<br/><br/>`timeout`<br/><br/>`invalid_header`                                       | 始终被视为不成功尝试,即使它们未在指令中指定   |
|--------------------------------------------------------------------------------------------|--------------------------|
| `http_500`<br/><br/>`http_502`<br/><br/>`http_503`<br/><br/>`http_504`<br/><br/>`http_429` | 仅在指令中指定时才被视为不成功尝试        |
| `http_403`<br/><br/>`http_404`                                                             | 永远不会被视为不成功尝试             |

将请求传递给下一个服务器可以通过 [尝试次数](#proxy-next-upstream-tries) 和 [时间](#proxy-next-upstream-timeout) 进行限制。

<a id="index-41"></a>

<a id="proxy-next-upstream-timeout"></a>

### proxy_next_upstream_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_next_upstream_timeout` time;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `proxy_next_upstream_timeout 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

限制可以将请求传递给 [下一个服务器](#proxy-next-upstream) 的时间。

| `0`   | 禁用此限制   |
|-------|---------|

<a id="index-42"></a>

<a id="proxy-next-upstream-tries"></a>

### proxy_next_upstream_tries

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_next_upstream_tries` number;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `proxy_next_upstream_tries 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

限制将请求传递给 [下一个服务器](#proxy-next-upstream) 的可能尝试次数。

| `0`   | 禁用此限制   |
|-------|---------|

<a id="index-43"></a>

<a id="proxy-no-cache"></a>

### proxy_no_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_no_cache` string ...;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | —                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

定义响应不被保存到缓存的条件。如果字符串参数中至少有一个值不为空且不等于"0",则响应将不会被保存：

```nginx
proxy_no_cache $cookie_nocache $arg_nocache$arg_comment;
proxy_no_cache $http_pragma    $http_authorization;
```

可以与 [proxy_cache_bypass](#proxy-cache-bypass) 指令一起使用。

<a id="index-44"></a>

<a id="proxy-pass"></a>

### proxy_pass

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_pass` uri;                      |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location, if in location, limit_except |

设置代理服务器的协议和地址,以及一个可选的 URI,用于映射 location。协议可以指定为 `http` 或 `https`。地址可以指定为域名或 IP 地址,以及一个可选的端口：

```nginx
proxy_pass http://localhost:8000/uri/;
```

或者指定为 UNIX 域套接字路径,在 `unix` 关键字之后,并用冒号括起来：

```nginx
proxy_pass http://unix:/tmp/backend.socket:/uri/;
```

如果域名解析为多个地址,所有地址将以轮询方式使用。此外,地址还可以指定为 [服务器组](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream)。

参数值可以包含变量。在这种情况下,如果地址指定为域名,则会在已描述的服务器组中搜索该名称,如果未找到,则使用 [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 来确定。

<a id="proxy-pass-uri"></a>

请求 URI 按以下方式传递给服务器:

* 如果 `proxy_pass` 指令\*\*带有 URI\*\* 指定,那么当请求传递给服务器时,:ref:规范化 <location> 请求 URI 中与 location 匹配的部分将被指令中指定的 URI 替换:

```nginx
location /name/ {
    proxy_pass http://127.0.0.1/remote/;
}
```

* 如果 `proxy_pass` **不带 URI** 指定,则在处理原始请求时,请求 URI 以客户端发送的相同形式传递给服务器,或者在处理更改后的 URI 时传递完整的规范化请求 URI:

```nginx
location /some/path/ {
    proxy_pass http://127.0.0.1;
}
```

在某些情况下,无法确定要替换的请求 URI 部分:

* 当 `location` 使用正则表达式指定时,以及在命名 `location` 内部。

在这些情况下,:samp:proxy_pass 应该不带 URI 指定。

* 当在代理的 `location` 内部使用 [rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 指令更改 URI 时,并且将使用此相同配置来处理请求 (break):

```nginx
location /name/ {
    rewrite    /name/([^/]+) /users?name=$1 break;
    proxy_pass http://127.0.0.1;
}
```

在这种情况下,指令中指定的 URI 将被忽略,完整的更改后的请求 URI 将传递给服务器。

* 当在 `proxy_pass` 中使用变量时:

```nginx
location /name/ {
    proxy_pass http://127.0.0.1$request_uri;
}
```

在这种情况下,如果在指令中指定了 URI,它将按原样传递给服务器,替换原始请求 URI。

[WebSocket](https://cn.angie.software//angie/docs/configuration/processing.md#websocket-proxy) 代理需要特殊配置。

#### NOTE
如果 `proxy_pass` 放置在前缀带有尾部斜杠的 `location` 中
(例如,:samp:location /name/),
并且 [auto_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#auto-redirect) 指令设置为 `default`,
则不带尾部斜杠的请求将被重定向 (`/name -> /name/`)。

<a id="index-45"></a>

<a id="proxy-pass-header"></a>

### proxy_pass_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_pass_header` field ...;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

允许将代理服务器的 [原本禁用](#proxy-hide-header) 的头字段传递给客户端。

<a id="index-46"></a>

<a id="proxy-pass-request-body"></a>

### proxy_pass_request_body

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_pass_request_body` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | `proxy_pass_request_body on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                    |

指示是否将原始请求正文传递给代理服务器。

```nginx
location /x-accel-redirect-here/ {
    proxy_method GET;
    proxy_pass_request_body off;
    proxy_set_header Content-Length "";

    proxy_pass ...;
}
```

另请参阅 [proxy_set_header](#proxy-set-header) 和 [proxy_pass_request_headers](#proxy-pass-request-headers) 指令。

<a id="index-47"></a>

<a id="proxy-pass-request-headers"></a>

### proxy_pass_request_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_pass_request_headers` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------------|
| 默认值                                                                                  | `proxy_pass_request_headers on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                       |

指示是否将原始请求的头字段传递给代理服务器。

```nginx
location /x-accel-redirect-here/ {
    proxy_method GET;
    proxy_pass_request_headers off;
    proxy_pass_request_body off;

    proxy_pass ...;
}
```

另请参阅 [proxy_set_header](#proxy-set-header) 和 [proxy_pass_request_body](#proxy-pass-request-body) 指令。

<a id="index-48"></a>

<a id="proxy-pass-trailers"></a>

### proxy_pass_trailers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_pass_trailers` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `proxy_pass_trailers off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

允许将代理服务器的尾部字段传递给客户端。

HTTP/1.1 中的尾部部分需要 [显式启用](https://datatracker.ietf.org/doc/html/rfc9110#section-6.5.1)。

```nginx
location / {
    proxy_http_version 1.1;
    proxy_set_header Connection "te";
    proxy_set_header TE "trailers";
    proxy_pass_trailers on;

    proxy_pass ...;
}
```

<a id="index-49"></a>

<a id="proxy-quic-active-connection-id-limit"></a>

### proxy_quic_active_connection_id_limit

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_quic_active_connection_id_limit` number;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------|
| 默认值                                                                                  | `proxy_quic_active_connection_id_limit 2;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                                      |

设置 [QUIC](#proxy-http-version)
`active_connection_id_limit` 传输参数值。
这是每个服务器可以维护的最大活动
[连接 ID](https://www.rfc-editor.org/rfc/rfc9000.html#name-connection-id)
数量。

<a id="index-50"></a>

<a id="proxy-quic-gso"></a>

### proxy_quic_gso

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_quic_gso` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `proxy_quic_gso off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                     |

切换使用
[通用分段卸载](https://docs.kernel.org/networking/segmentation-offloads.html#generic-segmentation-offload)
以 [QUIC](#proxy-http-version) 优化批处理模式发送数据。

<a id="index-51"></a>

<a id="proxy-quic-host-key"></a>

### proxy_quic_host_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_quic_host_key` file;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | —                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                  |

设置一个包含密钥的 file,
该密钥与 [QUIC](#proxy-http-version) 一起使用来加密
[无状态重置](https://www.rfc-editor.org/rfc/rfc9000.html#name-stateless-reset)
和
[地址验证](https://www.rfc-editor.org/rfc/rfc9000.html#address-validation)
令牌。
默认情况下,每次重启时都会生成一个随机密钥。
使用旧密钥生成的令牌不被接受。

<a id="index-52"></a>

<a id="proxy-read-timeout"></a>

### proxy_read_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_read_timeout` time;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `proxy_read_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

定义从代理服务器读取响应的超时时间。超时仅在两次连续读取操作之间设置,而不是用于整个响应的传输。如果代理服务器在此时间内未传输任何内容,则连接将关闭。

<a id="index-53"></a>

<a id="proxy-redirect"></a>

### proxy_redirect

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_redirect` `default`;<br/><br/>`proxy_redirect` `off`;<br/><br/>`proxy_redirect` redirect replacement;   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `proxy_redirect default;`                                                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                         |

设置应在代理服务器响应的 "Location" 和 "Refresh" 头字段中更改的文本。

假设代理服务器返回了头字段:

```console
Location: http://localhost:8000/two/some/uri/
```

指令

```nginx
proxy_redirect http://localhost:8000/two/ http://frontend/one/;
```

将把此字符串重写为:

```console
Location: http://frontend/one/some/uri/
```

replacement 字符串中可以省略服务器名称:

```nginx
proxy_redirect http://localhost:8000/two/ /;
```

然后将插入主服务器的名称和端口(如果不是 80)。

由 `default` 参数指定的默认替换使用 [location](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#location) 和 [proxy_pass](#proxy-pass) 指令的参数。因此,以下两个配置是等效的:

```nginx
location /one/ {
    proxy_pass     http://upstream:port/two/;
    proxy_redirect default;
}
```

```nginx
location /one/ {
    proxy_pass     http://upstream:port/two/;
    proxy_redirect http://upstream:port/two/ /one/;
}
```

#### WARNING
如果 [proxy_pass](#proxy-pass) 使用变量指定,则不允许使用 `default` 参数。

replacement 字符串可以包含变量:

```nginx
proxy_redirect http://localhost:8000/ http://$host:$server_port/;
```

redirect 也可以包含变量:

```nginx
proxy_redirect http://$proxy_host:8000/ /;
```

该指令可以使用正则表达式指定。在这种情况下,\`redirect\` 应该以 "~" 符号开头表示区分大小写的匹配,或者以 "~\*" 符号开头表示不区分大小写的匹配。正则表达式可以包含命名捕获和位置捕获,\`replacement\` 可以引用它们:

```nginx
proxy_redirect ~^(http://[^:]+):\d+(/.+)$ $1$2;
proxy_redirect ~*/user/([^/]+)/(.+)$      http://$1.example.com/$2;
```

可以在同一级别指定多个 proxy_redirect 指令:

```nginx
proxy_redirect default;
proxy_redirect http://localhost:8000/  /;
proxy_redirect http://www.example.com/ /;
```

如果多个指令可以应用于代理服务器响应的头字段,将选择第一个匹配的指令。

`off` 参数取消从上一级配置继承的 proxy_redirect 指令的效果。

使用此指令,还可以向代理服务器发出的相对重定向添加主机名:

```nginx
proxy_redirect / /;
```

<a id="index-54"></a>

<a id="proxy-request-buffering"></a>

### proxy_request_buffering

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_request_buffering` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | `proxy_request_buffering on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                    |

启用或禁用客户端请求体的缓冲。

| `on`   | 在将请求发送到代理服务器之前,从客户端 [读取](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-body-buffer-size) 整个请求体。   |
|--------|--------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 请求体在接收时立即发送到代理服务器。在这种情况下,如果 Angie 已经开始发送请求体,则无法将请求传递到 [下一个服务器](#proxy-next-upstream)。                                                |

当使用 HTTP/1.1 分块传输编码发送原始请求体时,无论指令值如何,请求体都将被缓冲,除非为代理 [启用](#proxy-http-version) HTTP/1.1。

<a id="index-55"></a>

<a id="proxy-send-lowat"></a>

### proxy_send_lowat

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_send_lowat` size;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `proxy_send_lowat 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

如果该指令设置为非零值,Angie 将尝试通过使用 [kqueue](https://cn.angie.software//angie/docs/configuration/processing.md#kqueue) 方法的 NOTE_LOWAT 标志或 SO_SNDLOWAT 套接字选项,以指定的大小最小化到代理服务器的出站连接上的发送操作数量。

#### NOTE
此指令在 Linux、Solaris 和 Windows 上被忽略。

<a id="index-56"></a>

<a id="proxy-send-timeout"></a>

### proxy_send_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_send_timeout` time;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `proxy_send_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

设置向代理服务器传输请求的超时时间。超时仅在两次连续的写操作之间设置,而不是用于整个请求的传输。如果代理服务器在此时间内没有接收到任何内容,连接将被关闭。

<a id="index-57"></a>

<a id="proxy-set-body"></a>

### proxy_set_body

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_set_body` value;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | —                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location    |

允许重新定义传递给代理服务器的请求体。该值可以包含文本、变量及其组合。

<a id="index-58"></a>

<a id="proxy-set-header"></a>

### proxy_set_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_set_header` field value;      |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `proxy_set_header Host $proxy_host;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

允许重新定义或追加字段到 [传递](#proxy-pass-request-headers) 给代理服务器的请求头。value 可以包含文本、变量及其组合。当且仅当当前级别没有定义 proxy_set_header 指令时,这些指令才从上一级配置继承。默认情况下,只重新定义两个字段:

```nginx
proxy_set_header Host       $proxy_host;
proxy_set_header Connection close;
```

如果启用了缓存,原始请求中的头字段 `If-Modified-Since`、`If-Unmodified-Since`、`If-None-Match`、`If-Match`、`Range` 和 `If-Range` 不会传递给代理服务器。

可以像这样传递未更改的 "Host" 请求头字段:

```nginx
proxy_set_header Host       $http_host;
```

但是,如果客户端请求头中不存在此字段,则不会传递任何内容。在这种情况下,最好使用 [$host](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-host) 变量 - 它的值等于 "Host" 请求头字段中的服务器名称,或者如果此字段不存在则为主服务器名称:

```nginx
proxy_set_header Host       $host;
```

此外,服务器名称可以与代理服务器的端口一起传递:

```nginx
proxy_set_header Host       $host:$proxy_port;
```

如果头字段的值为空字符串,则此字段不会传递给代理服务器:

```nginx
proxy_set_header Accept-Encoding "";
```

<a id="index-59"></a>

<a id="proxy-socket-keepalive"></a>

### proxy_socket_keepalive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_socket_keepalive` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `proxy_socket_keepalive off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

配置到代理服务器的出站连接的 "TCP keepalive" 行为。

| `off`   | 默认情况下,套接字使用操作系统的设置。        |
|---------|----------------------------|
| `on`    | 为套接字打开 SO_KEEPALIVE 套接字选项。 |

<a id="index-60"></a>

<a id="proxy-ssl-certificate"></a>

### proxy_ssl_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_certificate` file [file];   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

指定一个包含 PEM 格式证书的文件,用于向代理 HTTPS 服务器进行身份验证。可以在文件名中使用变量。

当启用 [proxy_ssl_ntls](#proxy-ssl-ntls) 时,该指令接受两个参数而不是一个:

```nginx
location /proxy {
    proxy_ssl_ntls  on;

    proxy_ssl_certificate      sign.crt enc.crt;
    proxy_ssl_certificate_key  sign.key enc.key;

    proxy_ssl_ciphers "ECC-SM2-WITH-SM4-SM3:ECDHE-SM2-WITH-SM4-SM3:RSA";

    proxy_pass https://backend:443;
}
```

<a id="index-61"></a>

<a id="proxy-ssl-certificate-cache"></a>

### proxy_ssl_certificate_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_certificate_cache` `off`;<br/><br/>`proxy_ssl_certificate_cache` `max=`N [`inactive=`time] [`valid=`time];   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `proxy_ssl_certificate_cache off;`                                                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                  |

定义一个缓存,用于存储使用变量指定的 [SSL 证书](#proxy-ssl-certificate) 和 [私钥](#proxy-ssl-certificate-key)。

该指令支持以下参数:

- `max` — 设置缓存中的最大元素数量。当缓存溢出时,将删除最近最少使用 (LRU) 的元素。
- `inactive` — 定义元素在未被访问后被删除的时间。默认为 10 秒。
- `valid` — 定义缓存元素被视为有效并可以重用的时间。默认为 60 秒。在此期间之后,证书将被重新加载或重新验证。
- `off` — 禁用缓存。

示例:

```nginx
proxy_ssl_certificate       $proxy_ssl_server_name.crt;
proxy_ssl_certificate_key   $proxy_ssl_server_name.key;
proxy_ssl_certificate_cache max=1000 inactive=20s valid=1m;
```

<a id="index-62"></a>

<a id="proxy-ssl-certificate-key"></a>

### proxy_ssl_certificate_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_certificate_key` file [file];   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | —                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                     |

指定一个包含 PEM 格式私钥的文件,用于向代理的 HTTPS 服务器进行身份验证。

可以指定值 `engine:`name`:id` 来代替文件,这将从名为 name 的 OpenSSL 引擎中加载具有指定 id 的私钥。

文件名中可以使用变量。

当启用 [proxy_ssl_ntls](#proxy-ssl-ntls) 时,该指令接受两个参数而不是一个:

```nginx
location /proxy {
    proxy_ssl_ntls  on;

    proxy_ssl_certificate      sign.crt enc.crt;
    proxy_ssl_certificate_key  sign.key enc.key;

    proxy_ssl_ciphers "ECC-SM2-WITH-SM4-SM3:ECDHE-SM2-WITH-SM4-SM3:RSA";

    proxy_pass https://backend:443;
}
```

<a id="index-63"></a>

<a id="proxy-ssl-ciphers"></a>

### proxy_ssl_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_ciphers` ciphers;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `proxy_ssl_ciphers DEFAULT;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

指定向代理的 HTTPS 服务器发送请求时启用的加密套件。加密套件以 OpenSSL 库能够理解的格式指定。

加密套件列表取决于安装的 OpenSSL 版本。
可以使用 `openssl ciphers` 命令查看完整列表。

#### WARNING
当使用 OpenSSL 时,:samp:proxy_ssl_ciphers 指令\*不\*配置 TLS 1.3 的加密套件。要使用 OpenSSL 调整 TLS 1.3 加密套件,请使用 [proxy_ssl_conf_command](#proxy-ssl-conf-command) 指令,该指令是为支持高级 SSL 配置而添加的。

- 在 LibreSSL 中,TLS 1.3 加密套件\*可以\*使用 `proxy_ssl_ciphers` 配置。
- 在 BoringSSL 中,TLS 1.3 加密套件完全无法配置。

<a id="index-64"></a>

<a id="proxy-ssl-conf-command"></a>

### proxy_ssl_conf_command

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_conf_command` name value;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

在与代理的 HTTPS 服务器建立连接时设置任意 OpenSSL 配置 [命令](https://docs.openssl.org/master/man3/SSL_CONF_cmd/)。

#### NOTE
当使用 OpenSSL 1.0.2 或更高版本时支持该指令。
要使用 OpenSSL 配置 TLS 1.3 加密套件,请使用 `ciphersuites` 命令。

可以在同一级别指定多个 proxy_ssl_conf_command 指令。当且仅当当前级别没有定义 proxy_ssl_conf_command 指令时,这些指令才会从上一级配置继承。

#### WARNING
请注意,直接配置 OpenSSL 可能会导致意外行为。

<a id="index-65"></a>

<a id="proxy-ssl-crl"></a>

### proxy_ssl_crl

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_crl` file;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | —                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location  |

指定一个包含 PEM 格式吊销证书 (CRL) 的文件,用于 [验证](#proxy-ssl-verify) 代理的 HTTPS 服务器的证书。

<a id="index-66"></a>

<a id="proxy-ssl-name"></a>

### proxy_ssl_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_name` name;        |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `proxy_ssl_name $proxy_host;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

允许覆盖用于 [验证](#proxy-ssl-verify) 代理的 HTTPS 服务器证书的服务器名称,以及在与代理的 HTTPS 服务器建立连接时 [通过 SNI 传递](#proxy-ssl-server-name) 的服务器名称。

默认情况下,使用 [proxy_pass](#proxy-pass) URL 的主机部分。

<a id="index-67"></a>

<a id="proxy-ssl-ntls"></a>

### proxy_ssl_ntls

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_ntls` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `proxy_ssl_ntls off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                     |

使用 [TongSuo](https://github.com/Tongsuo-Project/Tongsuo) TLS 库启用客户端对 NTLS 的支持。

```nginx
location /proxy {
    proxy_ssl_ntls  on;

    proxy_ssl_certificate      sign.crt enc.crt;
    proxy_ssl_certificate_key  sign.key enc.key;

    proxy_ssl_ciphers "ECC-SM2-WITH-SM4-SM3:ECDHE-SM2-WITH-SM4-SM3:RSA";

    proxy_pass https://backend:443;
}
```

#### NOTE
Angie 必须使用 `--with-ntls` 配置参数以及相应的支持 NTLS 的 SSL 库进行构建

```default
./configure --with-openssl=../Tongsuo-8.3.0 \
            --with-openssl-opt=enable-ntls  \
            --with-ntls
```

<a id="index-68"></a>

<a id="proxy-ssl-password-file"></a>

### proxy_ssl_password_file

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_password_file` file;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

指定一个包含 [私钥](#proxy-ssl-certificate-key) 密码短语的文件,每个密码短语单独占一行。加载密钥时会依次尝试这些密码短语。

<a id="index-69"></a>

<a id="proxy-ssl-protocols"></a>

### proxy_ssl_protocols

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_protocols` [`SSLv2`] [`SSLv3`] [`TLSv1`] [`TLSv1.1`] [`TLSv1.2`] [`TLSv1.3`];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `proxy_ssl_protocols TLSv1.2 TLSv1.3;`                                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                     |

#### Versionchanged
在 1.2.0 版本发生变更: `TLSv1.3` 参数已添加到默认设置中。

启用向代理的 HTTPS 服务器发送请求时使用的指定协议。

<a id="index-70"></a>

<a id="proxy-ssl-server-name"></a>

### proxy_ssl_server_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_server_name` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `proxy_ssl_server_name off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

启用或禁用在与代理的 HTTPS 服务器建立连接时，通过 [服务器名称指示](http://en.wikipedia.org/wiki/Server_Name_Indication) TLS 扩展（SNI，[RFC 6066](https://datatracker.ietf.org/doc/html/rfc6066.html)）传递由 [proxy_ssl_name](#proxy-ssl-name) 指令设置的服务器名称。

<a id="index-71"></a>

<a id="proxy-ssl-session-reuse"></a>

### proxy_ssl_session_reuse

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_session_reuse` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | `proxy_ssl_session_reuse on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                    |

确定在与代理服务器通信时是否可以重用 SSL 会话。如果日志中出现错误 "SSL3_GET_FINISHED:digest check failed"，请尝试禁用会话重用。

<a id="index-72"></a>

<a id="proxy-ssl-trusted-certificate"></a>

### proxy_ssl_trusted_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_trusted_certificate` file;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | —                                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

指定一个包含 PEM 格式受信任 CA 证书的文件，用于 [验证](#proxy-ssl-verify) 代理的 HTTPS 服务器的证书。

<a id="index-73"></a>

<a id="proxy-ssl-verify"></a>

### proxy_ssl_verify

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_verify` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `proxy_ssl_verify off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

启用或禁用对代理的 HTTPS 服务器证书的验证。

<a id="index-74"></a>

<a id="proxy-ssl-verify-depth"></a>

### proxy_ssl_verify_depth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_verify_depth` number;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `proxy_ssl_verify_depth 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

设置代理的 HTTPS 服务器证书链中的验证深度。

<a id="index-75"></a>

<a id="proxy-store"></a>

### proxy_store

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_store` `on` | `off` | string;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `proxy_store off;`                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

启用将文件保存到磁盘。

| `on`   | 根据 [alias](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#alias) 或 [root](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#root) 指令中指定的路径保存文件   |
|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 禁用文件保存                                                                                                                                                                                              |

文件名可以使用带变量的 `string` 显式设置：

```nginx
proxy_store /data/www$original_uri;
```

文件的修改时间根据响应中接收到的 `Last-Modified` 头字段设置。响应首先写入临时文件，然后重命名该文件。临时文件和响应的持久存储可以位于不同的文件系统上。但是，请注意，在这种情况下，文件将从一个文件系统复制到另一个文件系统，而不是在一个文件系统内进行廉价的重命名操作。因此建议对于任何给定的位置，保存的文件和由 [proxy_temp_path](#proxy-temp-path) 指令设置的临时文件目录都放在同一个文件系统上。

此指令可用于创建静态不可变文件的本地副本，例如：

```nginx
location /images/ {
    root               /data/www;
    error_page         404 = /fetch$uri;
}

location /fetch/ {
    internal;

    proxy_pass         http://backend/;
    proxy_store        on;
    proxy_store_access user:rw group:rw all:r;
    proxy_temp_path    /data/temp;

    alias              /data/www/;
}
```

或者像这样：

```nginx
location /images/ {
    root               /data/www;
    error_page         404 = @fetch;
}

location @fetch {
    internal;

    proxy_pass         http://backend;
    proxy_store        on;
    proxy_store_access user:rw group:rw all:r;
    proxy_temp_path    /data/temp;

    root               /data/www;
}
```

<a id="index-76"></a>

<a id="proxy-store-access"></a>

### proxy_store_access

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_store_access` users:permissions ...;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | `proxy_store_access user:rw;`                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                        |

设置新创建的文件和目录的访问权限，例如：

```nginx
proxy_store_access user:rw group:rw all:r;
```

如果指定了任何 `group` 或 `all` 访问权限，则可以省略 `user` 权限：

```nginx
proxy_store_access group:rw all:r;
```

<a id="index-77"></a>

<a id="proxy-temp-file-write-size"></a>

### proxy_temp_file_write_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_temp_file_write_size` size;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `proxy_temp_file_write_size 8k|16k;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

当启用将代理服务器的响应缓冲到临时文件时，限制一次写入临时文件的数据大小。默认情况下，大小受 [proxy_buffer_size](#proxy-buffer-size) 和 [proxy_buffers](#proxy-buffers) 指令设置的两个缓冲区限制。临时文件的最大大小由 [proxy_max_temp_file_size](#proxy-max-temp-file-size) 指令设置。

<a id="index-78"></a>

<a id="proxy-temp-path"></a>

### proxy_temp_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_temp_path` path [level1 [level2 [level3]]]\`;                                                                                               |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `proxy_temp_path proxy_temp;`<br/>(路径取决于 [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#paths) `--http-proxy-temp-path`) |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                             |

定义用于存储从代理服务器接收的数据的临时文件的目录。在指定目录下可以使用最多三级子目录层次结构。例如，在以下配置中

```nginx
proxy_temp_path /spool/angie/proxy_temp 1 2;
```

临时文件可能如下所示：

```nginx
/spool/angie/proxy_temp/7/45/00000123457
```

另请参阅 [proxy_cache_path](#proxy-cache-path) 指令的 `use_temp_path` 参数。

<a id="built-in-variables-6"></a>

## 内置变量

http_proxy 模块支持内置变量，可用于使用 [proxy_set_header](#proxy-set-header) 指令组合头部：

<a id="v-proxy-host"></a>

### `$proxy_host`

[proxy_pass](#proxy-pass) 指令中指定的被代理服务器的名称和端口；

<a id="v-proxy-port"></a>

### `$proxy_port`

[proxy_pass](#proxy-pass) 指令中指定的被代理服务器的端口，或协议的默认端口；

<a id="v-proxy-add-x-forwarded-for"></a>

### `$proxy_add_x_forwarded_for`

客户端请求头字段 `X-Forwarded-For` 附加 [$remote_addr](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-remote-addr) 变量后的值，以逗号分隔。如果客户端请求头中不存在 `X-Forwarded-For` 字段，则 [$proxy_add_x_forwarded_for](#v-proxy-add-x-forwarded-for) 变量等于 [$remote_addr](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-remote-addr) 变量。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_random_index.md

<!-- review: finished -->

<a id="http-random-index"></a>

# Random Index

该模块处理以斜杠字符 (`/`) 结尾的请求，并在目录中随机选择一个文件作为索引文件提供服务。该模块在 `http_index` 模块之前处理。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，该模块默认不会被构建；需要通过 `‑‑with‑http_random_index_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 来启用。

在从 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 获取的软件包和镜像中，该模块已包含在构建中。

<a id="configuration-example-35"></a>

## 配置示例

```nginx
location / {
    random_index on;
}
```

<a id="directives-36"></a>

## 指令

<a id="index-0"></a>

<a id="random-index"></a>

### random_index

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `random_index` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `random_index off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location                       |

启用或禁用在周围位置中模块的处理。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_realip.md

<!-- review: finished -->

<a id="http-realip"></a>

# RealIP

该模块用于将客户端地址和可选端口更改为指定头字段中发送的地址和端口。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，
该模块默认未构建；
需要通过
`--with-http_realip_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 进行启用。

在来自 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的包和镜像中，
该模块已包含在构建中。

<a id="configuration-example-36"></a>

## 配置示例

```nginx
set_real_ip_from  192.168.1.0/24;
set_real_ip_from  192.168.2.1;
set_real_ip_from  2001:0db8::/32;
real_ip_header    X-Forwarded-For;
real_ip_recursive on;
```

<a id="directives-37"></a>

## 指令

<a id="index-0"></a>

<a id="set-real-ip-from"></a>

### set_real_ip_from

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `set_real_ip_from` address | CIDR | `unix:`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认                                                                                   | —                                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                         |

定义已知发送正确替换地址的可信地址。
如果指定了特殊值 `unix:`，则所有UNIX域套接字将被信任。
可信地址也可以使用主机名指定。

<a id="index-1"></a>

<a id="real-ip-header"></a>

### real_ip_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `real_ip_header` field | `X-Real-IP` | `X-Forwarded-For` | `proxy_protocol`;   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| 默认                                                                                   | `real_ip_header X-Real-IP;`                                                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                         |

定义请求头字段，其值将用于替换客户端地址。

包含可选端口的请求头字段值也用于替换客户端端口。地址和端口应根据 [RFC 3986](https://datatracker.ietf.org/doc/html/rfc3986) 进行指定。

`proxy_protocol` 参数将客户端地址更改为来自PROXY协议头的地址。必须通过在 [listen](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#listen) 指令中设置 proxy_protocol 参数来预先启用PROXY协议。

<a id="index-2"></a>

<a id="real-ip-recursive"></a>

### real_ip_recursive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `real_ip_recursive` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认                                                                                   | `real_ip_recursive off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

如果禁用递归搜索，则与可信地址之一匹配的原始客户端地址被请求头字段中由 [real_ip_header](#real-ip-header) 指令定义的最后一个地址替换。如果启用递归搜索，则与可信地址之一匹配的原始客户端地址被请求头字段中最后一个非可信地址替换。

<a id="built-in-variables-7"></a>

## 内置变量

<a id="v-realip-remote-addr"></a>

### `$realip_remote_addr`

保存原始客户端地址

<a id="v-realip-remote-port"></a>

### `$realip_remote_port`

保存原始客户端端口


# https://cn.angie.software/angie/docs/configuration/modules/http/http_referer.md

<!-- review: finished -->

<a id="http-referer"></a>

# Referer

该模块用于阻止 `Referer` 头字段值无效的请求访问站点。需要注意的是，伪造一个带有适当 `Referer` 字段值的请求是相当容易的，因此该模块的预期目的不是彻底阻止此类请求，而是阻止由常规浏览器发送的大量请求流。还应考虑到，即使是有效请求，常规浏览器也可能不发送 `Referer` 字段。

<a id="configuration-example-37"></a>

## 配置示例

```nginx
valid_referers none blocked server_names
               *.example.com example.* www.example.org/galleries/
               ~\.google\.;

if ($invalid_referer) {
    return 403;
}
```

<a id="directives-38"></a>

## 指令

<a id="index-0"></a>

<a id="referer-hash-bucket-size"></a>

### referer_hash_bucket_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `referer_hash_bucket_size` size;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `referer_hash_bucket_size 64;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server, location                   |

设置有效引用来源哈希表的桶大小。设置哈希表的详细信息在单独的 [文档](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes) 中提供。

<a id="index-1"></a>

<a id="referer-hash-max-size"></a>

### referer_hash_max_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `referer_hash_max_size` size;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `referer_hash_max_size 2048;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server, location                |

设置有效引用来源哈希表的最大大小。设置哈希表的详细信息在单独的 [文档](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes) 中提供。

<a id="index-2"></a>

<a id="valid-referers"></a>

### valid_referers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `valid_referers` `none` | `blocked` | `server_names` | string ...;   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server, location                                                     |

指定将导致内置变量 [$invalid_referer](#v-invalid-referer) 被设置为空字符串的 `Referer` 请求头字段值。否则，该变量将被设置为 "1"。匹配搜索不区分大小写。

参数可以如下：

| `none`         | 请求头中缺少 `Referer` 字段；                                                       |
|----------------|----------------------------------------------------------------------------|
| `blocked`      | 请求头中存在 `Referer` 字段，但其值已被防火墙或代理服务器删除；此类值是不以 `http://` 或 `https://` 开头的字符串； |
| `server_names` | `Referer` 请求头字段包含其中一个服务器名称；                                                |
| `任意字符串`        | 定义服务器名称和可选的 URI 前缀。服务器名称的开头或结尾可以有一个 "\*"。在检查期间，`Referer` 字段中的服务器端口将被忽略；    |
| `正则表达式`        | 第一个符号应该是 "~"。需要注意的是，表达式将与 `http://` 或 `https://` 之后开始的文本进行匹配。              |

示例：

```nginx
valid_referers none blocked server_names
               *.example.com example.* www.example.org/galleries/
               ~\.google\.;
```

<a id="built-in-variables-8"></a>

## 内置变量

<a id="v-invalid-referer"></a>

### `$invalid_referer`

如果 `Referer` 请求头字段值被认为是 [有效的](#valid-referers)，则为空字符串，否则为 "1"。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_rewrite.md

<!-- review: finished -->

<a id="http-rewrite"></a>

# Rewrite

该模块用于使用 PCRE 正则表达式更改请求 URI,返回重定向,以及有条件地选择配置。

[break](#break)、[if](#if)、[return](#return)、[rewrite](#id5) 和 [set](#set) 指令按以下顺序处理:

* 在 server 级别指定的该模块指令按顺序执行;
* 重复执行:
  > * 根据请求 URI 搜索 location;
  > * 在找到的 location 内指定的该模块指令按顺序执行;
  > * 如果请求 URI 被 [重写](#id5),则重复循环,但 [不超过](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#internal) 10 次。

<a id="directives-39"></a>

## 指令

<a id="index-0"></a>

<a id="break"></a>

### break

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `break`;           |
|--------------------------------------------------------------------------------------|--------------------|
| 默认值                                                                                  | —                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server、location、if |

停止处理当前的 http_rewrite 模块指令集。

如果指令在 location 内指定,则请求的进一步处理将在此 location 中继续。

示例:

```nginx
if ($slow) {
    limit_rate 10k;
    break;
}
```

<a id="index-1"></a>

<a id="if"></a>

### if

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `if` (condition) { ... }   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | —                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server、location            |

对指定的条件进行求值。如果为真,则执行大括号内指定的该模块指令,并将 if 指令内的配置分配给请求。if 指令内的配置从上一级配置继承。

#### WARNING
虽然可以在 if 块内使用其他模块的指令,
但不建议这样做,
因为这可能导致意外行为。

条件可以是以下任意一种:

* 变量名;如果变量的值为空字符串或 "0",则为假;
* 使用 "=" 和 "!=" 运算符将变量与字符串进行比较;
* 使用 "~"(区分大小写匹配)和 "~\*"(不区分大小写匹配)运算符将变量与正则表达式进行匹配。正则表达式可以包含捕获,这些捕获可在 $1..$9 变量中供后续重用。还可以使用否定运算符 "!~" 和 "!~\*"。如果正则表达式包含 "}" 或 ";" 字符,则整个表达式应该用单引号或双引号括起来。
* 使用 "-f" 和 "!-f" 运算符检查文件是否存在;
* 使用 "-d" 和 "!-d" 运算符检查目录是否存在;
* 使用 "-e" 和 "!-e" 运算符检查文件、目录或符号链接是否存在;
* 使用 "-x" 和 "!-x" 运算符检查可执行文件。

示例:

```nginx
if ($http_user_agent ~ MSIE) {
    rewrite ^(.*)$ /msie/$1 break;
}

if ($http_cookie ~* "id=([^;]+)(?:;|$)") {
    set $id $1;
}

if ($request_method = POST) {
    return 405;
}

if ($slow) {
    limit_rate 10k;
}

if ($invalid_referer) {
    return 403;
}
```

#### NOTE
[$invalid_referer](https://cn.angie.software//angie/docs/configuration/modules/http/http_referer.md#v-invalid-referer) 内置变量的值由 [valid_referers](https://cn.angie.software//angie/docs/configuration/modules/http/http_referer.md#valid-referers) 指令设置。

<a id="index-2"></a>

<a id="return"></a>

### return

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `return` code [text];<br/><br/>`return` code URL;<br/><br/>`return` URL;   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server、location、if                                                         |

停止处理并向客户端返回指定的 `code`。非标准代码 444 会在不发送响应头的情况下关闭连接。

可以指定重定向 URL(用于代码 301、302、303、307 和 308)或响应正文文本(用于其他代码)。响应正文文本和重定向 URL 可以包含变量。作为特殊情况,重定向 URL 可以指定为此服务器的本地 URI,在这种情况下,完整的重定向 URL 将根据请求方案($scheme)以及 [server_name_in_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name-in-redirect) 和 [port_in_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#port-in-redirect) 指令形成。

此外,代码为 302 的临时重定向 URL 可以指定为唯一参数。此类参数应以 `http://`、`https://` 或 "$scheme" 字符串开头。URL 可以包含变量。

另请参阅 [error_page](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#error-page) 指令。

<a id="index-3"></a>

<a id="rewrite"></a>

### rewrite

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `rewrite` regex replacement [flag];   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | —                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server、location、if                    |

如果指定的正则表达式与请求 URI 匹配,则 URI 将按 `replacement` 字符串中指定的方式更改。rewrite 指令按其在配置文件中出现的顺序依次执行。可以使用 `flags` 终止指令的进一步处理。如果 `replacement` 字符串以 `http://`、`https://` 或 "$scheme" 开头,则处理停止并将重定向返回给客户端。

可选的 `flag` 参数可以是以下之一:

| `last`      | 停止处理当前的 http_rewrite 模块指令集,并开始搜索与更改后的 URI 匹配的新 location;                       |
|-------------|--------------------------------------------------------------------------------|
| `break`     | 停止处理当前的 http_rewrite 模块指令集,与 break 指令相同;                                       |
| `redirect`  | 返回代码为 302 的临时重定向;当 `replacement` 字符串不以 `http://`、`https://` 或 "$scheme" 开头时使用; |
| `permanent` | 返回代码为 301 的永久重定向。                                                              |

完整的重定向 URL 根据请求方案($scheme)以及 [server_name_in_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name-in-redirect) 和 [port_in_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#port-in-redirect) 指令形成。

示例:

```nginx
server {
#    ...
    rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 last;
    rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra  last;
    return  403;
#    ...
}
```

但如果这些指令放在 "/download/" location 内,则应将 `last` 标志替换为 `break`,否则 Angie 将进行 10 次循环并返回 500 错误:

```nginx
location /download/ {
    rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
    rewrite ^(/download/.*)/audio/(.*)\..*$ $1/mp3/$2.ra  break;
    return  403;
}
```

如果 `replacement` 字符串包含新的请求参数,则先前的请求参数将附加在它们之后。如果不希望这样,在替换字符串末尾放置一个问号可以避免附加它们,例如:

```nginx
rewrite ^/users/(.*)$ /show?user=$1? last;
```

如果正则表达式包含 "}" 或 ";" 字符,则整个表达式应该用单引号或双引号括起来。

<a id="index-4"></a>

<a id="rewrite-log"></a>

### rewrite_log

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `rewrite_log` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `rewrite_log off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http、server、location、if       |

启用或禁用将 http_rewrite 模块指令处理结果以 notice 级别记录到 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 中。

<a id="index-5"></a>

<a id="set"></a>

### set

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `set` $variable value;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | —                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server、location、if       |

为指定的变量设置值。该值可以包含文本、变量及其组合。

<a id="index-6"></a>

<a id="uninitialized-variable-warn"></a>

### uninitialized_variable_warn

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uninitialized_variable_warn` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | `uninitialized_variable_warn on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http、server、location、if                       |

控制是否记录有关未初始化变量的警告。

<a id="internal-implementation"></a>

## 内部实现

http_rewrite 模块指令在配置阶段被编译为内部指令,这些指令在请求处理期间被解释执行。解释器是一个简单的虚拟栈机器。

例如,指令

```nginx
location /download/ {
    if ($forbidden) {
        return 403;
    }

    if ($slow) {
        limit_rate 10k;
    }

    rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break;
}
```

将被转换为这些指令:

```console
variable $forbidden
check for zero
    return 403
    end of code
variable $slow
check for zero
match of regular expression
copy "/"
copy $1
copy "/mp3/"
copy $2
copy ".mp3"
end of regular expression
end of code
```

请注意,没有 [limit_rate](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#limit-rate) 指令的指令,因为它与 `http_rewrite` 模块无关。为 `if` 块创建了单独的配置。如果条件为真,请求将获得此配置,其中 `limit_rate` 等于 10k。

指令

```nginx
rewrite ^/(download/.*)/media/(.*)\..*$ /$1/mp3/$2.mp3 break;
```

如果将正则表达式中的第一个斜杠移到括号内,可以减少一条指令:

```nginx
rewrite ^(/download/.*)/media/(.*)\..*$ $1/mp3/$2.mp3 break;
```

相应的指令将如下所示:

```console
match of regular expression
copy $1
copy "/mp3/"
copy $2
copy ".mp3"
end of regular expression
end of code
```


# https://cn.angie.software/angie/docs/configuration/modules/http/http_scgi.md

<!-- review: finished -->

<a id="http-scgi"></a>

# SCGI

允许将请求传递给 SCGI 服务器。

<a id="configuration-example-38"></a>

## 配置示例

```nginx
location / {
    include   scgi_params;
    scgi_pass localhost:9000;
}
```

<a id="directives-40"></a>

## 指令

<a id="index-0"></a>

<a id="scgi-bind"></a>

### scgi_bind

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_bind` address [`transparent`] | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | —                                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                         |

使到 SCGI 服务器的出站连接源自指定的本地 IP 地址和可选端口。参数值可以包含变量。特殊值 `off` 取消从上一配置级别继承的 scgi_bind 指令的效果,允许系统自动分配本地 IP 地址和端口。

`transparent` 参数允许到 SCGI 服务器的出站连接源自非本地 IP 地址,例如来自客户端的真实 IP 地址:

```nginx
scgi_bind $remote_addr transparent;
```

为了使此参数生效,通常需要以 [超级用户](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 权限运行 Angie 工作进程。在 Linux 上不需要这样做,因为如果指定了 `transparent` 参数,工作进程会从主进程继承 CAP_NET_RAW 能力。

#### NOTE
需要配置内核路由表以拦截来自 SCGI 服务器的网络流量。

<a id="index-1"></a>

<a id="scgi-buffer-size"></a>

### scgi_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_buffer_size` size;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `scgi_buffer_size 4k|8k;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

设置用于读取从 SCGI 服务器接收的响应的第一部分的缓冲区大小。这部分通常包含一个小的响应头。默认情况下,缓冲区大小等于一个内存页。根据平台不同,这可能是 4K 或 8K。但可以设置得更小。

<a id="index-2"></a>

<a id="scgi-buffering"></a>

### scgi_buffering

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_buffering` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `scgi_buffering on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

启用或禁用来自 SCGI 服务器的响应的缓冲。

| `on`   | Angie 尽快从 SCGI 服务器接收响应,将其保存到由 [scgi_buffer_size](#scgi-buffer-size) 和 [scgi_buffers](#scgi-buffers) 指令设置的缓冲区中。向客户端发送会并行进行: 已填满的缓冲区会被传递用于发送,但总量不超过 [scgi_busy_buffers_size](#scgi-busy-buffers-size)。如果缓冲区未被完全填满,则不会被传递用于发送,除非这是响应的最后一部分。因此,当需要即时传输每隔几个字节时,缓冲读取模式并不适合。如果整个响应无法放入内存,可以将其中一部分保存到磁盘上的 [临时文件](#scgi-temp-path) 中。写入临时文件由 [scgi_max_temp_file_size](#scgi-max-temp-file-size) 和 [scgi_temp_file_write_size](#scgi-temp-file-write-size) 指令控制。   |
|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 响应在接收到时立即传递给客户端。Angie 以"读取 — 发送"的循环工作,不会等待缓冲区被填满: 例如从 4K 缓冲区读取到 10 字节时就会立即发送。同时,如果整个响应可以放入缓冲区,Angie 也可能一次读完。Angie 一次可以从服务器接收的最大数据量由 [scgi_buffer_size](#scgi-buffer-size) 指令设置。使用 `off` 时,:ref:scgi_limit_rate 不生效。                                                                                                                                                                                                                                       |

也可以通过在 `X-Accel-Buffering` 响应头字段中传递 "yes" 或 "no" 来启用或禁用缓冲。可以使用 [scgi_ignore_headers](#scgi-ignore-headers) 指令禁用此功能。

<a id="index-3"></a>

<a id="scgi-buffers"></a>

### scgi_buffers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_buffers` number size;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `scgi_buffers 8 4k | 8k;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

设置用于从 SCGI 服务器读取响应的缓冲区的数量和大小,针对单个连接。

默认情况下,缓冲区大小等于一个内存页。根据平台不同,这可能是 4K 或 8K。

<a id="index-4"></a>

<a id="scgi-busy-buffers-size"></a>

### scgi_busy_buffers_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_busy_buffers_size` size;     |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `scgi_busy_buffers_size 8k | 16k;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

当启用来自 SCGI 服务器的响应的 [缓冲](#scgi-buffering) 时,限制在响应尚未完全读取时可以忙于向客户端发送响应的缓冲区的总大小。同时,其余缓冲区可用于读取响应,如果需要,还可以将部分响应缓冲到临时文件中。

默认情况下,大小受 [scgi_buffer_size](#scgi-buffer-size) 和 [scgi_buffers](#scgi-buffers) 指令设置的两个缓冲区大小的限制。

<a id="index-5"></a>

<a id="scgi-cache"></a>

### scgi_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache` zone | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `scgi_cache off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

定义用于缓存的共享内存区域。同一区域可以在多个地方使用。参数值可以包含变量。

| `off`   | 禁用从上一配置级别继承的缓存。   |
|---------|-------------------|

<a id="index-6"></a>

<a id="scgi-cache-background-update"></a>

### scgi_cache_background_update

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_background_update` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | `scgi_cache_background_update off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                         |

允许启动后台子请求来更新过期的缓存项,同时将陈旧的缓存响应返回给客户端。

#### WARNING
注意,必须 [允许](#scgi-cache-use-stale-updating) 在更新时使用陈旧的缓存响应。

<a id="index-7"></a>

<a id="scgi-cache-bypass"></a>

### scgi_cache_bypass

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_bypass` string ...;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

定义不从缓存中获取响应的条件。如果字符串参数中至少有一个值不为空且不等于 "0",则不会从缓存中获取响应:

```nginx
scgi_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
scgi_cache_bypass $http_pragma    $http_authorization;
```

可以与 [scgi_no_cache](#scgi-no-cache) 指令一起使用。

<a id="index-8"></a>

<a id="scgi-cache-key"></a>

### scgi_cache_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_key` string;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | —                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

定义缓存的键,例如

```nginx
scgi_cache_key localhost:9000$request_uri;
```

<a id="index-9"></a>

<a id="scgi-cache-lock"></a>

### scgi_cache_lock

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_lock` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `scgi_cache_lock off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

启用后,一次只允许一个请求通过将请求传递给 SCGI 服务器来填充根据 [scgi_cache_key](#scgi-cache-key) 指令标识的新缓存元素。同一缓存元素的其他请求将等待响应出现在缓存中或此元素的缓存锁被释放,最长等待时间由 [scgi_cache_lock_timeout](#scgi-cache-lock-timeout) 指令设置。

<a id="index-10"></a>

<a id="scgi-cache-lock-age"></a>

### scgi_cache_lock_age

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_lock_age` time;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `scgi_cache_lock_age 5s;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

如果传递给 SCGI 服务器以填充新缓存元素的最后一个请求在指定时间内未完成,则可以再传递一个请求给 SCGI 服务器。

<a id="index-11"></a>

<a id="scgi-cache-lock-timeout"></a>

### scgi_cache_lock_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_lock_timeout` time;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `scgi_cache_lock_timeout 5s;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

设置 [scgi_cache_lock](#scgi-cache-lock) 的超时时间。当时间到期时,请求将被传递给 SCGI 服务器,但响应不会被缓存。

<a id="index-12"></a>

<a id="scgi-cache-max-range-offset"></a>

### scgi_cache_max_range_offset

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_max_range_offset` number;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | —                                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

为字节范围请求设置偏移量(以字节为单位)。如果范围超出偏移量,范围请求将被传递给 SCGI 服务器,并且响应不会被缓存。

<a id="index-13"></a>

<a id="scgi-cache-methods"></a>

### scgi_cache_methods

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_methods` `GET` | `HEAD` | `POST` ...;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------|
| 默认值                                                                                  | `scgi_cache_methods GET HEAD;`                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                              |

如果客户端请求方法在此指令中列出,则响应将被缓存。"GET" 和 "HEAD" 方法始终会被添加到列表中,但建议显式指定它们。另请参阅 [scgi_no_cache](#scgi-no-cache) 指令。

<a id="index-14"></a>

<a id="scgi-cache-min-uses"></a>

### scgi_cache_min_uses

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_min_uses` number;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `scgi_cache_min_uses 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

设置在多少次请求后响应将被缓存。

#### WARNING
缓存元数据存储在共享内存中。手动删除缓存文件不会重置计数器，可能导致不可预测的行为。要完全重置缓存，请停止服务器，删除缓存目录，然后重新启动。

#### NOTE
第三方缓存清除模块（例如 [缓存清除](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge)）仅删除文件，但不会重置 scgi_cache_min_uses 计数器。该指令旨在保护缓存免受不频繁请求的污染，在清除期间重置计数器可能会对性能产生负面影响。

<a id="index-15"></a>

<a id="scgi-cache-path"></a>

### scgi_cache_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_path` path [`levels=`levels] [`use_temp_path=``on` | `off`] `keys_zone=`name:size [`inactive=`time] [`max_size=`size] [`min_free=`size] [`manager_files=`number] [`manager_sleep=`time] [`manager_threshold=`time] [`loader_files=`number] [`loader_sleep=`time] [`loader_threshold=`time];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                                                                                                                                                                                                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                                                                                                                                                                                                                                                                                      |

设置缓存的路径和其他参数。缓存数据存储在文件中。缓存中的文件名是对 [缓存键](#scgi-cache-key) 应用 MD5 函数的结果。

`levels` 参数定义缓存的层次结构级别：从 1 到 3，每个级别接受值 1 或 2。例如，在以下配置中：

```nginx
scgi_cache_path /data/angie/cache levels=1:2 keys_zone=one:10m;
```

缓存中的文件名将如下所示：

```nginx
/data/angie/cache/c/29/b7f54b2df7773722d382f4809d65029c
```

缓存的响应首先写入临时文件，然后重命名该文件。临时文件和缓存可以放在不同的文件系统上。但是，请注意，在这种情况下，文件将在两个文件系统之间复制，而不是廉价的重命名操作。因此，建议对于任何给定位置，缓存和保存临时文件的目录都放在同一文件系统上。

临时文件的目录根据 `use_temp_path` 参数设置。

| `on`   | 如果省略此参数或将其设置为值 on，则将使用由给定位置的 [scgi_temp_path](#scgi-temp-path) 指令设置的目录。   |
|--------|---------------------------------------------------------------------------|
| `off`  | 临时文件将直接放在缓存目录中。                                                           |

此外，所有活动键和有关数据的信息都存储在共享内存区域中，其名称和大小由 `keys_zone` 参数配置。一兆字节的区域可以存储大约 8 千个键。缓存元数据存储在共享内存中。

在 `inactive` 参数指定的时间内未被访问的缓存数据将从缓存中删除，无论其新鲜度如何。

默认情况下，`inactive` 设置为 10 分钟。

特殊的\*\*缓存管理器\*\*进程监控最大缓存大小和缓存所在文件系统的最小可用空间量，当超出大小或可用空间不足时，它会删除最近最少使用的数据。数据以迭代方式删除。

| `max_size`          | 最大缓存大小                               |
|---------------------|--------------------------------------|
| `min_free`          | 缓存所在文件系统的最小可用空间量                     |
| `manager_files`     | 限制一次迭代期间要删除的项目数<br/><br/>默认情况下，`100` |
| `manager_threshold` | 限制一次迭代的持续时间<br/><br/>默认情况下，`200` 毫秒  |
| `manager_sleep`     | 配置迭代之间的暂停<br/><br/>默认情况下，`50` 毫秒     |

Angie 启动一分钟后，特殊的\*\*缓存加载器\*\*进程被激活。它将存储在文件系统上的先前缓存数据的信息加载到缓存区域中。加载也以迭代方式完成。

| `loader_files`     | 限制一次迭代期间要加载的项目数<br/><br/>默认情况下，`100`   |
|--------------------|----------------------------------------|
| `loader_threshold` | 限制一次迭代的持续时间<br/><br/>默认情况下，`200` 毫秒    |
| `loader_sleep`     | 配置迭代之间的暂停<br/><br/>默认情况下，`50` 毫秒       |

<a id="index-16"></a>

<a id="scgi-cache-revalidate"></a>

### scgi_cache_revalidate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_revalidate` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `scgi_cache_revalidate off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

启用使用带有 `If-Modified-Since` 和 `If-None-Match` 头字段的条件请求重新验证过期的缓存项。

<a id="index-17"></a>

<a id="scgi-cache-use-stale"></a>

### scgi_cache_use_stale

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_use_stale` `error` | `timeout` | `invalid_header` | `updating` | `http_500` | `http_503` | `http_403` | `http_404` | `http_429` | `off` ...;   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `scgi_cache_use_stale off;`                                                                                                                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                                     |

确定在哪些情况下可以使用过期的缓存响应。该指令的参数与 [scgi_next_upstream](#scgi-next-upstream) 指令的参数匹配。

| `error`    | 如果无法选择 SCGI 服务器来处理请求，则允许使用过期的缓存响应。                            |
|------------|---------------------------------------------------------------|
| `updating` | 附加参数，如果当前正在更新过期的缓存响应，则允许使用它。这可以最大限度地减少更新缓存数据时对 SCGI 服务器的访问次数。 |

也可以在响应头中直接启用使用过期的缓存响应，在响应变为过期后的指定秒数内：

* `Cache-Control` 头字段的 [stale-while-revalidate](https://datatracker.ietf.org/doc/html/rfc5861#section-3) 扩展允许在当前正在更新过期的缓存响应时使用它。
* `Cache-Control` 头字段的 [stale-if-error](https://datatracker.ietf.org/doc/html/rfc5861#section-4) 扩展允许在发生错误时使用过期的缓存响应。

#### NOTE
此方法的优先级低于使用指令设置参数。

要在填充新缓存元素时最大限度地减少对 SCGI 服务器的访问次数，可以使用 [scgi_cache_lock](#scgi-cache-lock) 指令。

<a id="index-18"></a>

<a id="scgi-cache-valid"></a>

### scgi_cache_valid

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_cache_valid` [code ...] time;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | —                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

为不同的响应代码设置缓存时间。例如，以下指令

```nginx
scgi_cache_valid 200 302 10m;
scgi_cache_valid 404      1m;
```

为代码 200 和 302 的响应设置 10 分钟的缓存，为代码 404 的响应设置 1 分钟的缓存。

如果仅指定缓存时间，

```nginx
scgi_cache_valid 5m;
```

则仅缓存 200、301 和 302 响应。

此外，可以使用 `any` 参数指定缓存任何响应：

```nginx
scgi_cache_valid 200 302 10m;
scgi_cache_valid 301      1h;
scgi_cache_valid any      1m;
```

#### NOTE
缓存参数也可以直接在响应头中设置。这比使用指令设置缓存时间具有更高的优先级。

* `X-Accel-Expires` 头字段以秒为单位设置响应的缓存时间。零值将禁用响应的缓存。如果值以 @ 前缀开头，则设置自 Epoch 以来的绝对时间（以秒为单位），响应可以缓存到该时间。
* 如果头不包含 `X-Accel-Expires` 字段，则可以在头字段 `Expires` 或 `Cache-Control` 中设置缓存参数。
* 如果头包含 `Set-Cookie` 字段，则此类响应将不会被缓存。
* 如果头包含特殊值 "\*" 的 `Vary` 字段，则此类响应将不会被缓存。如果头包含其他值的 `Vary` 字段，则此类响应将根据相应的请求头字段进行缓存。

可以使用 [scgi_ignore_headers](#scgi-ignore-headers) 指令禁用对这些响应头字段中的一个或多个的处理。

<a id="index-19"></a>

<a id="scgi-connect-timeout"></a>

### scgi_connect_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_connect_timeout` time;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `scgi_connect_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

定义与 SCGI 服务器建立连接的超时时间。需要注意的是，此超时时间通常不能超过 75 秒。

<a id="index-20"></a>

<a id="scgi-connection-drop"></a>

### scgi_connection_drop

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_connection_drop` time | `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | `scgi_connection_drop off;`                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                        |

启用在代理服务器从组中移除或被 [reresolve](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve) 进程或 [API 命令](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config-methods) `DELETE` 标记为永久不可用后，终止到该服务器的所有连接。

当为客户端或代理服务器处理下一个读取或写入事件时，连接将被终止。

设置 time 启用连接终止 [超时](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)；设置为 `on` 时，连接将立即断开。

<a id="index-21"></a>

<a id="scgi-force-ranges"></a>

### scgi_force_ranges

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_force_ranges` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `scgi_force_ranges off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

无论 SCGI 服务器响应中的 `Accept-Ranges` 字段如何，都为来自 SCGI 服务器的缓存和非缓存响应启用字节范围支持。

<a id="index-22"></a>

<a id="scgi-hide-header"></a>

### scgi_hide_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_hide_header` field;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

默认情况下，Angie 不会将 SCGI 服务器响应中的头字段 `Status` 和 `X-Accel-...` 传递给客户端。`scgi_hide_header` 指令设置不会被传递的其他字段。相反，如果需要允许传递字段，可以使用 [scgi_pass_header](#scgi-pass-header) 指令。

<a id="index-23"></a>

<a id="scgi-ignore-client-abort"></a>

### scgi_ignore_client_abort

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_ignore_client_abort` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | `scgi_ignore_client_abort off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                     |

确定当客户端在未等待响应的情况下关闭连接时,是否应关闭与 SCGI 服务器的连接。

<a id="index-24"></a>

<a id="scgi-ignore-headers"></a>

### scgi_ignore_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_ignore_headers` field ...;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | —                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

禁用对来自 SCGI 服务器的某些响应头字段的处理。可以忽略以下字段:`X-Accel-Redirect`、`X-Accel-Expires`、`X-Accel-Limit-Rate`、`X-Accel-Buffering`、`X-Accel-Charset`、`Expires`、`Cache-Control`、`Set-Cookie` 和 `Vary`。

如果未禁用,处理这些头字段将产生以下效果:

* `X-Accel-Expires`、`Expires`、`Cache-Control`、`Set-Cookie` 和 `Vary` 设置响应 [缓存](#scgi-cache-valid) 的参数;
* `X-Accel-Redirect` 执行到指定 URI 的 [内部重定向](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#internal);
* `X-Accel-Limit-Rate` 设置向客户端传输响应的 [速率限制](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#limit-rate);
* `X-Accel-Buffering` 启用或禁用响应的 [缓冲](#scgi-buffering);
* `X-Accel-Charset` 设置响应所需的 [字符集](https://cn.angie.software//angie/docs/configuration/modules/http/http_charset.md#id3)。

<a id="index-25"></a>

<a id="scgi-intercept-errors"></a>

### scgi_intercept_errors

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_intercept_errors` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `scgi_intercept_errors off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

确定代码大于或等于 300 的 SCGI 服务器响应应传递给客户端,还是被拦截并重定向到 Angie 以使用 [error_page](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#error-page) 指令进行处理。

<a id="index-26"></a>

<a id="scgi-limit-rate"></a>

### scgi_limit_rate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_limit_rate` rate;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `scgi_limit_rate 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location    |

限制从 SCGI 服务器读取响应的速度。
rate 以每秒字节数指定;可以使用变量。

| `0`   | 禁用速率限制   |
|-------|----------|

#### NOTE
限制是针对每个请求设置的,因此如果 Angie 同时打开两个到 SCGI 服务器的连接,则总速率将是指定限制的两倍。该限制仅在启用来自 SCGI 服务器的响应 [缓冲](#scgi-buffering) 时有效。

<a id="index-27"></a>

<a id="scgi-max-temp-file-size"></a>

### scgi_max_temp_file_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_max_temp_file_size` size;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `scgi_max_temp_file_size 1024m;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

当启用来自 SCGI 服务器的响应 [缓冲](#scgi-buffering) 时,如果整个响应不适合 [scgi_buffer_size](#scgi-buffer-size) 和 [scgi_buffers](#scgi-buffers) 指令设置的缓冲区,则响应的一部分可以保存到临时文件中。此指令设置临时文件的最大大小。一次写入临时文件的数据大小由 [scgi_temp_file_write_size](#scgi-temp-file-write-size) 指令设置。

| `0`   | 禁用将响应缓冲到临时文件   |
|-------|----------------|

#### NOTE
此限制不适用于将被 [缓存](#scgi-cache) 或 [存储](#scgi-store) 到磁盘的响应。

<a id="index-28"></a>

<a id="scgi-next-upstream"></a>

### scgi_next_upstream

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_next_upstream` `error` | `timeout` | `invalid_header` | `http_500` | `http_503` | `http_403` | `http_404` | `http_429` | `non_idempotent` | `off` ...;   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `scgi_next_upstream error timeout;`                                                                                                                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                                         |

指定在哪些情况下应将请求传递到下一个服务器:

| `error`          | 与服务器建立连接、向其传递请求或读取响应头时发生错误;                                                                                                                            |
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|
| `timeout`        | 与服务器建立连接、向其传递请求或读取响应头时发生超时;                                                                                                                            |
| `invalid_header` | 服务器返回空响应或无效响应;                                                                                                                                         |
| `http_500`       | 服务器返回代码为 500 的响应;                                                                                                                                      |
| `http_503`       | 服务器返回代码为 503 的响应;                                                                                                                                      |
| `http_403`       | 服务器返回代码为 403 的响应;                                                                                                                                      |
| `http_404`       | 服务器返回代码为 404 的响应;                                                                                                                                      |
| `http_429`       | 服务器返回代码为 429 的响应;                                                                                                                                      |
| `non_idempotent` | 通常,使用 [非幂等](https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.2) 方法<br/>(`POST`、`LOCK`、`PATCH`) 的请求如果已经发送到上游服务器,则不会传递到下一个服务器;启用此选项将明确允许重试此类请求; |
| `off`            | 禁用将请求传递到下一个服务器。                                                                                                                                        |

#### NOTE
需要注意的是,只有在尚未向客户端发送任何内容时,才可能将请求传递到下一个服务器。也就是说,如果在传输响应的过程中发生错误或超时,则无法修复此问题。

该指令还定义了什么被视为与服务器通信的 [不成功尝试](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#max-fails)。

| `error`<br/><br/>`timeout`<br/><br/>`invalid_header`   | 始终被视为不成功尝试,即使未在指令中指定   |
|--------------------------------------------------------|------------------------|
| `http_500`<br/><br/>`http_503`<br/><br/>`http_429`     | 仅在指令中指定时才被视为不成功尝试      |
| `http_403`<br/><br/>`http_404`                         | 永远不会被视为不成功尝试           |

将请求传递到下一个服务器可以通过 [尝试次数](#scgi-next-upstream-tries) 和 [时间](#scgi-next-upstream-timeout) 进行限制。

<a id="index-29"></a>

<a id="scgi-next-upstream-timeout"></a>

### scgi_next_upstream_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_next_upstream_timeout` time;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `scgi_next_upstream_timeout 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

限制可以将请求传递到 [下一个](#scgi-next-upstream) 服务器的时间。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-30"></a>

<a id="scgi-next-upstream-tries"></a>

### scgi_next_upstream_tries

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_next_upstream_tries` number;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `scgi_next_upstream_tries 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

限制将请求传递到 [下一个](#scgi-next-upstream) 服务器的可能尝试次数。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-31"></a>

<a id="scgi-no-cache"></a>

### scgi_no_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_no_cache` string ...;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | —                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

定义响应不会保存到缓存的条件。如果字符串参数中至少有一个值不为空且不等于 "0",则响应将不会被保存:

```nginx
scgi_no_cache $cookie_nocache $arg_nocache$arg_comment;
scgi_no_cache $http_pragma    $http_authorization;
```

可以与 [scgi_cache_bypass](#scgi-cache-bypass) 指令一起使用。

<a id="index-32"></a>

<a id="scgi-param"></a>

### scgi_param

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_param` parameter value [`if_not_empty`];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------|
| 默认值                                                                                  | —                                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                           |

设置应传递给 SCGI 服务器的参数。值可以包含文本、变量及其组合。当且仅当当前级别上没有定义 scgi_param 指令时,这些指令才会从上一级配置继承。

标准 [CGI 环境变量](https://datatracker.ietf.org/doc/html/rfc3875#section-4.1) 应作为 SCGI 头提供,请参阅发行版中提供的 scgi_params 文件:

```nginx
location / {
    include scgi_params;
#    ...
}
```

在标准 `scgi_params` 文件中,:samp:REQUEST_METHOD 设置为
`$upstream_request_method`。

如果指令使用 `if_not_empty` 指定,则仅当参数值不为空时才会将其传递给服务器:

```nginx
scgi_param HTTPS $https if_not_empty;
```

<a id="index-33"></a>

<a id="scgi-pass"></a>

### scgi_pass

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_pass` uri;         |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | —                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location, if in location |

设置 SCGI 服务器的地址。地址可以指定为域名或 IP 地址,以及可选的端口:

```nginx
scgi_pass localhost:9000;
```

或作为 UNIX 域套接字路径:

```nginx
scgi_pass unix:/tmp/scgi.socket;
```

如果域名解析为多个地址,则所有地址都将以轮询方式使用。此外,地址可以指定为 [服务器组](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream)。

参数值可以包含变量。在这种情况下,如果地址指定为域名,则在描述的服务器组中搜索该名称,如果未找到,则使用 [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 确定。

#### NOTE
如果在前缀带有尾部斜杠的 `location` 中指定了 `scgi_pass`
(例如 `location /name/`),
并且 [auto_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#auto-redirect) 指令设置为 `default`,
则不带尾部斜杠的请求将被重定向 (`/name -> /name/`)。

<a id="index-34"></a>

<a id="scgi-pass-header"></a>

### scgi_pass_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_pass_header` field ...;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | —                               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

允许将 [原本被禁用的](#scgi-hide-header) 头字段从 SCGI 服务器传递给客户端。

<a id="index-35"></a>

<a id="scgi-pass-request-body"></a>

### scgi_pass_request_body

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_pass_request_body` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `scgi_pass_request_body on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

指示是否将原始请求体传递给 SCGI 服务器。另请参阅 [scgi_pass_request_headers](#scgi-pass-request-headers) 指令。

<a id="index-36"></a>

<a id="scgi-pass-request-headers"></a>

### scgi_pass_request_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_pass_request_headers` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `scgi_pass_request_headers on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

指示是否将原始请求的头字段传递给 SCGI 服务器。另请参阅 [scgi_pass_request_body](#scgi-pass-request-body) 指令。

<a id="index-37"></a>

<a id="scgi-read-timeout"></a>

### scgi_read_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_read_timeout` time;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `scgi_read_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

定义从 SCGI 服务器读取响应的超时时间。超时仅在两次连续的读操作之间设置,而不是用于整个响应的传输。如果 SCGI 服务器在此时间内未传输任何内容,则连接将被关闭。

<a id="index-38"></a>

<a id="scgi-request-buffering"></a>

### scgi_request_buffering

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_request_buffering` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `scgi_request_buffering on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

启用或禁用客户端请求体的缓冲。

| `on`   | 在将请求发送到 SCGI 服务器之前,从客户端完整 [读取](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-body-buffer-size) 请求体。   |
|--------|------------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 请求体在接收时立即发送到 SCGI 服务器。在这种情况下,如果 Angie 已经开始发送请求体,则无法将请求传递到 [下一个服务器](#scgi-next-upstream)。                                                 |

当使用 HTTP/1.1 分块传输编码发送原始请求体时,无论指令值如何,请求体都将被缓冲。

<a id="index-39"></a>

<a id="scgi-send-timeout"></a>

### scgi_send_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_send_timeout` time;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `scgi_send_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

设置向 SCGI 服务器传输请求的超时时间。超时仅在两次连续的写操作之间设置,而不是用于整个请求的传输。如果 SCGI 服务器在此时间内未接收到任何内容,则连接将被关闭。

<a id="index-40"></a>

<a id="scgi-socket-keepalive"></a>

### scgi_socket_keepalive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_socket_keepalive` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `scgi_socket_keepalive off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

配置到 SCGI 服务器的出站连接的 "TCP keepalive" 行为。

| `off`   | 默认情况下,套接字使用操作系统的设置。        |
|---------|----------------------------|
| `on`    | 为套接字启用 SO_KEEPALIVE 套接字选项。 |

<a id="index-41"></a>

<a id="scgi-store"></a>

### scgi_store

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_store` `on` | `off` | string;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `scgi_store off;`                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

启用将文件保存到磁盘。

| `on`   | 使用与 [alias](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#alias) 或 [root](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#root) 指令对应的路径保存文件   |
|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 禁用保存文件                                                                                                                                                                                              |

可以使用带变量的 string 显式设置文件名：

```nginx
scgi_store /data/www$original_uri;
```

文件的修改时间根据接收到的 `Last-Modified` 响应头字段设置。响应首先写入临时文件,然后重命名该文件。临时文件和持久存储可以放在不同的文件系统上。但是请注意,在这种情况下,文件将跨两个文件系统复制,而不是进行廉价的重命名操作。因此建议对于任何给定位置,保存的文件和由 [scgi_temp_path](#scgi-temp-path) 指令设置的临时文件目录都放在同一文件系统上。

此指令可用于创建静态不变文件的本地副本,例如：

```nginx
location /images/ {
    root              /data/www;
    error_page        404 = /fetch$uri;
}

location /fetch/ {
    internal;

    scgi_pass         backend:9000;
    ...

    scgi_store        on;
    scgi_store_access user:rw group:rw all:r;
    scgi_temp_path    /data/temp;

    alias             /data/www/;
}
```

<a id="index-42"></a>

<a id="scgi-store-access"></a>

### scgi_store_access

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_store_access` users:permissions ...;   |
|--------------------------------------------------------------------------------------|----------------------------------------------|
| 默认值                                                                                  | `scgi_store_access user:rw;`                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                       |

设置新创建的文件和目录的访问权限,例如：

```nginx
scgi_store_access user:rw group:rw all:r;
```

如果指定了任何 `group` 或 `all` 访问权限,则可以省略用户权限：

```nginx
scgi_store_access group:rw all:r;
```

<a id="index-43"></a>

<a id="scgi-temp-file-write-size"></a>

### scgi_temp_file_write_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_temp_file_write_size` size;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `scgi_temp_file_write_size 8k|16k;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

当启用将来自 SCGI 服务器的响应缓冲到临时文件时,限制一次写入临时文件的数据大小。默认情况下,大小受 [scgi_buffer_size](#scgi-buffer-size) 和 [scgi_buffers](#scgi-buffers) 指令设置的两个缓冲区限制。临时文件的最大大小由 [scgi_max_temp_file_size](#scgi-max-temp-file-size) 指令设置。

<a id="index-44"></a>

<a id="scgi-temp-path"></a>

### scgi_temp_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `scgi_temp_path` path [level1 [level2 [level3]]]\`;                                                                                             |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `scgi_temp_path scgi_temp;`<br/>(路径取决于 `--http-scgi-temp-path` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#paths)) |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                          |

定义用于存储从 SCGI 服务器接收的数据的临时文件的目录。在指定目录下最多可以使用三级子目录层次结构。例如,在以下配置中

```nginx
scgi_temp_path /spool/angie/scgi_temp 1 2;
```

临时文件可能如下所示：

```nginx
/spool/angie/scgi_temp/7/45/00000123457
```

另请参阅 [scgi_cache_path](#scgi-cache-path) 指令的 `use_temp_path` 参数。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_secure_link.md

<!-- review: finished -->

<a id="http-secure-link"></a>

# Secure Link

该模块用于检查请求链接的真实性，保护资源免受未经授权的访问，并限制链接的生命周期。

请求链接的真实性通过比较请求中传递的校验和值和为请求计算的值来验证。如果链接有有限的生命周期且时间已过期，则该链接被视为过时。这些检查的状态在 [$secure_link](#v-secure-link) 变量中可用。

该模块提供两种替代操作模式。第一种模式通过 [secure_link_secret](#secure-link-secret) 指令启用，用于检查请求链接的真实性以及保护资源免受未经授权的访问。第二种模式通过 [secure_link](#id2) 和 [secure_link_md5](#secure-link-md5) 指令启用，也用于限制链接的生命周期。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，此模块默认不构建；应使用 `--with-http_secure_link_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用。

在来自 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中，模块包含在构建中。

<a id="directives-41"></a>

## 指令

<a id="index-0"></a>

<a id="secure-link"></a>

### secure_link

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `secure_link` 表达式;     |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | —                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

定义一个包含变量的字符串，用于从中提取链接的校验和值和生命周期。

表达式中使用的变量通常与请求相关联；请参阅下面的 [示例](#secure-link-md5)。

从字符串中提取的校验和值与由 [secure_link_md5](#secure-link-md5) 指令定义的表达式的 MD5 哈希值进行比较。

如果校验和不匹配，则 [$secure_link](#v-secure-link) 变量被设置为空字符串。如果校验和匹配，则检查链接的生命周期。

如果链接有有限的生命周期且时间已过期，则 [$secure_link](#v-secure-link) 变量被设置为 `0`。否则，它被设置为 `1`。请求中传递的 MD5 哈希值以 base64url 编码。

如果链接有有限的生命周期，则过期时间以自纪元（1970年1月1日 00:00:00 GMT）以来的秒数设置。该值在表达式中指定于 MD5 哈希之后，并以逗号分隔。请求中传递的过期时间可通过 [$secure_link_expires](#v-secure-link-expires) 变量用于 [secure_link_md5](#secure-link-md5) 指令。如果未指定过期时间，则链接具有无限的生命周期。

<a id="index-1"></a>

<a id="secure-link-md5"></a>

### secure_link_md5

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `secure_link_md5` 表达式;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | —                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location   |

定义一个表达式，其 MD5 哈希值将被计算并与请求中传递的值进行比较。

表达式应包含链接（资源）的受保护部分和一个秘密成分。如果链接有有限的生命周期，表达式还应包含 [$secure_link_expires](#v-secure-link-expires)。

为了防止未经授权的访问，表达式可以包含一些关于客户端的信息，例如其地址和浏览器版本。

示例：

```nginx
location /s/ {
    secure_link $arg_md5,$arg_expires;
    secure_link_md5 "$secure_link_expires$uri$remote_addr secret";

    if ($secure_link = "") {
        return 403;
    }

    if ($secure_link = "0") {
        return 410;
    }

#    ...
}
```

链接 "/s/link?md5=_e4Nc3iduzkWRm01TBBNYw&expires=2147483647" 限制了对客户端 IP 地址为 127.0.0.1 的 "/s/link" 的访问。该链接也有限的生命周期，直到 2038 年 1 月 19 日（GMT）。

在 UNIX 上，可以通过以下命令获取 md5 请求参数值：

```console
echo -n '2147483647/s/link127.0.0.1 secret' | \
   openssl md5 -binary | openssl base64 | tr +/ -_ | tr -d =
```

<a id="index-2"></a>

<a id="secure-link-secret"></a>

### secure_link_secret

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `secure_link_secret` 单词;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | —                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location                   |

定义一个秘密单词，用于检查请求链接的真实性。

请求链接的完整 URI 如下所示：

```console
/prefix/hash/link
```

其中 hash 是为链接和秘密单词连接而计算的 MD5 哈希的十六进制表示，prefix 是没有斜杠的任意字符串。

如果请求链接通过了真实性检查，则 [$secure_link](#v-secure-link) 变量被设置为从请求 URI 提取的链接。否则，[$secure_link](#v-secure-link) 变量被设置为空字符串。

示例：

```nginx
location /p/ {
    secure_link_secret secret;

    if ($secure_link = "") {
        return 403;
    }

    rewrite ^ /secure/$secure_link;
}

location /secure/ {
    internal;
}
```

请求 "/p/5e814704a28d9bc1914ff19fa0c4a00a/link" 将被内部重定向到 "/secure/link"。

在 UNIX 上，可以通过以下命令获取此示例的哈希值：

```console
echo -n 'linksecret' | openssl md5 -hex
```

<a id="built-in-variables-9"></a>

## 内置变量

<a id="v-secure-link"></a>

### `$secure_link`

链接检查的状态。具体值取决于所选的操作模式。

<a id="v-secure-link-expires"></a>

### `$secure_link_expires`

在请求中传递的链接的生命周期；仅用于 [secure_link_md5](#secure-link-md5) 指令。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_slice.md

<!-- review: finished -->

<a id="http-slice"></a>

# Slice

该模块是一个过滤器，将请求拆分为子请求，每个子请求返回特定范围的响应。该过滤器提供了更有效的大响应缓存。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，默认情况下不会构建此模块；它需要通过 `‑‑with‑http_slice_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用。

在来自 [我们仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的包和镜像中，该模块已包含在构建中。

<a id="configuration-example-39"></a>

## 配置示例

```nginx
location / {
    slice             1m;
    proxy_cache       cache;
    proxy_cache_key   $uri$is_args$args$slice_range;
    proxy_set_header  Range $slice_range;
    proxy_cache_valid 200 206 1h;
    proxy_pass        http://localhost:8000;
}
```

在此示例中，响应被分割为 1 兆字节可缓存的切片。

<a id="directives-42"></a>

## 指令

<a id="index-0"></a>

<a id="slice"></a>

### slice

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `slice` size;          |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | `slice 0;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

设置切片的大小。零值将禁用将响应分割为切片。

#### WARNING
请注意，值过低可能导致过多的内存使用和打开大量文件。

为了使子请求返回所需的范围，应该将 [$slice_range](#v-slice-range) 变量作为:samp:Range\`请求头字段传递给代理服务器。如果启用了 :ref:\`缓存 <proxy_cache>，应将 [$slice_range](#v-slice-range) 添加到 [缓存键](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-key) 中，并应 [启用](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-valid) 对状态码为 206 的响应的缓存。

<a id="built-in-variables-10"></a>

## 内置变量

<a id="v-slice-range"></a>

### `$slice_range`

以 [HTTP字节范围](https://datatracker.ietf.org/doc/html/rfc7233#section-2.1) 格式表示的当前切片范围，例如，`bytes=0-1048575`。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_split_clients.md

<!-- review: finished -->

<a id="http-split-clients"></a>

# Split Clients

该模块用于 A/B 测试、金丝雀发布或其他需要将一部分客户端路由到一个服务器或配置，同时将其余部分路由到其他地方的场景。

<a id="configuration-example-40"></a>

## 配置示例

```nginx
http {
    split_clients "${remote_addr}AAA" $variant {
                   0.5%               .one;
                   2.0%               .two;
                   *                  "";
    }

    server {
        location / {
            index index${variant}.html;
```

<a id="directives-43"></a>

## 指令

<a id="index-0"></a>

<a id="split-clients"></a>

### split_clients

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `split_clients` string $variable { ... }   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | —                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                       |

通过哈希 string 创建一个 $variable；
string 中的变量被替换，
替换结果被哈希，
然后将哈希值用于选择 $variable 的字符串值。

哈希函数使用
[MurmurHash2](https://en.wikipedia.org/wiki/MurmurHash#MurmurHash2)
（32 位），
其整个值范围
（0 到 4294967295）
按出现顺序映射到桶中；
百分比决定了桶的大小。
通配符 (`*`) 可以出现在最后；
不属于其他桶的哈希值会映射到其指定的值。

示例：

```nginx
split_clients "${remote_addr}AAA" $variant {
               0.5%               .one;
               2.0%               .two;
               *                  "";
}
```

在这里，替换 `$*remote_addr*AAA` 字符串后，
哈希值分布如下：

- 值从 0 到 21474835（0.5%）产生 `.one`；
- 值从 21474836 到 107374180（2%）产生 `.two`；
- 值从 107374181 到 4294967295（所有其他值）产生 `""`
  （空字符串）。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_ssi.md

<!-- review: finished -->

<a id="http-ssi"></a>

# SSI

该模块是一个过滤器，用于处理通过它传递的响应中的 SSI（服务器端包含）命令。

<a id="configuration-example-41"></a>

## 配置示例

```nginx
location / {
    ssi on;
#    ...
}
```

<a id="directives-44"></a>

## 指令

<a id="index-0"></a>

<a id="ssi"></a>

### ssi

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssi` `on` | `off`;                    |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `ssi off;`                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location, if in location |

启用或禁用响应中 SSI 命令的处理。

<a id="index-1"></a>

<a id="ssi-last-modified"></a>

### ssi_last_modified

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssi_last_modified` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `ssi_last_modified off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

允许在 SSI 处理过程中保留原始响应中的 `Last-Modified` 头字段，以便于响应缓存。

默认情况下，头字段会被移除，因为响应的内容在处理过程中被修改，可能包含动态生成的元素或与原始响应独立更改的部分。

<a id="index-2"></a>

<a id="ssi-min-file-chunk"></a>

### ssi_min_file_chunk

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssi_min_file_chunk` size;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `ssi_min_file_chunk 1k;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

设置存储在磁盘上的响应部分的最小大小，从该大小开始，使用 [sendfile](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#sendfile) 发送它们是有意义的。

<a id="index-3"></a>

<a id="ssi-silent-errors"></a>

### ssi_silent_errors

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssi_silent_errors` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `ssi_silent_errors off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

如果启用，在 SSI 处理期间发生错误时，将抑制输出 "[an error occurred while processing the directive]" 字符串。

<a id="index-4"></a>

<a id="ssi-types"></a>

### ssi_types

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssi_types` mime-type ...;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `ssi_types text/html;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

启用对具有指定 MIME 类型的响应中 SSI 命令的处理，除了 `text/html`。特殊值 "\*" 匹配任何 MIME 类型。

<a id="index-5"></a>

<a id="ssi-value-length"></a>

### ssi_value_length

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssi_value_length` length;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `ssi_value_length 256;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

设置 SSI 命令中参数值的最大长度。

<a id="ssi-commands"></a>

## SSI 命令

SSI 命令具有以下通用格式：

```html
<!--# command parameter1=value1 parameter2=value2 ... -->
```

支持以下命令：

<a id="samp-block"></a>

### `block`

定义一个可以作为 include 命令中的存根使用的块。块可以包含其他 SSI 命令。该命令具有以下参数：

<a id="samp-name"></a>

#### `name`

块名称。

示例：

```html
<!--# block name="one" -->
stub
<!--# endblock -->
```

<a id="samp-config"></a>

### `config`

设置在 SSI 处理期间使用的一些参数，即：

<a id="samp-errmsg"></a>

#### `errmsg`

在 SSI 处理期间发生错误时输出的字符串。默认情况下，输出以下字符串：

```none
`[an error occurred while processing the directive]`
```

<a id="samp-timefmt"></a>

#### `timefmt`

传递给 `strftime()` 函数的格式字符串，用于输出日期和时间。默认情况下，使用以下格式：

```none
`"%A, %d-%b-%Y %H:%M:%S %Z"`
```

"%s" 格式适合以秒为单位输出时间。

<a id="samp-echo"></a>

### `echo`

输出变量的值。该命令具有以下参数：

<a id="samp-var"></a>

#### `var`

变量名称。

<a id="samp-encoding"></a>

#### `encoding`

编码方法。可能的值包括 `none`、`url` 和 `entity`。默认使用 `entity`。

<a id="samp-default"></a>

#### `default`

一个非标准参数，设置在变量未定义时输出的字符串。默认输出 :samp:\` (none)\`。

该命令

```html
<!--# echo var="name" default="no" -->
```

替换以下命令序列：

```html
<!--# if expr="$name" --><!--# echo var="name" --><!--#
     else -->no<!--# endif -->
```

<a id="samp-if"></a>

### `if`

执行条件包含。支持以下命令：

```html
<!--# if expr="..." -->
...
<!--# elif expr="..." -->
...
<!--# else -->
...
<!--# endif -->
```

当前仅支持一层嵌套。该命令具有以下参数：

<a id="samp-expr"></a>

#### `expr`

表达式。表达式可以是：

* 变量存在性检查：

```html
<!--# if expr="$name" -->
```

* 变量与文本的比较：

```html
<!--# if expr="$name = text" -->
<!--# if expr="$name != text" -->
```

* 变量与正则表达式的比较：

```html
<!--# if expr="$name = /text/" -->
<!--# if expr="$name != /text/" -->
```

如果 text 包含变量，则会替换它们的值。正则表达式可以包含位置捕获和命名捕获，稍后可以通过变量使用，例如：

```html
<!--# if expr="$name = /(.+)@(?P<domain>.+)/" -->
  <!--# echo var="1" -->
  <!--# echo var="domain" -->
<!--# endif -->
```

<a id="samp-include"></a>

### `include`

将另一个请求的结果包含到响应中。该命令具有以下参数：

<a id="samp-file"></a>

#### `file`

指定包含的文件，例如：

```html
<!--# include file="footer.html" -->
```

<a id="samp-virtual"></a>

#### `virtual`

指定包含的请求，例如：

```html
<!--# include virtual="/remote/body.php?argument=value" -->
```

在一页上指定的多个请求，由代理或 FastCGI/uwsgi/SCGI/gRPC 服务器处理的请求会并行运行。如果需要顺序处理，则应使用 wait 参数。

<a id="samp-stub"></a>

#### `stub`

一个非标准参数，命名包含请求结果为空主体或请求处理期间发生错误时输出的块，例如：

```html
<!--# block name="one" -->&nbsp;<!--# endblock -->
<!--# include virtual="/remote/body.php?argument=value" stub="one" -->
```

替换块内容在包含请求上下文中处理。

<a id="samp-wait"></a>

#### `wait`

一个非标准参数，指示在继续 SSI 处理之前等待请求完全完成，例如：

```html
<!--# include virtual="/remote/body.php?argument=value" wait="yes" -->
```

<a id="ssi-include-set"></a>

#### `set`

一个非标准参数，指示将请求处理的成功结果写入指定变量，例如：

```html
<!--# include virtual="/remote/body.php?argument=value" set="one" -->
```

响应的最大大小由 [subrequest_output_buffer_size](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#subrequest-output-buffer-size) 指令设置：

```nginx
location /remote/ {
    subrequest_output_buffer_size 64k;
#    ...
}
```

<a id="samp-set"></a>

### `set`

设置变量的值。该命令具有以下参数：

#### `var`

变量名称。

<a id="samp-value"></a>

#### `value`

变量值。如果赋值中包含变量，则会替换它们的值。

<a id="built-in-variables-11"></a>

## 内置变量

<a id="v-date-local"></a>

### `$date_local`

当前时间（本地时区）。格式由 config 命令中的 timefmt 参数设置。

<a id="v-date-gmt"></a>

### `$date_gmt`

当前时间（GMT）。格式由 config 命令中的 timefmt 参数设置。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_ssl.md

<!-- review: finished -->

<a id="http-ssl"></a>

# SSL

提供 HTTPS 所需的支持。

当从 [源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时,
此模块默认不会被构建;
应使用
`‑‑with‑http_ssl_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用。

在来自 [我们仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中,
该模块已包含在构建中。

#### NOTE
此模块需要 OpenSSL 库。

<a id="configuration-example-42"></a>

## 配置示例

为了降低处理器负载,建议

* 将 [工作进程](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-processes) 数量设置为等于处理器数量,
* 启用 [keep-alive](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#keepalive-timeout) 连接,
* 启用 [共享](#ssl-session-cache) 会话缓存,
* 禁用 [内置](#ssl-session-cache) 会话缓存,
* 并可能增加会话 [生命周期](#ssl-session-timeout) (默认为 5 分钟):

```nginx
worker_processes auto;

http {

    # ...

    server {
        listen              443 ssl;
        keepalive_timeout   70;

        ssl_protocols       TLSv1.2 TLSv1.3;
        ssl_ciphers         AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
        ssl_certificate     /usr/local/angie/conf/cert.pem;
        ssl_certificate_key /usr/local/angie/conf/cert.key;
        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 10m;

        # ...
    }
```

<a id="directives-45"></a>

## 指令

<a id="index-0"></a>

<a id="ssl-buffer-size"></a>

### ssl_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_buffer_size` size;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `ssl_buffer_size 16k;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server              |

设置用于发送数据的缓冲区大小。

默认情况下,缓冲区大小为 16k,这对应于发送大响应时的最小开销。为了最小化首字节时间,使用较小的值可能是有益的,例如:

```nginx
ssl_buffer_size 4k;
```

<a id="index-1"></a>

<a id="ssl-certificate"></a>

### ssl_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_certificate` file;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | —                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server              |

为给定的虚拟服务器指定 PEM 格式的证书文件。如果除了主证书之外还应指定中间证书,则应按以下顺序在同一文件中指定它们:首先是主证书,然后是中间证书。PEM 格式的私钥可以放在同一文件中。

此指令可以多次指定以加载不同类型的证书,例如 RSA 和 ECDSA:

```nginx
server {
    listen              443 ssl;
    server_name         example.com;

    ssl_certificate     example.com.rsa.crt;
    ssl_certificate_key example.com.rsa.key;

    ssl_certificate     example.com.ecdsa.crt;
    ssl_certificate_key example.com.ecdsa.key;

    # ...
}
```

只有 OpenSSL 1.0.2 或更高版本支持为不同证书使用单独的证书链。对于较旧的版本,只能使用一个证书链。

#### NOTE
使用 OpenSSL 1.0.2 或更高版本时,可以在文件名中使用变量:

```nginx
ssl_certificate     $ssl_server_name.crt;
ssl_certificate_key $ssl_server_name.key;
```

请注意,使用变量意味着将为每次 SSL 握手加载证书,这可能会对性能产生负面影响。

可以指定值 `data:$variable` 来代替 file,这将从变量加载证书而不使用中间文件。请注意,不当使用此语法可能会带来安全隐患,例如将私钥数据写入 [错误日志](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log)。

#### NOTE
> 应该记住,由于 HTTPS 协议的限制,为了最大的互操作性,虚拟服务器应该监听 [不同的 IP 地址](https://cn.angie.software//angie/docs/configuration/ssl.md#https-separate-ips)。

如果启用了 [ssl_ntls](#ssl-ntls),该指令可以接受两个参数
(证书的签名部分和加密部分)
而不是一个:

```nginx
listen ... ssl;

ssl_ntls  on;

# 双 NTLS 证书
ssl_certificate      sign.crt enc.crt;
ssl_certificate_key  sign.key enc.key;

# 可以与常规 RSA 证书一起使用
ssl_certificate  rsa.crt;
ssl_certificate_key rsa.key;
```

<a id="index-2"></a>

<a id="ssl-certificate-cache"></a>

### ssl_certificate_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_certificate_cache` `off`;<br/><br/>`ssl_certificate_cache` `max=`N [`inactive=`time] [`valid=`time];   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `ssl_certificate_cache off;`                                                                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                                                                                                |

定义一个缓存,用于存储使用变量指定的 [SSL 证书](#ssl-certificate) 和 [私钥](#ssl-certificate-key)。

该指令支持以下参数:

- `max` — 设置缓存中的最大元素数量。当缓存溢出时,
  最近最少使用 (LRU) 的元素将被移除。
- `inactive` — 定义元素在未被访问的情况下被移除的时间。
  默认为 10 秒。
- `valid` — 定义缓存元素被视为有效并可以重用的时间。
  默认为 60 秒。在此期间之后,
  证书将被重新加载或重新验证。
- `off` — 禁用缓存。

示例:

```nginx
ssl_certificate       $ssl_server_name.crt;
ssl_certificate_key   $ssl_server_name.key;
ssl_certificate_cache max=1000 inactive=20s valid=1m;
```

<a id="index-3"></a>

<a id="ssl-certificate-compression"></a>

### ssl_certificate_compression

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_certificate_compression` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | `ssl_certificate_compression off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                                  |

启用 TLS 1.3 服务器证书 [压缩](https://datatracker.ietf.org/doc/html/rfc8879)。

#### NOTE
在使用 OpenSSL 3.2 或更高版本时支持该指令;支持的压缩算法列表由库提供。

#### NOTE
在使用 [BoringSSL](https://boringssl.googlesource.com/boringssl/) 时支持该指令;支持的压缩算法列表包括 `zlib`。

如果启用了 [ssl_stapling](#ssl-stapling),则禁用证书压缩。

<a id="index-4"></a>

<a id="ssl-certificate-key"></a>

### ssl_certificate_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_certificate_key` file;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | —                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                  |

为给定的虚拟服务器指定 PEM 格式的私钥文件。

#### NOTE
使用 OpenSSL 1.0.2 或更高版本时,可以在文件名中使用变量。

可以指定值 `engine:name:id` 来代替 file,这将从 OpenSSL 引擎 name 加载具有指定 id 的私钥。

可以指定值 `store:scheme:id` 来代替 file,用于从具有指定 id 和 OpenSSL 提供程序注册的 URI scheme 加载私钥,例如 [pkcs11](https://datatracker.ietf.org/doc/html/rfc7512)。

可以指定值 `data:$variable` 来代替 file,这将从变量加载私钥而不使用中间文件。请注意,不当使用此语法可能会带来安全隐患,例如将私钥数据写入 [错误日志](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log)。

> 如果启用了 [ssl_ntls](#ssl-ntls),该指令可以接受两个参数
> (密钥的签名部分和加密部分)
> 而不是一个:

> ```nginx
> listen ... ssl;

> ssl_ntls  on;

> # 双 NTLS 证书
> ssl_certificate      sign.crt enc.crt;
> ssl_certificate_key  sign.key enc.key;

> # 可以与常规 RSA 证书一起使用
> ssl_certificate  rsa.crt;
> ssl_certificate_key rsa.key;
> ```

<a id="index-5"></a>

<a id="ssl-ciphers"></a>

### ssl_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ciphers` ciphers;          |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `ssl_ciphers HIGH:!aNULL:!MD5;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                    |

指定启用的密码套件。密码套件以 OpenSSL 库理解的格式指定,例如:

```nginx
ssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
```

密码套件列表取决于安装的 OpenSSL 版本。
可以使用 `openssl ciphers` 命令查看完整列表。

#### WARNING
使用 OpenSSL 时,:samp:ssl_ciphers 指令  *不* 配置 TLS
1.3 的密码套件。要使用 OpenSSL 配置 TLS 1.3 密码套件,请使用
[ssl_conf_command](#ssl-conf-command) 指令,该指令是为支持高级
SSL 配置而添加的。

- 在 LibreSSL 中,TLS 1.3 密码套件  *可以* 使用
  `ssl_ciphers` 配置。
- 在 BoringSSL 中,TLS 1.3 密码套件根本无法配置。

<a id="index-6"></a>

<a id="ssl-client-certificate"></a>

### ssl_client_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_client_certificate` file;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                     |

指定 PEM 格式的受信任 CA 证书文件,用于
[验证](#ssl-verify-client) 客户端证书,以及在启用
[ssl_stapling](#ssl-stapling) 时验证 OCSP 响应。

证书列表将发送给客户端。如果不希望这样做,可以使用 [ssl_trusted_certificate](#ssl-trusted-certificate) 指令。

<a id="index-7"></a>

<a id="ssl-conf-command"></a>

### ssl_conf_command

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_conf_command` name value;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                     |

设置任意 OpenSSL [配置命令](https://docs.openssl.org/master/man3/SSL_CONF_cmd/)。

#### NOTE
在使用 OpenSSL 1.0.2 或更高版本时支持该指令。
要使用 OpenSSL 配置 TLS 1.3 密码套件,请使用 `Ciphersuites` 命令。

可以在同一级别上指定多个 ssl_conf_command 指令:

```nginx
ssl_conf_command Options PrioritizeChaCha;
ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;
```

如果当前级别没有定义 ssl_conf_command 指令,则这些指令会从上一个配置级别继承。

#### WARNING
直接配置 OpenSSL 可能导致意外行为。

<a id="index-8"></a>

<a id="ssl-crl"></a>

### ssl_crl

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_crl` file;   |
|--------------------------------------------------------------------------------------|-------------------|
| 默认值                                                                                  | —                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server      |

指定用于 [验证](#ssl-verify-client) 客户端证书的 PEM 格式吊销证书 (CRL) 文件。

<a id="index-9"></a>

<a id="ssl-dhparam"></a>

### ssl_dhparam

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_dhparam` file;   |
|--------------------------------------------------------------------------------------|-----------------------|
| 默认值                                                                                  | —                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server          |

指定一个包含 DHE 密码套件的 DH 参数的文件。

#### WARNING
默认情况下不设置参数,因此不会使用 DHE 密码套件。

<a id="index-10"></a>

<a id="ssl-early-data"></a>

### ssl_early_data

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_early_data` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `ssl_early_data off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                     |

启用或禁用 TLS 1.3 [早期数据](https://datatracker.ietf.org/doc/html/rfc8446#section-2.3)。

在早期数据中发送的请求会受到 [重放攻击](https://datatracker.ietf.org/doc/html/rfc8470) 的影响。为了保护应用层免受此类攻击,应使用 [$ssl_early_data](#v-ssl-early-data) 变量。

```nginx
proxy_set_header Early-Data $ssl_early_data;
```

#### NOTE
在使用 OpenSSL 1.1.1 或更高版本以及 [BoringSSL](https://boringssl.googlesource.com/boringssl/) 时支持该指令。

<a id="index-11"></a>

<a id="ssl-encrypted-hello-key"></a>

### ssl_encrypted_hello_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_encrypted_hello_key` file;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                      |

指定一个包含 PEM 格式的 ECH 私钥和 ECHConfigList 的文件。
该指令可以指定多次。
需要支持加密客户端问候 (ECH) 的 OpenSSL 或 BoringSSL 构建;
否则不支持。

<a id="index-12"></a>

<a id="ssl-ecdh-curve"></a>

### ssl_ecdh_curve

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ecdh_curve` curve;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `ssl_ecdh_curve auto;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server              |

指定 ECDHE 密码套件的曲线。

#### NOTE
在使用 OpenSSL 1.0.2 或更高版本时,可以指定多个曲线,例如:

```nginx
ssl_ecdh_curve prime256v1:secp384r1;
```

特殊值 `auto` 对应于 OpenSSL 1.0.2 或更高版本中 OpenSSL 库内置的曲线列表,或者在较旧版本中对应于 prime256v1。

#### NOTE
在使用 OpenSSL 1.0.2 或更高版本时,该指令设置服务器支持的曲线列表。因此,为了使 ECDSA 证书能够正常工作,重要的是要包括证书中使用的曲线。

<a id="index-13"></a>

<a id="ssl-ntls"></a>

### ssl_ntls

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ntls` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `ssl_ntls off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server               |

在使用 [TongSuo](https://github.com/Tongsuo-Project/Tongsuo) TLS 库时启用服务器端对 NTLS 的支持。

```nginx
listen ... ssl;
ssl_ntls  on;
```

#### NOTE
必须使用 `--with-ntls` 配置参数构建 Angie,并使用相应的支持 NTLS 的 SSL 库

```default
./configure --with-openssl=../Tongsuo-8.3.0 \
            --with-openssl-opt=enable-ntls  \
            --with-ntls
```

<a id="index-14"></a>

<a id="ssl-ocsp"></a>

### ssl_ocsp

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ocsp` `on` | `off` | `leaf`;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `ssl_ocsp off;`                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                        |

启用客户端证书链的 OCSP 验证。`leaf` 参数仅启用客户端证书的验证。

为了使 OCSP 验证正常工作,:ref:ssl_verify_client 指令应设置为 `on` 或 `optional`。

要解析 OCSP 响应者主机名,也应指定 [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 指令。

示例：

```nginx
ssl_verify_client on;
ssl_ocsp          on;
resolver          127.0.0.53;
```

<a id="index-15"></a>

<a id="ssl-ocsp-cache"></a>

### ssl_ocsp_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ocsp_cache` `off` | [shared:name:size];   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | `ssl_ocsp_cache off;`                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                                   |

设置存储客户端证书状态以进行 OCSP 验证的缓存的名称和大小。该缓存在所有工作进程之间共享。可以在多个虚拟服务器中使用相同名称的缓存。

`off` 参数禁止使用缓存。

<a id="index-16"></a>

<a id="ssl-ocsp-responder"></a>

### ssl_ocsp_responder

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ocsp_responder` uri;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                |

覆盖在 ["Authority Information Access"](https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.2.1) 证书扩展中指定的 OCSP 响应者的 URI,用于 [验证](#ssl-ocsp) 客户端证书。

仅支持 `http://` OCSP 响应者:

```nginx
ssl_ocsp_responder http://ocsp.example.com/;
```

<a id="index-17"></a>

<a id="ssl-password-file"></a>

### ssl_password_file

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_password_file` file;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                |

指定一个包含 [私钥](#ssl-certificate-key) 密码短语的文件,每个密码短语在单独的一行中指定。加载密钥时将依次尝试密码短语。

示例:

```nginx
http {
    ssl_password_file /etc/keys/global.pass;
    ...

    server {
        server_name www1.example.com;
        ssl_certificate_key /etc/keys/first.key;
    }

    server {
        server_name www2.example.com;

        # 也可以使用命名管道代替文件
        ssl_password_file /etc/keys/fifo;
        ssl_certificate_key /etc/keys/second.key;
    }
}
```

<a id="index-18"></a>

<a id="ssl-prefer-server-ciphers"></a>

### ssl_prefer_server_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_prefer_server_ciphers` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `ssl_prefer_server_ciphers off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                                |

指定在使用 SSLv3 和 TLS 协议时,服务器密码套件应优于客户端密码套件。

<a id="index-19"></a>

<a id="ssl-protocols"></a>

### ssl_protocols

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_protocols` [`SSLv2`] [`SSLv3`] [`TLSv1`] [`TLSv1.1`] [`TLSv1.2`] [`TLSv1.3`];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|
| 默认值                                                                                  | `ssl_protocols TLSv1.2 TLSv1.3;`                                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                                                                         |

#### Versionchanged
在 1.2.0 版本发生变更: `TLSv1.3` 参数被添加到默认集合中。

启用指定的协议。

#### NOTE
TLSv1.1 和 TLSv1.2 参数仅在使用 OpenSSL 1.0.1 或更高版本时有效。

TLSv1.3 参数仅在使用 OpenSSL 1.1.1 或更高版本时有效。

<a id="index-20"></a>

<a id="ssl-reject-handshake"></a>

### ssl_reject_handshake

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_reject_handshake` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `ssl_reject_handshake off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                           |

如果启用,:ref:server 块中的 SSL 握手将被拒绝。

例如,在以下配置中,与服务器名称不是 example.com 的 SSL 握手将被拒绝:

```nginx
server {
    listen               443 ssl default_server;
    ssl_reject_handshake on;
}

server {
    listen              443 ssl;
    server_name         example.com;
    ssl_certificate     example.com.crt;
    ssl_certificate_key example.com.key;
}
```

<a id="index-21"></a>

<a id="ssl-session-cache"></a>

### ssl_session_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_cache` `off` | `none` | [builtin[:size]] [shared:name:size];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| 默认值                                                                                  | `ssl_session_cache none;`                                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                                                                |

设置用于存储会话参数的缓存类型和大小。缓存可以是以下任意类型：

| `off`     | 严格禁止使用会话缓存：Angie 明确告知客户端会话不可重用。                                                                                                                                                    |
|-----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `none`    | 温和地禁止使用会话缓存：Angie 告知客户端会话可以重用，但实际上不在缓存中存储会话参数。                                                                                                                                     |
| `builtin` | OpenSSL 内置缓存；仅由一个工作进程使用。缓存大小以会话数指定。如果未指定大小，则等于 20480 个会话。使用内置缓存可能导致内存碎片。                                                                                                           |
| `shared`  | 在所有工作进程之间共享的缓存。缓存大小以字节为单位指定；1 兆字节可以存储约 4000 个会话。每个共享缓存应有一个任意名称。具有相同名称的缓存可以在多个虚拟服务器中使用。除非使用 [ssl_session_ticket_key](#ssl-session-ticket-key) 指令显式配置，否则它还用于自动生成、存储和定期轮换 TLS 会话票据密钥。 |

两种缓存类型可以同时使用，例如：

```nginx
ssl_session_cache builtin:1000 shared:SSL:10m;
```

但仅使用共享缓存而不使用内置缓存应该更高效。

<a id="index-22"></a>

<a id="ssl-session-ticket-key"></a>

### ssl_session_ticket_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_ticket_key` file;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                     |

设置包含用于加密和解密 TLS 会话票据的密钥的文件。如果需要在多个服务器之间共享相同的密钥，则此指令是必需的。默认情况下，使用随机生成的密钥。

如果指定了多个密钥，则仅使用第一个密钥来加密 TLS 会话票据。这允许配置密钥轮换，例如：

```nginx
ssl_session_ticket_key current.key;
ssl_session_ticket_key previous.key;
```

该文件必须包含 80 或 48 字节的随机数据，可以使用以下命令创建：

```console
openssl rand 80 > ticket.key
```

根据文件大小，将使用 AES256（用于 80 字节密钥）或 AES128（用于 48 字节密钥）进行加密。

<a id="index-23"></a>

<a id="ssl-session-tickets"></a>

### ssl_session_tickets

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_tickets` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `ssl_session_tickets on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                          |

启用或禁用通过 [TLS 会话票据](https://datatracker.ietf.org/doc/html/rfc5077) 进行会话恢复。

<a id="index-24"></a>

<a id="ssl-session-timeout"></a>

### ssl_session_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_timeout` time;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `ssl_session_timeout 5m;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                  |

指定客户端可以重用会话参数的时间。

<a id="index-25"></a>

<a id="ssl-stapling"></a>

### ssl_stapling

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_stapling` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `ssl_stapling off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                   |

启用或禁用服务器 [装订 OCSP 响应](https://datatracker.ietf.org/doc/html/rfc6066#section-8)。示例：

```nginx
ssl_stapling on;
resolver 127.0.0.53;
```

要使 OCSP 装订正常工作，应该知道服务器证书颁发者的证书。如果 [ssl_certificate](#ssl-certificate) 文件不包含中间证书，则服务器证书颁发者的证书应存在于 [ssl_trusted_certificate](#ssl-trusted-certificate) 指令指定的文件中。

#### WARNING
为了解析 OCSP 响应者主机名，还应指定 [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 指令。

<a id="index-26"></a>

<a id="ssl-stapling-file"></a>

### ssl_stapling_file

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_stapling_file` file;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                |

设置后，装订的 OCSP 响应将从指定的文件中获取，而不是查询服务器证书中指定的 OCSP 响应者。

该文件应为 DER 格式，由 `openssl ocsp` 命令生成。

<a id="index-27"></a>

<a id="ssl-stapling-responder"></a>

### ssl_stapling_responder

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_stapling_responder` `uri`;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                      |

覆盖证书扩展 ["Authority Information Access"](https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.2.1) 中指定的 OCSP 响应者的 URI。

仅支持 `http://` OCSP 响应者：

```nginx
ssl_stapling_responder http://ocsp.example.com/;
```

<a id="index-28"></a>

<a id="ssl-stapling-verify"></a>

### ssl_stapling_verify

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_stapling_verify` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `ssl_stapling_verify off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                          |

启用或禁用服务器对 OCSP 响应的验证。

要使验证正常工作，应使用 [ssl_trusted_certificate](#ssl-trusted-certificate) 指令将服务器证书颁发者的证书、根证书和所有中间证书配置为受信任。

<a id="index-29"></a>

<a id="ssl-trusted-certificate"></a>

### ssl_trusted_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_trusted_certificate` file;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                      |

指定包含 PEM 格式受信任 CA 证书的文件，用于 [验证](#ssl-verify-client) 客户端证书，以及在启用 [ssl_stapling](#ssl-stapling) 时验证 OCSP 响应。

与 [ssl_client_certificate](#ssl-client-certificate) 设置的证书集不同，这些证书的列表不会发送给客户端。

<a id="index-30"></a>

<a id="ssl-verify-client"></a>

### ssl_verify_client

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_verify_client` `on` | `off` | `optional` | `optional_no_ca`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| 默认值                                                                                  | `ssl_verify_client off;`                                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                                                        |

启用客户端证书验证。验证结果存储在 [$ssl_client_verify](#v-ssl-client-verify) 变量中。

| `optional`       | 请求客户端证书，如果证书存在则进行验证。                                     |
|------------------|----------------------------------------------------------|
| `optional_no_ca` | 请求客户端证书，但不要求其由受信任的 CA 证书签名。这适用于由 Angie 外部的服务执行实际证书验证的情况。 |

<a id="index-31"></a>

<a id="ssl-verify-depth"></a>

### ssl_verify_depth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_verify_depth` number;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `ssl_verify_depth 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                 |

设置客户端证书链中的验证深度。

<a id="ssl-error-codes"></a>

## 错误处理

`http_ssl` 模块支持几个非标准错误代码，可以使用 [error_page](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#error-page) 指令进行重定向：

| `495`   | 客户端证书验证过程中发生错误；    |
|---------|--------------------|
| `496`   | 客户端未提供所需的证书；       |
| `497`   | 常规请求已发送到 HTTPS 端口。 |

重定向发生在请求完全解析之后，此时变量（如 [$request_uri](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-uri)、[$uri](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-uri)、[$args](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-args) 等）已可用。

<a id="built-in-variables-12"></a>

## 内置变量

http_ssl 模块支持内置变量：

<a id="v-ssl-alpn-protocol"></a>

### `$ssl_alpn_protocol`

返回在 SSL 握手期间通过 ALPN 选择的协议，否则返回空字符串。

<a id="v-ssl-cipher"></a>

### `$ssl_cipher`

返回已建立的 SSL 连接所使用的密码套件名称。

<a id="v-ssl-ciphers"></a>

### `$ssl_ciphers`

返回客户端支持的密码套件列表。已知的密码套件按名称列出，未知的以十六进制显示，例如：

> AES128-SHA:AES256-SHA:0x00ff

#### NOTE
仅在使用 OpenSSL 1.0.2 或更高版本时才完全支持该变量。对于较旧版本，该变量仅适用于新会话，并且仅列出已知的密码套件。

<a id="v-ssl-client-escaped-cert"></a>

### `$ssl_client_escaped_cert`

返回已建立的 SSL 连接的 PEM 格式客户端证书（URL 编码）。

<a id="v-ssl-client-fingerprint"></a>

### `$ssl_client_fingerprint`

返回已建立的 SSL 连接的客户端证书的 SHA1 指纹。

<a id="v-ssl-client-i-dn"></a>

### `$ssl_client_i_dn`

根据 [RFC 2253](https://datatracker.ietf.org/doc/html/rfc2253) 返回已建立的 SSL 连接的客户端证书的"颁发者 DN"字符串。

<a id="v-ssl-client-i-dn-legacy"></a>

### `$ssl_client_i_dn_legacy`

返回已建立的 SSL 连接的客户端证书的"颁发者 DN"字符串。

<a id="v-ssl-client-raw-cert"></a>

### `$ssl_client_raw_cert`

返回已建立的 SSL 连接的 PEM 格式客户端证书。

<a id="v-ssl-client-s-dn"></a>

### `$ssl_client_s_dn`

根据 [RFC 2253](https://datatracker.ietf.org/doc/html/rfc2253) 返回已建立的 SSL 连接的客户端证书的"主题 DN"字符串。

<a id="v-ssl-client-s-dn-legacy"></a>

### `$ssl_client_s_dn_legacy`

返回已建立的 SSL 连接的客户端证书的"主题 DN"字符串。

<a id="v-ssl-client-serial"></a>

### `$ssl_client_serial`

返回已建立的 SSL 连接的客户端证书的序列号。

<a id="v-ssl-client-sigalg"></a>

### `$ssl_client_sigalg`

返回已建立的 SSL 连接的客户端证书的\`签名算法 <[https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-16](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-16)>\`_。

#### NOTE
仅在使用 OpenSSL 3.5 或更高版本时才支持该变量。对于较旧版本，该变量值将为空字符串。

#### NOTE
该变量仅适用于新会话。

<a id="v-ssl-client-v-end"></a>

### `$ssl_client_v_end`

返回客户端证书的结束日期。

<a id="v-ssl-client-v-remain"></a>

### `$ssl_client_v_remain`

返回客户端证书到期前的剩余天数。

<a id="v-ssl-client-v-start"></a>

### `$ssl_client_v_start`

返回客户端证书的开始日期。

<a id="v-ssl-client-verify"></a>

### `$ssl_client_verify`

返回客户端证书验证的结果：`SUCCESS`、`FAILED:reason`，如果未提供证书则返回 `NONE`。

<a id="v-ssl-curve"></a>

### `$ssl_curve`

返回在 SSL 握手期间用于密钥交换的协商曲线。已知的曲线按名称列出，未知的以十六进制显示，例如：

> prime256v1

#### NOTE
仅在使用 OpenSSL 3.0 或更高版本时才支持该变量。对于较旧版本，该变量值将为空字符串。

<a id="v-ssl-curves"></a>

### `$ssl_curves`

返回客户端支持的曲线列表。已知的曲线按名称列出，未知的以十六进制显示，例如：

> 0x001d:prime256v1:secp521r1:secp384r1

#### NOTE
仅在使用 OpenSSL 1.0.2 或更高版本时才支持该变量。对于较旧版本，该变量值将为空字符串。

该变量仅适用于新会话。

<a id="v-ssl-early-data"></a>

### `$ssl_early_data`

如果使用 TLS 1.3 [早期数据](#ssl-early-data) 且握手未完成，则返回"1"，否则返回""。

<a id="v-ssl-encrypted-hello"></a>

### `$ssl_encrypted_hello`

如果使用加密客户端问候（ECH），则返回"1"，否则返回""。

<a id="v-ssl-protocol"></a>

### `$ssl_protocol`

返回已建立的 SSL 连接的协议。

<a id="v-ssl-server-cert-type"></a>

### `$ssl_server_cert_type`

根据服务器证书和密钥的类型，取值为 `RSA`、`DSA`、`ECDSA`、`ED448`、
`ED25519`、`SM2`、`RSA-PSS` 或 `unknown`。

<a id="v-ssl-server-name"></a>

### `$ssl_server_name`

返回通过 [SNI](http://en.wikipedia.org/wiki/Server_Name_Indication) 请求的服务器名称。

<a id="v-ssl-session-id"></a>

### `$ssl_session_id`

返回已建立的 SSL 连接的会话标识符。

<a id="v-ssl-session-reused"></a>

### `$ssl_session_reused`

如果 SSL 会话被重用，则返回"r"，否则返回"."。

<a id="v-ssl-sigalg"></a>

### `$ssl_sigalg`

返回已建立的 SSL 连接的服务器证书的\`签名算法 <[https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-16](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-16)>\`_。

#### NOTE
仅在使用 OpenSSL 3.5 或更高版本时才支持该变量。对于较旧版本，该变量值将为空字符串。

#### NOTE
该变量仅适用于新会话。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_stub_status.md

<!-- review: finished -->

<a id="http-stub-status"></a>

# Stub Status

该模块提供对基本服务器状态信息的访问。

当从源代码中 [构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，
默认不会构建此模块；
应通过 `‑‑with‑http_stub_status_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 来启用。

在来自 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中，
该模块已包含在构建中。

<a id="configuration-example-43"></a>

## 配置示例

```nginx
location = /basic_status {
    stub_status;
}
```

此配置创建了一个简单的网页，显示基本状态信息，如下所示：

```console
Active connections: 291
server accepts handled requests
 16630948 16630948 31070465
Reading: 6 Writing: 179 Waiting: 106
```

<a id="directives-46"></a>

## 指令

<a id="index-0"></a>

<a id="stub-status"></a>

### stub_status

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `stub_status`;   |
|--------------------------------------------------------------------------------------|------------------|
| 默认值                                                                                  | —                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server, location |

状态信息将可从所在位置访问。

<a id="data"></a>

## 数据

提供以下状态信息：

<a id="samp-active-connections"></a>

### `Active connections`

当前活跃客户端连接数，包括等待连接。

<a id="samp-accepts"></a>

### `accepts`

接受的客户端连接总数。

<a id="samp-handled"></a>

### `handled`

处理的连接总数。通常，该参数值与accepts相同，除非达到某些资源限制（例如，[worker_connections](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-connections) 限制）。

<a id="samp-requests"></a>

### `requests`

客户端请求总数。

<a id="samp-reading"></a>

### `Reading`

当前正在读取请求头的连接数。

<a id="samp-writing"></a>

### `Writing`

当前正在向客户端写回响应的连接数。

<a id="samp-waiting"></a>

### `Waiting`

当前空闲等待请求的客户端连接数。

<a id="built-in-variables-13"></a>

## 内置变量

<a id="v-connections-active"></a>

### `$connections_active`

与 Active connections 的值相同。

<a id="v-connections-reading"></a>

### `$connections_reading`

与 Reading 的值相同。

<a id="v-connections-writing"></a>

### `$connections_writing`

与 Writing 的值相同。

<a id="v-connections-waiting"></a>

### `$connections_waiting`

与 Waiting 的值相同。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_sub.md

<!-- review: finished -->

<a id="http-sub"></a>

# Sub

该模块是一个过滤器，通过将一个指定字符串替换为另一个字符串来修改响应。

当从源代码 [构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，
此模块默认不被构建；
它应通过
`‑‑with‑http_sub_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 来启用。

在来自 [我们的存储库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中，
该模块已包含在构建中。

<a id="configuration-example-44"></a>

## 配置示例

```nginx
location / {
    sub_filter '<a href="http://127.0.0.1:8080/'  '<a href="https://$host/';
    sub_filter '<img src="http://127.0.0.1:8080/' '<img src="https://$host/';
    sub_filter_once on;
}
```

<a id="directives-47"></a>

## 指令

<a id="index-0"></a>

<a id="sub-filter"></a>

### sub_filter

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sub_filter` string replacement;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | —                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

设置要替换的字符串和替换字符串。匹配要替换的字符串时不区分大小写。要替换的字符串和替换字符串可以包含变量。在同一配置级别上可以指定多个 `sub_filter` 指令。这些指令仅在当前级别未定义 `sub_filter` 指令的情况下才会从上一级配置继承。

<a id="index-1"></a>

<a id="sub-filter-last-modified"></a>

### sub_filter_last_modified

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sub_filter_last_modified` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | `sub_filter_last_modified off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                     |

允许在替换期间保留原始响应的 `Last-Modified` 头字段，以便于响应缓存。

默认情况下，由于响应内容在处理过程中被修改，头字段会被移除。

<a id="index-2"></a>

<a id="sub-filter-once"></a>

### sub_filter_once

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sub_filter_once` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `sub_filter_once on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

指示是否仅查找每个要替换的字符串一次或重复查找。

<a id="index-3"></a>

<a id="sub-filter-types"></a>

### sub_filter_types

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sub_filter_types` mime-type ...;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `sub_filter_types text/html;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

除了 `text/html` 外，还在指定 MIME 类型的响应中启用字符串替换。特殊值 "\*" 匹配任何 MIME 类型。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_upstream.md

<!-- review: finished -->

<a id="http-upstream"></a>

# Upstream

提供一个上下文,用于描述可在 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass)、[fastcgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-pass)、[uwsgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-pass)、[scgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-pass)、[memcached_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_memcached.md#memcached-pass) 和 [grpc_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_grpc.md#grpc-pass) 指令中使用的服务器组。

<a id="configuration-example-45"></a>

## 配置示例

```nginx
upstream backend {
    zone backend 1m;
    server backend1.example.com       weight=5;
    server backend2.example.com:8080;
    server backend3.example.com       service=_example._tcp resolve;
    server unix:/tmp/backend3;

    server backup1.example.com:8080   backup;
    server backup2.example.com:8080   backup;
}

resolver 127.0.0.53 status_zone=resolver;

server {
    location / {
        proxy_pass http://backend;
    }
}
```

<a id="directives-48"></a>

## 指令

<a id="index-0"></a>

<a id="u-backup-switch"></a>

### backup_switch (PRO)

#### Versionadded
Added in version 1.9.0: PRO

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `backup_switch` `permanent`[=time];   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | —                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                              |

该指令启用从  *活动* 组(即上次成功找到服务器的组)而不是主组开始服务器选择的能力。
如果在活动组中无法为下一个请求找到服务器,
并且搜索移动到备份组,
则该组将成为活动组,
后续请求将首先定向到该组中的服务器。

如果定义了 `permanent` 参数但没有 [time](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax) 值,
则该组在选择后保持活动状态,
并且不会自动重新检查较低级别的组。
如果指定了 time,
则该组的活动状态在指定的时间间隔后过期,
负载均衡器将再次检查较低级别的组,
如果服务器正常工作则返回到这些组。

示例:

```nginx
upstream my_backend {
    server primary1.example.com;
    server primary2.example.com;

    server backup1.example.com backup;
    server backup2.example.com backup;

    backup_switch permanent=2m;
}
```

如果负载均衡器从主服务器切换到备份组,
所有后续请求将在 2 分钟内由该备份组处理。
2 分钟过后,负载均衡器会重新检查主服务器,
如果它们正常工作,则再次使其成为活动组。

<a id="index-1"></a>

<a id="u-bind-conn"></a>

### bind_conn (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `bind_conn` value;   |
|--------------------------------------------------------------------------------------|----------------------|
| 默认值                                                                                  | —                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream             |

当指定为变量字符串的 value 不等于 `""` 和 `"0"` 时,
允许将服务器连接绑定到客户端连接。

#### WARNING
`bind_conn` 指令必须在所有设置负载均衡方法的指令之后使用,
否则将不起作用。
如果与 [sticky](#u-sticky) 指令一起使用,
则 `bind_conn` 必须在 `sticky` 之后。

#### WARNING
使用该指令时,:ref:Proxy <http_proxy> 模块设置
必须允许使用持久连接,例如:

```nginx
proxy_http_version 1.1;
proxy_set_header Connection "";
```

该指令的典型用例是代理使用 NTLM 身份验证的连接,
其中需要在协商开始时确保客户端到服务器的绑定:

```nginx
map $http_authorization   $ntlm {
    ~*^N(?:TLM|egotiate)  1;
}

upstream ntlm_backend {
    server 127.0.0.1:8080;
    bind_conn $ntlm;
}

server {
    # ...
    location / {
        proxy_pass http://ntlm_backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        # ...
    }
}
```

<a id="index-2"></a>

<a id="u-feedback"></a>

### feedback (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `feedback` variable [`inverse`] [`factor=`number] [`account=`condition_variable] [`last_byte`];   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                                                                                          |

在 `upstream` 中设置基于反馈的负载均衡机制。
它通过将每个代理服务器的权重乘以平均反馈值来动态调整均衡决策,
该值会根据 variable 的值随时间变化,
并受可选条件的约束。

可以指定以下参数:

| `variable`   | 从中获取反馈值的变量。<br/>它应该表示性能或健康指标;<br/>假定服务器在响应头或其他方式中提供该值。<br/><br/>该值在服务器的每个响应中进行评估,<br/>并根据 `inverse` 和 `factor` 设置<br/>纳入移动平均值。                                                                                                                                                                                                                             |
|--------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `inverse`    | 如果设置了该参数,则反馈值将被反向解释:<br/>较低的值表示更好的性能。                                                                                                                                                                                                                                                                                                                      |
| `factor`     | 计算平均值时考虑反馈值的因子。<br/>有效值为 0 到 99 之间的整数。<br/>默认值为 `90`。<br/><br/>平均值使用 [指数平滑](https://en.wikipedia.org/wiki/Exponential_smoothing) 公式计算。<br/><br/>因子越大,新值对平均值的影响越小;<br/>如果指定为 `90`,则将采用 90% 的先前值<br/>和仅 10% 的新值。                                                                                                                                             |
| `account`    | 指定一个条件变量,<br/>用于控制在计算中考虑哪些响应。<br/>仅当该响应的条件变量<br/>不等于 `""` 或 `"0"` 时,<br/>才会使用该响应的反馈值更新平均值。<br/><br/>#### NOTE<br/>默认情况下,:ref:主动检查 <u_upstream_probe> 期间的响应<br/>不包含在计算中;<br/>将 [$upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#v-upstream-probe) 变量<br/>与 `account` 结合使用可以包含这些响应<br/>或甚至排除其他所有响应。 |
| `last_byte`  | 允许在接收到完整响应后处理来自代理服务器的数据,<br/>而不仅仅是响应头。                                                                                                                                                                                                                                                                                                                     |

示例:

```nginx
upstream backend {

    zone backend 1m;

    feedback $feedback_value factor=80 account=$condition_value;

    server backend1.example.com;
    server backend2.example.com;
}

map $upstream_http_custom_score $feedback_value {
    "high"                      100;
    "medium"                    75;
    "low"                       50;
    default                     10;
}

map $upstream_probe $condition_value {
    "high_priority" "1";
    "low_priority"  "0";
    default         "1";
}
```

此配置根据响应头字段中的特定分数
按反馈级别对服务器响应进行分类,
并在 [$upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#v-upstream-probe) 上添加条件,
仅考虑来自 `high_priority` 主动检查的响应
或对常规客户端请求的响应。

<a id="index-3"></a>

<a id="u-hash"></a>

### hash

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `hash` key [`consistent`];   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | —                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                     |

为服务器组指定负载均衡方法,其中客户端到服务器的映射使用哈希键值确定。键可以包含文本、变量及其组合。请注意,从组中添加或删除服务器可能会导致大多数键重新映射到不同的服务器。该方法与 [Cache::Memcached](https://metacpan.org/pod/Cache::Memcached) Perl 库兼容。

```nginx
hash $remote_addr;
```

当使用解析为多个 IP 地址的域名时
(例如,使用 `resolve` 参数),
服务器不会对接收到的地址进行排序,因此它们的顺序可能在
不同服务器之间有所不同,这会影响客户端分布。
为确保一致的分布,
请使用 `consistent` 参数。

如果指定了 `consistent` 参数,将使用 [ketama](https://www.metabrew.com/article/libketama-consistent-hashing-algo-memcached-clients) 一致性哈希方法。该方法确保当从组中添加或删除服务器时,只有少数键会重新映射到不同的服务器。这有助于为缓存服务器实现更高的缓存命中率。该方法与 [Cache::Memcached::Fast](https://metacpan.org/pod/Cache::Memcached::Fast) Perl 库兼容,其中 `ketama_points` 参数设置为 160。

<a id="index-4"></a>

<a id="u-ip-hash"></a>

### ip_hash

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ip_hash`;   |
|--------------------------------------------------------------------------------------|--------------|
| 默认值                                                                                  | —            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream     |

为服务器组指定负载均衡方法,根据客户端 IP 地址在服务器之间分配请求。使用客户端 IPv4 地址的前三个八位组或完整的 IPv6 地址作为哈希键。该方法确保来自同一客户端的请求始终传递到同一服务器,除非该服务器不可用。在这种情况下,客户端请求将传递到另一台服务器。最有可能的是,这也将是同一台服务器。

如果需要临时移除某台服务器,应使用 `down` 参数标记它,以保持客户端 IP 地址的当前哈希:

```nginx
upstream backend {
    ip_hash;

    server backend1.example.com;
    server backend2.example.com;
    server backend3.example.com down;
    server backend4.example.com;
}
```

<a id="index-5"></a>

<a id="u-keepalive"></a>

### keepalive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `keepalive` connections;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | —                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                   |

激活到上游服务器的连接缓存。

`connections` 参数设置每个工作进程缓存中保留的到上游服务器的空闲 keepalive 连接的最大数量。当超过此数量时,最近最少使用的连接将被关闭。

#### NOTE
需要特别注意的是,:samp:keepalive 指令不限制 Angie 工作进程可以打开的到上游服务器的连接总数。`connections` 参数应设置得足够低,以便让上游服务器也能处理新的传入连接。

#### WARNING
`keepalive` 指令必须在所有设置负载均衡方法的指令之后使用,否则它将不起作用。

使用 keepalive 连接的 memcached 上游配置示例:

```nginx
upstream memcached_backend {
    server 127.0.0.1:11211;
    server 10.0.0.2:11211;

    keepalive 32;
}

server {
    #...

    location /memcached/ {
        set $memcached_key $uri;
        memcached_pass memcached_backend;
    }

}
```

对于 HTTP,应将 [proxy_http_version](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http-version) 指令设置为 "1.1",并清除 `Connection` 头字段:

```nginx
upstream http_backend {
    server 127.0.0.1:8080;

    keepalive 16;
}

server {
    #...

    location /http/ {
        proxy_pass http://http_backend;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
    #    ...
    }
}
```

#### NOTE
或者,可以通过向上游服务器传递 "Connection: Keep-Alive" 头字段来使用 HTTP/1.0 持久连接,但不推荐使用此方法。

对于 FastCGI 服务器,需要设置 [fastcgi_keep_conn](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-keep-conn) 才能使 keepalive 连接工作:

```nginx
upstream fastcgi_backend {
    server 127.0.0.1:9000;

    keepalive 8;
}

server {
    #...

    location /fastcgi/ {
        fastcgi_pass fastcgi_backend;
        fastcgi_keep_conn on;
    #    ...
    }
}
```

#### NOTE
SCGI 和 uwsgi 协议没有 keepalive 连接的概念。

<a id="index-6"></a>

<a id="u-keepalive-requests"></a>

### keepalive_requests

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `keepalive_requests` number;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `keepalive_requests 1000;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                       |

设置可以通过一个 keepalive 连接处理的最大请求数。达到最大请求数后,连接将被关闭。

定期关闭连接对于释放每个连接的内存分配是必要的。因此,使用过高的最大请求数可能导致内存使用过多,不建议这样做。

<a id="index-7"></a>

<a id="u-keepalive-time"></a>

### keepalive_time

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `keepalive_time` time;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | `keepalive_time 1h;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                 |

限制可以通过一个 keepalive 连接处理请求的最长时间。达到此时间后,连接将在后续请求处理完成后关闭。

<a id="index-8"></a>

<a id="u-keepalive-timeout"></a>

### keepalive_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `keepalive_timeout` timeout;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `keepalive_timeout 60s;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                       |

设置与上游服务器的空闲保持连接保持打开状态的超时时间。

<a id="index-9"></a>

<a id="u-least-conn"></a>

### least_conn

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `least_conn`;   |
|--------------------------------------------------------------------------------------|-----------------|
| 默认值                                                                                  | —               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream        |

指定服务器组应使用负载均衡方法,将请求传递给活动连接数最少的服务器,同时考虑服务器的权重。如果有多个这样的服务器,则使用加权轮询均衡方法依次尝试它们。

<a id="index-10"></a>

<a id="u-least-time"></a>

### least_time (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `least_time` `header` | `last_byte` [`factor=`number] [`account=`condition_variable];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                                                                                |

指定服务器组应使用负载均衡方法,其中活动服务器接收请求的机会与其平均响应时间成反比;响应时间越短,服务器获得的请求越多。

| `header`    | 该指令计算接收响应头的平均时间。   |
|-------------|--------------------|
| `last_byte` | 该指令使用接收整个响应的平均时间。  |

| `factor`   | 与 [response_time_factor (PRO)](#u-response-time-factor) 的作用相同,如果设置了该参数,则会覆盖它。                                                                                                                                                                                                                                             |
|------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `account`  | 指定一个条件变量,用于控制哪些响应包含在计算中。<br/>仅当响应的条件变量不是 `""` 或 `"0"` 时,才会更新平均值。<br/><br/>#### NOTE<br/>默认情况下,:ref:主动健康探测 <u_upstream_probe> 期间的响应不包含在计算中;<br/>将 [$upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#v-upstream-probe) 变量与 `account` 结合使用,<br/>可以包含这些响应,甚至排除其他所有响应。 |

当前值在 API 的 [上游指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-upstreams) 中以服务器的 `health` 对象中的 `header_time` (仅头部)和 `response_time` (整个响应)形式呈现。

<a id="index-11"></a>

<a id="u-queue"></a>

### queue (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `queue` number [`timeout=`time];   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | —                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                           |

如果在第一次尝试时无法为请求分配代理服务器(例如,在短暂的服务中断期间或负载激增达到 [max_conns](#u-server) 限制时),请求不会被拒绝;相反,Angie 会尝试将其排队等待处理。

该指令的 number 参数设置 [工作进程](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-processes) 队列中的最大请求数。如果队列已满,则向客户端返回 `502 (Bad Gateway)` 错误。

#### NOTE
[proxy_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-next-upstream) 指令的逻辑也适用于排队的请求。具体来说,如果为请求选择了服务器但无法将其交给该服务器,则请求可能会返回队列。

如果在 `timeout` 设置的 [时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax) 内(默认为 60 秒)未选择服务器来处理排队的请求,则向客户端返回 `502 (Bad Gateway)` 错误。过早关闭连接的客户端的请求也会从队列中删除;在 [API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-queue) 中有通过队列的请求状态的计数器。

#### WARNING
`queue` 指令必须在所有设置负载均衡方法的指令之后使用;否则它将不起作用。

<a id="index-12"></a>

<a id="u-random"></a>

### random

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `random` [`two`];   |
|--------------------------------------------------------------------------------------|---------------------|
| 默认值                                                                                  | —                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream            |

为服务器组指定负载均衡方法,将请求传递给随机选择的服务器,同时考虑服务器权重。

如果指定了可选的 `two` 参数,Angie 会随机选择两个服务器,然后使用 [least_conn](#u-least-conn) 方法从中选择一个,即将请求传递给活动连接数最少的服务器。

<a id="index-13"></a>

<a id="u-response-time-factor"></a>

### response_time_factor (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `response_time_factor` number;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `response_time_factor 90;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                         |

设置在使用 [指数加权移动平均](https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average) 公式计算 [least_time (PRO)](#u-least-time) 负载均衡方法的平均响应时间时,\*\*先前\*\*值的平滑因子。

指定的 number 越高,新值对平均值的影响越小;如果指定为 `90`,则取先前值的 90% 和新值的 10%。有效值范围为 0 到 99(含)。

当前计算结果在 API 的 [上游指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-upstreams) 中以服务器 `health` 对象中的 `header_time` (仅头部)和 `response_time` (完整响应)形式呈现。

#### NOTE
计算中仅包含成功的响应;什么被视为不成功的响应由 [proxy_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-next-upstream)、[fastcgi_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-next-upstream) 、[uwsgi_ignore_headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-next-upstream) 、[scgi_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-next-upstream) 、[memcached_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_memcached.md#memcached-next-upstream) 和 [grpc_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_grpc.md#grpc-next-upstream) 指令确定。此外,:samp:header_time 值仅在接收并处理所有头部时重新计算,而 `response_time` 仅在接收完整响应时重新计算。

<a id="index-14"></a>

<a id="u-server"></a>

### server

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server` address [parameters];   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                         |

定义服务器的地址和其他参数。地址可以指定为域名或 IP 地址,可带可选端口,或指定为 UNIX 域套接字路径(在 `unix:` 前缀之后)。如果未指定端口,则使用端口 80。解析为多个 IP 地址的域名会一次性定义多个服务器。

可以定义以下参数:

| `weight=`number    | 设置服务器的权重。默认值为 1。                                                            |
|--------------------|-----------------------------------------------------------------------------|
| `max_conns=`number | 限制到代理服务器的最大同时活动连接数。默认值为 `0`,表示没有限制。如果服务器组不在 [共享内存区](#u-zone) 中,则该限制按工作进程生效。 |

#### NOTE
启用 [空闲保持连接](#u-keepalive)、多个 [工作进程](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-processes) 和 [共享内存区](#u-zone) 时,到代理服务器的活动和空闲连接总数可能超过 `max_conns` 值。

<a id="max-fails"></a>

`max_fails=`number — 设置在指定的 [fail_timeout](#fail-timeout)
时间段内与服务器通信的失败尝试次数，
达到该次数后服务器将被视为不可用；
之后，将在相同的时间段后再次检查。

失败尝试的定义由 [proxy_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-next-upstream)、
[fastcgi_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-next-upstream)、[uwsgi_ignore_headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-next-upstream)、
[scgi_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-next-upstream)、[memcached_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_memcached.md#memcached-next-upstream) 和
[grpc_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_grpc.md#grpc-next-upstream) 指令确定。

当超过 `max_fails` 时，从 [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe) 的角度来看，
服务器也被视为不可用；客户端请求将不会被定向到该服务器，
直到检查确定其可用为止。

#### NOTE
如果组中的 `server` 指令解析为多个服务器，
其 `max_fails` 设置将分别应用于每个服务器。

如果在解析所有 `server` 指令后，
上游中仅剩一个服务器，
则 `max_fails` 设置不起作用并将被忽略。

| `max_fails=1`   | 默认尝试次数；   |
|-----------------|-----------|
| `max_fails=0`   | 禁用尝试计数。   |

<a id="fail-timeout"></a>

`fail_timeout=`time — 设置时间段，
在此期间必须发生指定次数的与服务器通信失败尝试
（[max_fails](#max-fails)），服务器才会被视为不可用。
然后服务器在相同的时间段内保持不可用状态，
之后再次被检查。

默认值为 10 秒。

#### NOTE
如果组中的 `server` 指令解析为多个服务器，
其 `fail_timeout` 设置将分别应用于每个服务器。

如果在解析所有 `server` 指令后，
上游中仅剩一个服务器，
则 `fail_timeout` 设置不起作用并将被忽略。

| `backup`      | 将服务器标记为备份服务器。当主服务器不可用时，它将接收请求。<br/><br/>如果指定了 [backup_switch (PRO)](#u-backup-switch) 指令，<br/>其主动备份逻辑也将适用。   |
|---------------|--------------------------------------------------------------------------------------------------------------|
| `down`        | 将服务器标记为永久不可用。                                                                                                |
| `drain` (PRO) | 将服务器标记为排空状态；这意味着<br/>它仅接收来自先前通过 [sticky](#u-sticky) 绑定的会话的请求。<br/>否则，行为与 `down` 模式相同。                        |

#### WARNING
`backup` 参数不能与
[hash](#u-hash)、[ip_hash](#u-ip-hash) 和
[random](#u-random) 负载均衡方法一起使用。

`down` 和 `drain` 参数互斥。

<a id="reresolve"></a>

| `resolve`      | 允许监控与域名对应的 IP 地址列表的变化，<br/>并在不重新加载配置的情况下更新它。<br/>该组必须位于<br/>[共享内存](#u-zone) 中；<br/>还必须定义 [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver)。                                                                                                                                                                                                                                                                                                                                                  |
|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `service=`name | 启用 DNS SRV 记录的解析并设置服务名称。要使该参数生效，<br/>必须为服务器指定 `resolve` 参数，<br/>且主机名中不指定端口。<br/><br/>如果服务名称不包含点，则根据 RFC 标准形成名称：<br/>服务名称前加 `_` 前缀，<br/>然后在点后附加 `_tcp`。<br/>因此，服务名称 `http` 将变为 `_http._tcp`。<br/><br/>Angie 通过组合规范化的服务名称和主机名来解析 SRV 记录，<br/>并通过 DNS 获取结果组合的服务器列表，<br/>以及它们的优先级和权重。<br/><br/>- 具有最高优先级的 SRV 记录<br/>  （优先级值最低的记录）<br/>  被解析为主服务器，<br/>  而其他记录成为备份服务器。<br/>  如果 `server` 设置了 `backup`，<br/>  则具有最高优先级的 SRV 记录被解析为备份服务器，<br/>  其他记录被忽略。<br/>- 权重类似于 `server` 指令的 `weight` 参数。<br/>  如果在指令本身和 SRV 记录中都指定了权重，<br/>  则使用指令中设置的权重。 |

在此示例中，对记录 `_http._tcp.backend.example.com` 执行查找：

```nginx
server backend.example.com service=http resolve;
```

| `sid=`id   | 设置组中的服务器 ID。如果未指定该参数，<br/>ID 将设置为 IP 地址和端口或 UNIX 套接字路径的<br/>十六进制 MD5 哈希值。   |
|------------|-----------------------------------------------------------------------------|

<a id="slow-start"></a>

| `slow_start=`time   | 设置返回服务器权重逐步恢复的 [时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)，<br/>当使用 [轮询](#round-robin) 或 [least_conn](#u-least-conn) 方法进行负载均衡时。<br/><br/>如果设置了该参数，<br/>并且从 [max_fails](#max-fails) 和 [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe) 的角度来看，<br/>服务器在故障后再次被认为可运行，<br/>则该服务器会在给定的时间段内逐步增加到其指定的权重。<br/><br/>如果未设置该参数，<br/>在类似情况下，<br/>服务器会立即以其指定的权重开始运行。   |
|---------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

#### NOTE
如果上游中仅指定了一个 `server`，
`slow_start` 将不起作用并会被忽略。

<a id="index-15"></a>

<a id="u-state"></a>

### state (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `state` file;   |
|--------------------------------------------------------------------------------------|-----------------|
| 默认值                                                                                  | —               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream        |

指定一个 file，用于持久化存储上游服务器列表。
当从 [我们的软件包](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 安装时，
会专门创建目录 `/var/lib/angie/state/` （FreeBSD 上为 `/var/db/angie/state/`）
来存储此类文件，并具有适当的访问权限，
在配置中您只需添加文件名：

```nginx
upstream backend {

    zone backend 1m;
    state /var/lib/angie/state/<FILE NAME>;
}
```

这里的服务器列表格式类似于 `server`。
每当通过配置 API 在 [/config/http/upstreams/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config-http-upstreams-servers) 部分更改服务器时，
文件内容就会被修改。
该文件在 Angie 启动或重新加载配置时读取。

#### WARNING
要在 `upstream` 块中使用 `state` 指令，
其中不能有 `server` 指令，
但需要共享内存区（[zone](#u-zone)）。

<a id="index-16"></a>

<a id="u-sticky"></a>

### sticky

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sticky` cookie name [attr=value]...;<br/><br/>`sticky route` $variable...;<br/><br/>`sticky learn` `zone=`zone `create=`$create_var1... `lookup=`$lookup_var1... [`header`] [`norefresh`] [`timeout=`time];<br/><br/>`sticky learn` [`zone=`zone] `lookup=`$lookup_var1... `remote_action=`uri `remote_result=`$remote_var [`norefresh`] [`timeout=`time];   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                                                                                                                                                                                                                                                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                                                                                                                                                                                                                                                                                                                                                      |

配置会话亲和性，以将客户端会话绑定到代理服务器，
模式由第一个参数指定；
要排空配置了 `sticky` 指令的服务器，
可以在 [server](#u-server) 块中使用 `drain` (PRO) 选项。

#### WARNING
`sticky` 指令必须在所有指定特定负载均衡方法的指令之后使用，
否则将不起作用。
如果与 [bind_conn (PRO)](#u-bind-conn) 指令一起使用，
则 `bind_conn` 必须在 `sticky` 之后。

`cookie` 模式

此模式使用 cookie 来管理会话。
适用于已经使用 cookie 进行会话跟踪的场景。

在应用任何粘性之前，第一个客户端请求
会根据配置的负载均衡方法发送到后端服务器。
然后 Angie 会设置一个标识所选服务器的 cookie。

cookie 名称（`name`）由 `sticky` 指令定义，
其值对应于 [sid](#reresolve)
（来自 [server](#u-server) 指令）。
如果设置了 [sticky_secret](#u-sticky-secret)，此值会进一步进行哈希处理。

后续携带此 cookie 的请求会被路由到
由其 [sid](#reresolve) 指定的服务器。
如果该服务器不可用或无法处理请求，
则通过配置的负载均衡方法选择另一个服务器。

您可以在指令中分配 cookie 属性；
默认情况下，仅设置 `path=/`。
属性值可以包含变量。
要删除某个属性，请将其设置为空值：`attr=`。
例如，`sticky cookie path=` 会省略 `path` 属性。

此示例设置一个名为 `srv_id` 的 cookie，有效期为 1 小时，
使用来自变量的域名：

```nginx
upstream backend {
    server backend1.example.com:8080;
    server backend2.example.com:8080;

    sticky cookie srv_id domain=$my_domain max-age=3600;
}
```

`route` 模式

此模式使用预定义的路由标识符，
这些标识符可能来自 URL、cookie 或请求参数。
灵活性较低，但适用于此类标识符已经存在的情况。

后端服务器可能返回一个客户端和服务器都知道的路由 ID。
此值必须与 [sid](#reresolve) 匹配。

后续请求应携带路由 ID，
例如通过 [cookie](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-cookie) 或 [查询参数](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-arg)。

该指令接受一个变量列表来提取路由 ID。
第一个非空值会与 [sid](#reresolve) 进行匹配。

在此示例中，Angie 首先检查 `route` cookie，
然后检查 `route` 查询参数：

```nginx
upstream backend {
    server backend1.example.com:8080 "sid=server 1";
    server backend2.example.com:8080 "sid=server 2";

    sticky route $cookie_route $arg_route;
}
```

`learn` 模式（PRO 1.4.0+）

此模式使用动态生成的密钥将客户端分配给后端。
它很灵活，支持在共享内存中存储会话
以及各种标识符来源。

会话从后端服务器的响应中创建。
`create` 和 `lookup` 定义如何生成和定位会话，
两者都接受多个变量。

会话 ID 是 `create` 中第一个非空变量。
例如，它可能来自响应 cookie。

会话存储在共享内存中，
通过 `zone name:size` 定义。
如果在 `timeout` 时长（默认：1 小时）内未使用，会话将过期。

默认情况下，Angie 在每次使用时刷新会话。
要禁用此功能，请使用 `norefresh`。

客户端请求中的会话 ID 通过 `lookup` 提取，
使用列出的第一个非空变量。
如果找不到，则为新请求。

使用 `header` 可在接收到响应头时创建会话，
而不是在完整响应处理后。

示例：使用 `examplecookie` 创建会话：

```nginx
upstream backend {
    server backend1.example.com:8080;
    server backend2.example.com:8080;

    sticky learn
        create=$upstream_cookie_examplecookie
        lookup=$cookie_examplecookie
        zone=client_sessions:1m;
}
```

带 `remote_action` 的 `learn` 模式（PRO 1.8.0+）

使用 `remote_action` 和 `remote_result`
通过外部会话存储管理会话 ID。
共享内存区域充当缓存；
外部存储具有权威性。
`create` 与 `remote_action` 不兼容。

会话在 `timeout` （默认：1 小时）后过期，
与 `remote_action` 无关。

默认情况下，Angie 在每次使用时刷新会话 TTL。
使用 `norefresh` 可禁用此功能。

`zone` 在使用 `remote_action` 时是可选的。
如果没有它，Angie 总是查询外部存储。

基本流程：

- 从第一个非空的 `lookup` 变量中提取会话 ID。
  如果没有，则回退到标准负载均衡。
- 如果设置了 `zone` 且会话存在，则使用它并停止。
- 如果没有会话或没有 zone，选择一个服务器并向
  `remote_action` 端点发起 HTTP 子请求，包含：
  - 会话 ID（[$sticky_sessid](#v-sticky-sessid)）；
  - 来自 `sid=` 或 [$sticky_sid](#v-sticky-sid) 的服务器 ID。

  通过 HTTP 头（通过 [proxy_set_header](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-set-header)）发送这些信息。
- 远程存储响应：
  - 200/201/204 确认会话；如果设置了 `zone` 则缓存它。
  - 409 表示冲突（如果设置了 `zone`）— 会话链接到另一个服务器。
    使用 `remote_result` 提取更正后的服务器 ID。
  - 其他状态码或缺少服务器 ID — 回退到原始服务器。

`remote_result` 使用 `upstream_http_*` 变量
从远程存储的响应中读取头部。

示例：会话 ID 来自 `$cookie_bar`，
通过 `$upstream_http_x_sticky_sid` 确认：

```nginx
http {

    upstream u1 {
        server srv1;
        server srv2;

        sticky learn zone=sz:1m
            lookup=$cookie_bar
            remote_action=/remote_session
            remote_result=$upstream_http_x_sticky_sid;

        zone z 1m;
    }

    server {

        listen localhost;

        location / {
            proxy_pass http://u1/;
        }

        location /remote_session {
            internal;
            proxy_set_header X-Sticky-Sessid $sticky_sessid;
            proxy_set_header X-Sticky-Sid $sticky_sid;
            proxy_set_header X-Sticky-Last $msec;
            proxy_pass http://remote;
        }
    }
}
```

以下是一个简化的配置示例。
远程存储在 `X-Sid` 头中返回会话 ID，
从而确认或覆盖 Angie 的选择：

```nginx
http {

    proxy_cache_path c1 keys_zone=s1:1m;

    upstream tc_0 {
        server 10.0.0.1 sid=web-server-01;
        server 10.0.0.2 sid=web-server-02;

        sticky learn
            lookup=$arg_id
            remote_action=@create_session
            remote_result=$upstream_http_x_sid;
    }

    server {
        listen 127.0.0.1:8080;

        location / {
            proxy_pass http://tc_0/;
        }

        # Request to the remote session store
        location @create_session {
            internal;

            proxy_set_header X-Sticky-Sessid $sticky_sessid;
            proxy_set_header X-Sticky-Sid    $sticky_sid;
            proxy_set_header X-Sticky-Last   $msec;

            proxy_pass http://session_backend;

            proxy_connect_timeout 1s;
            proxy_read_timeout    1s;

            proxy_cache        s1;
            proxy_cache_valid  200 1d;
            proxy_cache_key    "$scheme$proxy_host$request_uri$sticky_sessid";
        }
    }
}
```

响应示例：

```none
HTTP/1.1 200 OK
...
X-Sid: web-server-01
X-Session-Backend: backend-pool-1
```

生成的 Angie 变量：

- `$upstream_http_x_sid` → `web-server-01`
- `$upstream_http_x_session_backend` → `backend-pool-1`

`remote_result` 将使用 `web-server-01`
来选择匹配的 `sid`。

`sticky` 指令遵循上游服务器状态：

- 标记为 `down` 或失败的服务器会被排除。
- 超过 `max_conns` 限制的服务器会被跳过。
- `drain` 服务器（PRO）在 `sticky` 模式下当标识符匹配时仍可能被选中用于新会话。
- 恢复的服务器会自动重新使用。

您可以使用
[sticky_secret](#u-sticky-secret) 和 [sticky_strict](#u-sticky-strict) 进一步调整行为。
如果粘性失败且 `sticky_strict` 关闭，
则使用回退负载均衡；
如果开启，则拒绝请求。

`sticky` 中使用的每个 `zone` 必须专属于单个 `upstream`。
区域不能在多个 `upstream` 块之间共享。

<a id="index-17"></a>

<a id="u-sticky-secret"></a>

### sticky_secret

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sticky_secret` string;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | —                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                  |

将 string 作为盐值添加到 MD5 哈希函数中，
用于 `cookie` 和 `route` 模式下的 [sticky](#u-sticky) 指令。
string 可以包含变量，例如 `$remote_addr`：

```nginx
upstream backend {
    server backend1.example.com:8080;
    server backend2.example.com:8080;

    sticky cookie cookie_name;
    sticky_secret my_secret.$remote_addr;
}
```

盐值会附加到被哈希的值后面；
要独立验证哈希机制：

```console
$ echo -n "<VALUE><SALT>" | md5sum
```

<a id="index-18"></a>

<a id="u-sticky-strict"></a>

### sticky_strict

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sticky_strict` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `sticky_strict off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                        |

启用时，如果所需的服务器不可用，
会导致 Angie 向客户端返回 HTTP 502 错误，
而不是像上游中没有可用服务器时那样使用任何其他可用服务器。

<a id="index-19"></a>

<a id="u-upstream"></a>

### upstream

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `upstream` name { ... }   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | —                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                      |

定义一组服务器。服务器可以监听不同的端口。此外，可以混合使用监听 TCP 和 UNIX 域套接字的服务器。

示例：

```nginx
upstream backend {
    server backend1.example.com weight=5;
    server 127.0.0.1:8080       max_fails=3 fail_timeout=30s;
    server backup1.example.com  backup;
}
```

<a id="round-robin"></a>

默认情况下,请求使用加权轮询均衡方法在服务器之间分配。在上面的示例中,每 7 个请求将按如下方式分配:5 个请求发送到 backend1.example.com,第二个和第三个服务器各接收一个请求。

如果在与服务器通信期间发生错误,请求将被传递到下一个服务器,依此类推,直到尝试所有正常运行的服务器。如果无法从任何服务器获得成功响应,客户端将收到与最后一个服务器通信的结果。

<a id="index-20"></a>

<a id="u-zone"></a>

### zone

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `zone` name [size];   |
|--------------------------------------------------------------------------------------|-----------------------|
| 默认值                                                                                  | —                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream              |

定义共享内存区域的名称和大小,该区域保存在工作进程之间共享的组配置和运行时状态。多个组可以共享同一个区域。在这种情况下,只需指定一次大小即可。

#### NOTE
只有在配置的 `size` 不变时，重载才会保留区域内容。
任何大小变更——增大或减小——都会导致区域被重新创建为空。

<a id="built-in-variables-14"></a>

## 内置变量

`http_upstream` 模块支持以下内置变量:

<a id="v-sticky-sessid"></a>

### `$sticky_sessid`

与 [sticky](#u-sticky) 中的 `remote_action` 一起使用;
存储从 `lookup` 获取的初始会话 ID。

<a id="v-sticky-sid"></a>

### `$sticky_sid`

与 [sticky](#u-sticky) 中的 `remote_action` 一起使用;
存储先前与会话关联的服务器 ID。

<a id="v-upstream-addr"></a>

### `$upstream_addr`

存储上游服务器的 IP 地址和端口,或 UNIX 域套接字的路径。如果在请求处理期间联系了多个服务器,它们的地址用逗号分隔,例如:

> 192.168.1.1:80, 192.168.1.2:80, unix:/tmp/sock

如果发生从一个服务器组到另一个服务器组的内部重定向(由 `X-Accel-Redirect` 或 [error_page](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#error-page) 发起),则来自不同组的服务器地址用冒号分隔,例如:

> 192.168.1.1:80, 192.168.1.2:80, unix:/tmp/sock : 192.168.10.1:80, 192.168.10.2:80

如果无法选择服务器,该变量保存 [服务器组](#u-upstream) 的 名称。

<a id="v-upstream-bytes-received"></a>

### `$upstream_bytes_received`

从上游服务器接收的字节数。来自多个连接的值用逗号和冒号分隔,类似于 [$upstream_addr](#v-upstream-addr) 变量中的地址。

<a id="v-upstream-bytes-sent"></a>

### `$upstream_bytes_sent`

发送到上游服务器的字节数。来自多个连接的值用逗号和冒号分隔,类似于 [$upstream_addr](#v-upstream-addr) 变量中的地址。

<a id="v-upstream-cache-status"></a>

### `$upstream_cache_status`

保存访问响应缓存的状态。状态可以是
`MISS`、`BYPASS`、`EXPIRED`、`STALE`、`UPDATING`、
`REVALIDATED` 或 `HIT`:

- `MISS`:在缓存中未找到响应,
  请求被传递到上游服务器。
- `BYPASS`:绕过缓存,
  请求直接传递到上游服务器。
- `EXPIRED`:缓存的响应已过期,
  向上游服务器传递新请求以更新内容。
- `STALE`:缓存的响应已过期,
  但仍然提供给客户端,
  直到最终从上游服务器更新内容。
- `UPDATING`:缓存的响应已过期,
  但仍然提供给客户端,
  同时正在进行从上游服务器的更新。
- `REVALIDATED`:缓存的响应已过期,
  但已成功重新验证,
  无需从上游服务器更新。
- `HIT`:响应从缓存中获取。

如果请求绕过缓存而未访问它,
则不设置该变量。

<a id="v-upstream-cache-key"></a>

### `$upstream_cache_key`

包含用于请求的缓存键。

<a id="v-upstream-connect-time"></a>

### `$upstream_connect_time`

保存与上游服务器建立连接所花费的时间;时间以秒为单位保存,具有毫秒分辨率。在 SSL 的情况下,包括握手所花费的时间。多个连接的时间用逗号和冒号分隔,类似于 [$upstream_addr](#v-upstream-addr) 变量中的地址。

<a id="v-upstream-cookie"></a>

### `$upstream_cookie_<name>`

上游服务器在 `Set-Cookie` 响应头字段中发送的指定名称的 cookie。仅保存最后一个服务器响应中的 cookie。

<a id="v-upstream-header-time"></a>

### `$upstream_header_time`

保存从上游服务器接收响应头所花费的时间;时间以秒为单位保存,具有毫秒分辨率。多个响应的时间用逗号和冒号分隔,类似于 [$upstream_addr](#v-upstream-addr) 变量中的地址。

<a id="v-upstream-http"></a>

### `$upstream_http_<name>`

保存服务器响应头字段。例如,:samp:Server 响应头字段可通过 `$upstream_http_server` 变量获取。将头字段名称转换为变量名称的规则与以 `$http_` 前缀开头的变量相同。仅保存最后一个服务器响应中的头字段。

<a id="v-upstream-request-method"></a>

### `$upstream_request_method`

用于上游请求的请求方法。当缓存将 `HEAD` 转换为 `GET` 或设置了 [proxy_method](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-method) 时,它可能与客户端请求方法不同。

<a id="v-upstream-queue-time"></a>

### `$upstream_queue_time`

保存请求在下一次服务器选择之前在 [队列](#u-queue) 中花费的时间;
时间以秒为单位保存,具有毫秒分辨率。
多次尝试的时间用逗号和冒号分隔,
类似于 [$upstream_addr](#v-upstream-addr) 变量中的地址。

<a id="v-upstream-response-length"></a>

### `$upstream_response_length`

保存从上游服务器获取的响应的长度;长度以字节为单位保存。多个响应的长度用逗号和冒号分隔,类似于 [$upstream_addr](#v-upstream-addr) 变量中的地址。

<a id="v-upstream-response-time"></a>

### `$upstream_response_time`

保存从上游服务器接收响应所花费的时间;时间以秒为单位保存,具有毫秒分辨率。多个响应的时间用逗号和冒号分隔,类似于 [$upstream_addr](#v-upstream-addr) 变量中的地址。

<a id="v-upstream-status"></a>

### `$upstream_status`

保存从上游服务器获取的响应的状态码。多个响应的状态码用逗号和冒号分隔,类似于 [$upstream_addr](#v-upstream-addr) 变量中的地址。如果无法选择服务器,该变量保存 502(Bad Gateway)状态码。

<a id="v-upstream-sticky-status"></a>

### `$upstream_sticky_status`

粘性请求的状态。

| `""`   | 请求发送到未启用粘性的上游。             |
|--------|----------------------------|
| `NEW`  | 请求不包含粘性信息。                 |
| `HIT`  | 带有粘性信息的请求发送到所需的服务器。        |
| `MISS` | 带有粘性信息的请求发送到由负载均衡算法选择的服务器。 |

来自多个连接的状态用逗号和冒号分隔,
类似于 [$upstream_addr](#v-upstream-addr) 变量中的地址。

<a id="v-upstream-trailer"></a>

### `$upstream_trailer_<name>`

保存从上游服务器获取的响应末尾的字段。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_upstream_probe.md

<!-- review: finished -->

<a id="http-upstream-probe"></a>

# Upstream Probe

该模块为 [Upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 实现主动健康探测。

<a id="configuration-example-46"></a>

## 配置示例

```nginx
server {
    listen ...;

    location /backend {
        ...
        proxy_pass http://backend;

        upstream_probe backend_probe
            uri=/probe
            port=10004
            interval=5s
            test=$good
            essential
            fails=3
            passes=3
            max_body=10m
            mode=idle;
    }
}
```

<a id="directives-49"></a>

## 指令

<a id="index-0"></a>

<a id="u-upstream-probe"></a>

### upstream_probe (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `upstream_probe` name [`uri=`address] [`port=`number] [`interval=`time] [`method=`method] [`test=`condition] [`essential` [`persistent`]] [`fails=`number] [`passes=`number] [`max_body=`size] [`mode=``always` | `idle` | `onfail`] [`ping`] [`ping_timeout=`time];   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                                                                                                                                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location                                                                                                                                                                                                                                                               |

为 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 组中的服务器定义主动健康探测，这些上游组在与 `upstream_probe` 指令相同的 `location` 上下文中通过 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass)、[uwsgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-pass) 和类似指令指定。Angie 根据指定的参数定期向上游组中的每个服务器执行请求。

如果对服务器的请求成功，考虑到 `upstream_probe` 指令的所有参数设置以及控制其定义所在的 `location` 上下文如何使用上游的所有参数，则服务器通过探测。这包括 [proxy_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-next-upstream) 和 [uwsgi_ignore_headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-next-upstream) 指令等，以及 [proxy_set_header](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-set-header) 等。

要使用探测，上游必须具有共享内存区域（[zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-zone)）。一个上游可以配置多个探测。

接受以下参数：

| `name`               | 探测的必需名称。                                                                                                                                                                                                                                 |
|----------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `uri`                | 要附加到 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass)、[uwsgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-pass) 等参数的请求 URI。默认为 `/`。 |
| `port`               | 探测请求的备用端口号。                                                                                                                                                                                                                              |
| `interval`           | 探测之间的间隔。默认为 `5s`。                                                                                                                                                                                                                        |
| `method`             | 探测请求的 HTTP 方法。默认为 `GET`。                                                                                                                                                                                                                 |
| `test`               | 在请求期间要检查的条件；定义为包含变量的字符串。如果变量替换产生 `""` 或 `"0"`，则探测失败。                                                                                                                                                                                     |
| `essential`          | 如果设置，服务器的初始状态需要验证，在通过探测之前不会将客户端请求转发给它。                                                                                                                                                                                                   |
| `persistent`         | 设置此参数需要首先启用 `essential`；在 [配置重新加载](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile-reloading) 之前正常工作的 `persistent` 服务器无需首先通过此探测即可开始接收请求。                                                                    |
| `fails`              | 使服务器变为不健康状态的连续失败请求数。默认为 1。                                                                                                                                                                                                               |
| `passes`             | 使服务器变为健康状态的连续成功请求数。默认为 1。                                                                                                                                                                                                                |
| `max_body`           | 响应正文的最大内存量。默认为 `256k`。                                                                                                                                                                                                                   |
| `mode`               | 探测模式，取决于服务器的健康状态：<br/><br/>- `always` — 无论服务器状态如何都进行探测；<br/>- `idle` — 探测影响不健康的服务器以及自上次客户端请求以来已经过 `interval` 的服务器。<br/>- `onfail` — 仅探测不健康的服务器。<br/><br/>默认为 `always`。                                                                   |
| `ping` (PRO)         | 使用 ICMP 回显请求而不是 HTTP 探测。需要使用 `--with-http_upstream_probe_icmp` 构建 Angie。与 `test`、`port`、`method` 或 `uri` 不兼容。                                                                                                                            |
| `ping_timeout` (PRO) | 等待 ICMP 回显应答的超时时间。默认为 `1s`。                                                                                                                                                                                                              |

示例：

```nginx
upstream backend {
    zone backend 1m;

    server backend1.example.com;
    server backend2.example.com;
}

map $upstream_status $good {
    200     "1";
}

server {
    listen ...;

    location /backend {
        ...
        proxy_pass http://backend;

        upstream_probe backend_probe
            uri=/probe
            port=10004
            interval=5s
            test=$good
            essential
            persistent
            fails=3
            passes=3
            max_body=10m
            mode=idle;
    }
}
```

探测操作的详细信息：

- 最初，服务器在通过为其配置的\*所有\* `essential` 探测之前不会接收客户端请求（如果配置已重新加载且服务器在此之前被认为是健康的，则跳过 `persistent` 探测）。如果没有此类探测，则认为服务器是健康的。
- 如果为服务器配置的\*任何\*探测达到其 `fails` 阈值，或者服务器本身达到 [max_fails](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#max-fails) 阈值，则认为服务器不健康且不会接收客户端请求。
- 要使不健康的服务器再次被认为是健康的，为其配置的\*所有\*探测必须达到各自的 `passes` 阈值；之后，考虑 [max_fails](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#max-fails) 阈值。

<a id="built-in-variables-15"></a>

## 内置变量

`http_upstream_probe` 模块支持以下内置变量：

<a id="v-upstream-probe"></a>

### `$upstream_probe` (PRO)

当前活动的 [upstream_probe](#u-upstream-probe) 的名称。

<a id="v-upstream-probe-body"></a>

### `$upstream_probe_body` (PRO)

在 [upstream_probe](#u-upstream-probe) 期间接收的服务器响应正文；其大小受 `max_body` 限制。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_userid.md

<!-- review: finished -->

<a id="http-userid"></a>

# UserID

该模块设置适合客户端识别的 cookies。接收到的和设置的 cookies 可以使用内置变量 [$uid_got](#v-uid-got) 和 [$uid_set](#v-uid-set) 进行记录。该模块与 Apache 的 [mod_uid](http://www.lexa.ru/programs/mod-uid.html) 模块兼容。

<a id="configuration-example-47"></a>

## 配置示例

```nginx
userid         on;
userid_name    uid;
userid_domain  example.com;
userid_path    /;
userid_expires 365d;
userid_p3p     'policyref="/w3c/p3p.xml", CP="CUR ADM OUR NOR STA NID"';
```

<a id="directives-50"></a>

## 指令

<a id="index-0"></a>

<a id="userid"></a>

### userid

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `userid` `on` | `v1` | `log` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `userid off;`                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

启用或禁用设置 cookies 和记录接收到的 cookies：

| `on`   | 启用设置版本 2 的 cookies 和记录接收到的 cookies；   |
|--------|---------------------------------------|
| `v1`   | 启用设置版本 1 的 cookies 和记录接收到的 cookies；   |
| `log`  | 禁用设置 cookies，但启用记录接收到的 cookies；       |
| `off`  | 禁用设置 cookies 和记录接收到的 cookies。         |

<a id="index-1"></a>

<a id="userid-domain"></a>

### userid_domain

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `userid_domain` name | `none`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `userid_domain none;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

定义设置 cookies 的域。参数 `none` 禁用设置 cookies 的域。

<a id="index-2"></a>

<a id="userid-expires"></a>

### userid_expires

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `userid_expires` time | `max` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `userid_expires off;`                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

设置浏览器应保持 cookies 的时间。参数 `max` 会导致 cookie 在"2037年12月31日 23:55:55 GMT"过期。参数 `off` 会导致 cookie 在浏览器会话结束时过期。

<a id="index-3"></a>

<a id="userid-flags"></a>

### userid_flags

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `userid_flags` `off` | flag ...;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `userid_flags off;`                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

如果参数不是 `off`，则定义一个或多个 cookies 的附加标志： `secure`, `httponly`, `samesite=strict`, `samesite=lax`, `samesite=none`。

<a id="index-4"></a>

<a id="userid-mark"></a>

### userid_mark

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `userid_mark` letter | digit | = | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `userid_mark off;`                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

如果参数不是 `off`，则启用 cookie 标记机制并设置用作标记的字符。该机制用于在保持客户端标识符的同时添加或更改 [userid_p3p](#userid-p3p) 和/或 cookies 过期时间。标记可以是任何英文字母（区分大小写）、数字或"="字符。

如果设置了标记，则将其与传递在 cookie 中的客户端标识符的 base64 表示的第一个填充符号进行比较。如果它们不匹配，则会使用指定的标记、过期时间和:samp:P3P 头重新发送 cookie。

<a id="index-5"></a>

<a id="userid-name"></a>

### userid_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `userid_name` name;    |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | `userid_name uid;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

设置 cookie 名称。

<a id="index-6"></a>

<a id="userid-p3p"></a>

### userid_p3p

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `userid_p3p` string | `none`;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `userid_p3p none;`              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

设置将与 cookie 一起发送的:samp:P3P 头字段的值。如果指令设置为特殊值 `none`，则在响应中将不发送:samp:P3P 头。

<a id="index-7"></a>

<a id="userid-path"></a>

### userid_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `userid_path` path;    |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | `userid_path /;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

定义设置 cookies 的路径。

<a id="index-8"></a>

<a id="userid-service"></a>

### userid_service

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `userid_service` number;     |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `userid_service 服务器的 IP 地址;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

如果由多个服务器（服务）发出标识符，则应为每个服务分配其自己的 `number` 以确保客户端标识符的唯一性。对于版本 1 的 cookies，默认值为零。对于版本 2 的 cookies，默认值为由服务器的 IP 地址的最后四个八位字节组成的数字。

<a id="built-in-variables-16"></a>

## 内置变量

<a id="v-uid-got"></a>

### `$uid_got`

cookie 名称和接收到的客户端标识符。

<a id="v-uid-reset"></a>

### `$uid_reset`

如果变量设置为非空字符串且不是 `0`，则客户端标识符将被重置。特殊值 `log` 还会导致关于重置标识符的消息输出到 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log)。

<a id="v-uid-set"></a>

### `$uid_set`

cookie 名称和发送的客户端标识符。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_uwsgi.md

<!-- review: finished -->

<a id="http-uwsgi"></a>

# uWSGI

允许将请求传递给 uWSGI 服务器。

<a id="configuration-example-48"></a>

## 配置示例

```nginx
location / {
    include    uwsgi_params;
    uwsgi_pass localhost:9000;
}
```

<a id="directives-51"></a>

## 指令

<a id="index-0"></a>

<a id="uwsgi-bind"></a>

### uwsgi_bind

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_bind` address [`transparent`] | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------|
| 默认值                                                                                  | —                                               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                          |

使到 uWSGI 服务器的出站连接源自指定的本地 IP 地址和可选端口。参数值可以包含变量。特殊值 `off` 取消从上一级配置继承的 uwsgi_bind 指令的效果,允许系统自动分配本地 IP 地址和端口。

`transparent` 参数允许到 uWSGI 服务器的出站连接源自非本地 IP 地址,例如,源自客户端的真实 IP 地址:

```nginx
uwsgi_bind $remote_addr transparent;
```

为了使此参数生效,通常需要以 [超级用户](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 权限运行 Angie 工作进程。在 Linux 上不需要这样做,因为如果指定了 `transparent` 参数,工作进程会从主进程继承 CAP_NET_RAW 能力。

#### NOTE
需要配置内核路由表以拦截来自 uWSGI 服务器的网络流量。

<a id="index-1"></a>

<a id="uwsgi-buffer-size"></a>

### uwsgi_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_buffer_size` size;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `uwsgi_buffer_size 4k|8k;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

设置用于读取从 uWSGI 服务器接收的响应的第一部分的缓冲区大小。这部分通常包含一个小的响应头。默认情况下,缓冲区大小等于一个内存页。根据平台不同,这可能是 4K 或 8K。但可以设置得更小。

<a id="index-2"></a>

<a id="uwsgi-buffering"></a>

### uwsgi_buffering

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_buffering` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `uwsgi_buffering on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

启用或禁用来自 uWSGI 服务器的响应的缓冲。

| `on`   | Angie 尽快从 uWSGI 服务器接收响应,将其保存到由 [uwsgi_buffer_size](#uwsgi-buffer-size) 和 [uwsgi_buffers](#uwsgi-buffers) 指令设置的缓冲区中。向客户端发送会并行进行: 已填满的缓冲区会被传递用于发送,但其总大小受 [uwsgi_busy_buffers_size](#uwsgi-busy-buffers-size) 限制。如果缓冲区未被完全填满,则不会被传递用于发送,除非它包含响应的最后一部分。因此,当需要立即传递每几个字节时,缓冲读取并不适合。如果整个响应无法放入内存,则可以将其一部分保存到磁盘上的 [临时文件](#uwsgi-temp-path) 中。写入临时文件由 [uwsgi_max_temp_file_size](#uwsgi-max-temp-file-size) 和 [uwsgi_temp_file_write_size](#uwsgi-temp-file-write-size) 指令控制。   |
|--------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 响应在接收到时立即传递给客户端。Angie 以"读取 — 发送"的循环工作,不会等待缓冲区完全填满: 例如,从 4K 缓冲区读取的 10 字节会立即发送。同时,如果整个响应可以放入缓冲区,Angie 可以完整读取它。Angie 一次可以从服务器接收的数据的最大大小由 [uwsgi_buffer_size](#uwsgi-buffer-size) 指令设置。使用 `off` 时,:ref:uwsgi_limit_rate 不生效。                                                                                                                                                                                                                                               |

也可以通过在 `X-Accel-Buffering` 响应头字段中传递 "yes" 或 "no" 来启用或禁用缓冲。可以使用 [uwsgi_ignore_headers](#uwsgi-ignore-headers) 指令禁用此功能。

<a id="index-3"></a>

<a id="uwsgi-buffers"></a>

### uwsgi_buffers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_buffers` number size;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `uwsgi_buffers 8 4k | 8k;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

设置用于从 uWSGI 服务器读取响应的缓冲区的数量和大小,针对单个连接。

默认情况下,缓冲区大小等于一个内存页。根据平台不同,这可能是 4K 或 8K。

<a id="index-4"></a>

<a id="uwsgi-busy-buffers-size"></a>

### uwsgi_busy_buffers_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_busy_buffers_size` size;     |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `uwsgi_busy_buffers_size 8k | 16k;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

当启用来自 uWSGI 服务器的响应的 [缓冲](#uwsgi-buffering) 时,限制在响应尚未完全读取时可以忙于向客户端发送响应的缓冲区的总大小。同时,其余的缓冲区可用于读取响应,如果需要,还可以将部分响应缓冲到临时文件中。

默认情况下,大小受 [uwsgi_buffer_size](#uwsgi-buffer-size) 和 [uwsgi_buffers](#uwsgi-buffers) 指令设置的两个缓冲区大小的限制。

<a id="index-5"></a>

<a id="uwsgi-cache"></a>

### uwsgi_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache` zone | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `uwsgi_cache off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

定义用于缓存的共享内存区域。同一区域可以在多个地方使用。参数值可以包含变量。

| `off`   | 禁用从上一级配置继承的缓存。   |
|---------|------------------|

<a id="index-6"></a>

<a id="uwsgi-cache-background-update"></a>

### uwsgi_cache_background_update

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_background_update` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------|
| 默认值                                                                                  | `uwsgi_cache_background_update off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                          |

允许启动后台子请求来更新过期的缓存项,同时将过期的缓存响应返回给客户端。

#### WARNING
注意,必须 [允许](#uwsgi-cache-use-stale-updating) 在更新过期缓存响应时使用它。

<a id="index-7"></a>

<a id="uwsgi-cache-bypass"></a>

### uwsgi_cache_bypass

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_bypass` ...;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

定义不从缓存中获取响应的条件。如果字符串参数中至少有一个值不为空且不等于 "0",则不会从缓存中获取响应:

```nginx
uwsgi_cache_bypass $cookie_nocache $arg_nocache$arg_comment;
uwsgi_cache_bypass $http_pragma    $http_authorization;
```

可以与 [uwsgi_no_cache](#uwsgi-no-cache) 指令一起使用。

<a id="index-8"></a>

<a id="uwsgi-cache-key"></a>

### uwsgi_cache_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_key` string;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

定义缓存的键,例如

```nginx
uwsgi_cache_key localhost:9000$request_uri;
```

<a id="index-9"></a>

<a id="uwsgi-cache-lock"></a>

### uwsgi_cache_lock

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_lock` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `uwsgi_cache_lock off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

启用后,一次只允许一个请求通过将请求传递给 uWSGI 服务器来填充根据 [uwsgi_cache_key](#uwsgi-cache-key) 指令标识的新缓存元素。同一缓存元素的其他请求将等待响应出现在缓存中或此元素的缓存锁被释放,最长等待时间由 [uwsgi_cache_lock_timeout](#uwsgi-cache-lock-timeout) 指令设置。

<a id="index-10"></a>

<a id="uwsgi-cache-lock-age"></a>

### uwsgi_cache_lock_age

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_lock_age` time;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `uwsgi_cache_lock_age 5s;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

如果传递给 uWSGI 服务器以填充新缓存元素的最后一个请求在指定时间内未完成,则可以再传递一个请求给 uWSGI 服务器。

<a id="index-11"></a>

<a id="uwsgi-cache-lock-timeout"></a>

### uwsgi_cache_lock_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_lock_timeout` time;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `uwsgi_cache_lock_timeout 5s;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

设置 [uwsgi_cache_lock](#uwsgi-cache-lock) 的超时时间。当时间到期时,请求将被传递给 uWSGI 服务器,但是响应不会被缓存。

<a id="index-12"></a>

<a id="uwsgi-cache-max-range-offset"></a>

### uwsgi_cache_max_range_offset

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_max_range_offset` number;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | —                                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

为字节范围请求设置偏移量(以字节为单位)。如果范围超出偏移量,范围请求将被传递到 uWSGI 服务器,并且响应不会被缓存。

<a id="index-13"></a>

<a id="uwsgi-cache-methods"></a>

### uwsgi_cache_methods

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_methods` `GET` | `HEAD` | `POST` ...;   |
|--------------------------------------------------------------------------------------|------------------------------------------------------|
| 默认值                                                                                  | `uwsgi_cache_methods GET HEAD;`                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                               |

如果客户端请求方法在此指令中列出,则响应将被缓存。"GET" 和 "HEAD" 方法始终会添加到列表中,但建议显式指定它们。另请参阅 [uwsgi_no_cache](#uwsgi-no-cache) 指令。

<a id="index-14"></a>

<a id="uwsgi-cache-min-uses"></a>

### uwsgi_cache_min_uses

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_min_uses` number;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `uwsgi_cache_min_uses 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

设置在多少次请求后响应将被缓存。

#### WARNING
缓存元数据存储在共享内存中。手动删除缓存文件不会重置计数器，可能导致不可预测的行为。要完全重置缓存，请停止服务器，删除缓存目录，然后重新启动。

#### NOTE
第三方缓存清除模块（例如 [缓存清除](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge)）仅删除文件，但不会重置 uwsgi_cache_min_uses 计数器。该指令旨在保护缓存免受不频繁请求的污染，在清除时重置计数器可能会对性能产生负面影响。

<a id="index-15"></a>

<a id="uwsgi-cache-path"></a>

### uwsgi_cache_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_path` path [`levels=`levels] [`use_temp_path=``on` | `off`] `keys_zone=`name:size [`inactive=`time] [`max_size=`size] [`min_free=`size] [`manager_files=`number] [`manager_sleep=`time] [`manager_threshold=`time] [`loader_files=`number] [`loader_sleep=`time] [`loader_threshold=`time];   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                                                                                                                                                                                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                                                                                                                                                                                                                                                                                                       |

设置缓存的路径和其他参数。缓存数据存储在文件中。缓存中的文件名是对 [缓存键](#uwsgi-cache-key) 应用 MD5 函数的结果。

`levels` 参数定义缓存的层次结构级别：从 1 到 3，每个级别接受值 1 或 2。例如，在以下配置中：

```nginx
uwsgi_cache_path /data/angie/cache levels=1:2 keys_zone=one:10m;
```

缓存中的文件名将如下所示：

```nginx
/data/angie/cache/c/29/b7f54b2df7773722d382f4809d65029c
```

缓存的响应首先写入临时文件，然后重命名该文件。临时文件和缓存可以放在不同的文件系统上。但是，请注意，在这种情况下，文件将在两个文件系统之间复制，而不是进行廉价的重命名操作。因此，建议对于任何给定位置，缓存和存放临时文件的目录都放在同一文件系统上。

临时文件的目录根据 `use_temp_path` 参数设置。

| `on`   | 如果省略此参数或将其设置为值 on，则将使用由给定位置的 [uwsgi_temp_path](#uwsgi-temp-path) 指令设置的目录。   |
|--------|-----------------------------------------------------------------------------|
| `off`  | 临时文件将直接放在缓存目录中。                                                             |

此外,所有活动键和有关数据的信息都存储在共享内存区域中,其名称和大小由 `keys_zone` 参数配置。一兆字节的区域可以存储大约 8 千个键。缓存元数据存储在共享内存中。

在 `inactive` 参数指定的时间内未被访问的缓存数据将从缓存中删除,无论其新鲜度如何。

默认情况下,:samp:inactive 设置为 10 分钟。

一个特殊的\*\*缓存管理器\*\*进程监控最大缓存大小和缓存所在文件系统上的最小可用空间量,当超过大小或没有足够的可用空间时,它会删除最近最少使用的数据。数据以迭代方式删除。

| `max_size`          | 缓存大小的最大阈值                         |
|---------------------|-----------------------------------|
| `min_free`          | 缓存所在文件系统上可用空间的最小阈值                |
| `manager_files`     | 一次迭代中删除的最大缓存项数<br/><br/>默认值:`100` |
| `manager_threshold` | 限制一次迭代的时间<br/><br/>默认值:`200` 毫秒   |
| `manager_sleep`     | 迭代之间保持暂停的时间<br/><br/>默认值:`50` 毫秒  |

Angie 启动一分钟后,会激活一个特殊的\*\*缓存加载器\*\*进程,该进程将存储在文件系统上的先前缓存数据的信息加载到缓存区域中。加载也以迭代方式进行。

| `loader_files`     | 一次迭代中加载的最大缓存项数<br/><br/>默认值:`100`   |
|--------------------|-------------------------------------|
| `loader_threshold` | 限制一次迭代的时间<br/><br/>默认值:`200` 毫秒     |
| `loader_sleep`     | 迭代之间保持暂停的时间<br/><br/>默认值:`50` 毫秒    |

<a id="index-16"></a>

<a id="uwsgi-cache-revalidate"></a>

### uwsgi_cache_revalidate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_revalidate` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `uwsgi_cache_revalidate off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

启用使用带有 `If-Modified-Since` 和 `If-None-Match` 头字段的条件请求重新验证过期的缓存项。

<a id="index-17"></a>

<a id="uwsgi-cache-use-stale"></a>

### uwsgi_cache_use_stale

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_use_stale` `error` | `timeout` | `invalid_header` | `updating` | `http_500` | `http_503` |  `http_403` | `http_404` | `http_429` | `off` ...;   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `uwsgi_cache_use_stale off;`                                                                                                                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                                       |

确定在哪些情况下可以使用过期的缓存响应。该指令的参数与 [uwsgi_ignore_headers](#uwsgi-next-upstream) 指令的参数匹配。

| `error`    | 如果无法选择 uwsgi 服务器来处理请求,则允许使用过期的缓存响应。                            |
|------------|----------------------------------------------------------------|
| `updating` | 附加参数,如果当前正在更新过期的缓存响应,则允许使用它。这可以最大限度地减少更新缓存数据时对 uwsgi 服务器的访问次数。 |

也可以直接在响应头中启用使用过期的缓存响应,在响应变为过期后的指定秒数内:

* `Cache-Control` 头字段的 [stale-while-revalidate](https://datatracker.ietf.org/doc/html/rfc5861#section-3) 扩展允许在当前正在更新过期的缓存响应时使用它。
* `Cache-Control` 头字段的 [stale-if-error](https://datatracker.ietf.org/doc/html/rfc5861#section-4) 扩展允许在发生错误时使用过期的缓存响应。

#### NOTE
此方法的优先级低于设置指令参数。

为了在填充新缓存元素时最大限度地减少对 uwsgi 服务器的请求数,可以使用 [uwsgi_cache_lock](#uwsgi-cache-lock) 指令。

<a id="index-18"></a>

<a id="uwsgi-cache-valid"></a>

### uwsgi_cache_valid

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_cache_valid` [code ...] time;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

为不同的响应代码设置缓存时间。例如,以下指令

```nginx
uwsgi_cache_valid 200 302 10m;
uwsgi_cache_valid 404      1m;
```

为代码 200 和 302 的响应设置 10 分钟的缓存,为代码 404 的响应设置 1 分钟的缓存。

如果仅指定缓存时间,

```nginx
uwsgi_cache_valid 5m;
```

则仅缓存 200、301 和 302 响应。

此外,可以使用 `any` 参数指定缓存任何响应:

```nginx
uwsgi_cache_valid 200 302 10m;
uwsgi_cache_valid 301      1h;
uwsgi_cache_valid any      1m;
```

#### NOTE
缓存参数也可以直接在响应头中设置。此方法的优先级高于使用指令设置缓存时间。

* `X-Accel-Expires` 头字段以秒为单位设置响应的缓存时间。值 0 禁用响应的缓存。如果值以 @ 前缀开头,则设置自 Epoch 以来的绝对时间(以秒为单位),响应可以缓存到该时间。
* 如果头中不包含 `X-Accel-Expires` 字段,则缓存参数由 `Expires` 或 `Cache-Control` 头字段确定。
* 带有 `Set-Cookie` 头字段的响应将不会被缓存。
* 带有特殊值 "\*" 的 `Vary` 头字段的响应将不会被缓存。带有其他值的 `Vary` 头字段的响应将在考虑相应请求头字段的情况下被缓存。

可以使用 [uwsgi_ignore_headers](#uwsgi-ignore-headers) 指令禁用对这些头字段中的一个或多个的处理。

<a id="index-19"></a>

<a id="uwsgi-connect-timeout"></a>

### uwsgi_connect_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_connect_timeout` time;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `uwsgi_connect_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

定义与 uwsgi 服务器建立连接的超时时间。需要注意的是,此超时时间通常不能超过 75 秒。

<a id="index-20"></a>

<a id="uwsgi-connection-drop"></a>

### uwsgi_connection_drop

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_connection_drop` time | `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | `uwsgi_connection_drop off;`                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                         |

配置当代理服务器因 [重新解析](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve) 过程或 [API 命令](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config-methods) `DELETE` 而从组中移除或标记为永久不可用时,是否终止到该服务器的所有连接。

当处理客户端或代理服务器的下一个读取或写入事件时,连接将被终止。

设置 time 启用连接终止 [超时](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax);
设置为 `on` 时,连接将立即断开。

<a id="index-21"></a>

<a id="uwsgi-force-ranges"></a>

### uwsgi_force_ranges

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_force_ranges` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `uwsgi_force_ranges off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

无论 uwsgi 服务器的响应中是否存在 `Accept-Ranges` 字段,都为来自该服务器的缓存和非缓存响应启用字节范围支持。

<a id="index-22"></a>

<a id="uwsgi-hide-header"></a>

### uwsgi_hide_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_hide_header` field;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | —                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

默认情况下,Angie 不会将 uwsgi 服务器响应中的头字段 `Date`、`Server`、`X-Pad` 和 `X-Accel-...` 传递给客户端。uwsgi_hide_header 指令设置不会被传递的其他字段。相反,如果需要允许传递字段,可以使用 [uwsgi_pass_header](#uwsgi-pass-header) 指令。

<a id="index-23"></a>

<a id="uwsgi-ignore-client-abort"></a>

### uwsgi_ignore_client_abort

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ignore_client_abort` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `uwsgi_ignore_client_abort off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

确定当客户端在未等待响应的情况下关闭连接时,是否应关闭与 uwsgi 服务器的连接。

<a id="index-24"></a>

<a id="uwsgi-ignore-headers"></a>

### uwsgi_ignore_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ignore_headers` field ...;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | —                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

禁用对来自 uwsgi 服务器的某些响应头字段的处理。可以忽略以下字段:`X-Accel-Redirect`、`X-Accel-Expires`、`X-Accel-Limit-Rate`、`X-Accel-Buffering`、`X-Accel-Charset`、`Expires`、`Cache-Control`、`Set-Cookie` 和 `Vary`。

如果未禁用,处理这些头字段将产生以下效果:

* `X-Accel-Expires`、`Expires`、`Cache-Control`、`Set-Cookie` 和 `Vary` 设置响应 [缓存](#uwsgi-cache-valid) 的参数;
* `X-Accel-Redirect` 执行到指定 URI 的 [内部重定向](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#internal);
* `X-Accel-Limit-Rate` 设置向客户端传输响应的 [速率限制](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#limit-rate);
* `X-Accel-Buffering` 启用或禁用响应的 [缓冲](#uwsgi-buffering);
* `X-Accel-Charset` 设置响应所需的 [字符集](https://cn.angie.software//angie/docs/configuration/modules/http/http_charset.md#id3)。

<a id="index-25"></a>

<a id="uwsgi-intercept-errors"></a>

### uwsgi_intercept_errors

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_intercept_errors` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `uwsgi_intercept_errors off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

确定状态码大于或等于 300 的 uwsgi 服务器响应应该传递给客户端,还是被拦截并重定向到 Angie 以使用 [error_page](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#error-page) 指令进行处理。

<a id="index-26"></a>

<a id="uwsgi-limit-rate"></a>

### uwsgi_limit_rate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_limit_rate` rate;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `uwsgi_limit_rate 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

限制从 uwsgi 服务器读取响应的速度。
rate 以每秒字节数指定;可以使用变量。

| `0`   | 禁用速率限制   |
|-------|----------|

#### NOTE
限制是按请求设置的,因此如果 Angie 同时打开两个到 uwsgi 服务器的连接,总速率将是指定限制的两倍。该限制仅在启用来自 uwsgi 服务器的响应 [缓冲](#uwsgi-buffering) 时有效。

<a id="index-27"></a>

<a id="uwsgi-max-temp-file-size"></a>

### uwsgi_max_temp_file_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_max_temp_file_size` size;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `uwsgi_max_temp_file_size 1024m;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

当启用来自 uwsgi 服务器的响应 [缓冲](#uwsgi-buffering) 时,如果整个响应不适合 [uwsgi_buffer_size](#uwsgi-buffer-size) 和 [uwsgi_buffers](#uwsgi-buffers) 指令设置的缓冲区,则响应的一部分可以保存到临时文件中。此指令设置临时文件的最大大小。一次写入临时文件的数据大小由 [uwsgi_temp_file_write_size](#uwsgi-temp-file-write-size) 指令设置。

| `0`   | 禁用将响应缓冲到临时文件   |
|-------|----------------|

#### NOTE
此限制不适用于将被 [缓存](#uwsgi-cache) 或 [存储到磁盘](#uwsgi-store) 的响应。

<a id="index-28"></a>

<a id="uwsgi-modifier1"></a>

### uwsgi_modifier1

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_hide_header` field;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | —                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

默认情况下,Angie 不会将 uwsgi 服务器响应中的头字段 `Date`、`Server`、`X-Pad` 和 `X-Accel-...` 传递给客户端。`uwsgi_hide_header` 指令设置不会被传递的其他字段。相反,如果需要允许传递字段,可以使用 [uwsgi_pass_header](#uwsgi-pass-header) 指令。

<a id="index-29"></a>

<a id="uwsgi-modifier2"></a>

### uwsgi_ignore_client_abort

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ignore_client_abort` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `uwsgi_ignore_client_abort off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                      |

确定当客户端在未等待响应的情况下关闭连接时,是否应关闭与 uwsgi 服务器的连接。

<a id="index-30"></a>

<a id="uwsgi-next-upstream"></a>

### uwsgi_ignore_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ignore_headers` field ...;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | —                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

指定在哪些情况下应将请求传递给 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 组中的下一个服务器:

| `0`              | 发生连接错误、请求传输错误或响应头读取错误;                                                                                                                               |
|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------|
| `timeout`        | 在建立连接、传输请求或读取响应头期间发生超时;                                                                                                                              |
| `invalid_header` | 服务器返回空响应或无效响应;                                                                                                                                       |
| `http_500`       | 服务器返回代码为 500 的响应;                                                                                                                                    |
| `http_503`       | 服务器返回代码为 503 的响应;                                                                                                                                    |
| `http_403`       | 服务器返回代码为 403 的响应;                                                                                                                                    |
| `http_404`       | 服务器返回代码为 404 的响应;                                                                                                                                    |
| `http_429`       | 服务器返回代码为 429 的响应;                                                                                                                                    |
| `non_idempotent` | 通常,如果已经向上游服务器发送了请求,则不会将使用 [非幂等](https://datatracker.ietf.org/doc/html/rfc7231#section-4.2.2) 方法(`POST`、`LOCK`、`PATCH`)的请求传递给另一个服务器;启用此参数可显式允许重试此类请求; |
| `off`            | 禁用将响应缓冲到临时文件                                                                                                                                         |

#### NOTE
应该理解,只有在尚未向客户端发送任何内容时,才可能将请求传递给下一个服务器。也就是说,如果在响应传输过程中发生错误或超时,则无法修复此问题。

该指令还定义了什么被视为与服务器通信的 [不成功尝试](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#max-fails)。

| `error`<br/><br/>`timeout`<br/><br/>`invalid_header`   | 始终被视为不成功尝试,即使未在指令中指定   |
|--------------------------------------------------------|------------------------|
| `http_500`<br/><br/>`http_503`<br/><br/>`http_429`     | 仅在指令中指定时才被视为不成功尝试      |
| `http_403`<br/><br/>`http_404`                         | 永远不会被视为不成功尝试           |

将请求传递给下一个服务器可以通过 [尝试次数](#uwsgi-next-upstream-tries) 和 [时间](#uwsgi-next-upstream-timeout) 进行限制。

<a id="index-31"></a>

<a id="uwsgi-next-upstream-timeout"></a>

### uwsgi_next_upstream_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_next_upstream_timeout` time;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `uwsgi_next_upstream_timeout 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

限制可以将请求传递给 [下一个](#uwsgi-next-upstream) 服务器的时间。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-32"></a>

<a id="uwsgi-next-upstream-tries"></a>

### uwsgi_next_upstream_tries

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_next_upstream_tries` number;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `uwsgi_next_upstream_tries 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

限制将请求传递给 [下一个](#uwsgi-next-upstream) 服务器的可能尝试次数。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-33"></a>

<a id="uwsgi-no-cache"></a>

### uwsgi_no_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_no_cache` string ...;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | —                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

定义不将响应保存到缓存的条件。如果字符串参数中至少有一个值不为空且不等于"0",则不会保存响应:

```nginx
uwsgi_no_cache $cookie_nocache $arg_nocache$arg_comment;
uwsgi_no_cache $http_pragma    $http_authorization;
```

可以与 [uwsgi_cache_bypass](#uwsgi-cache-bypass) 指令一起使用。

<a id="index-34"></a>

<a id="uwsgi-param"></a>

### uwsgi_param

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_param` parameter value [`if_not_empty`];   |
|--------------------------------------------------------------------------------------|---------------------------------------------------|
| 默认值                                                                                  | —                                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                            |

设置应传递给 uwsgi 服务器的参数。该值可以包含文本、变量及其组合。当且仅当当前级别上没有定义 `uwsgi_param` 指令时,这些指令才从上一级配置继承。

标准 [CGI 环境变量](https://datatracker.ietf.org/doc/html/rfc3875#section-4.1) 应作为 uwsgi 头提供,请参阅发行版中提供的 `uwsgi_params` 文件:

```nginx
location / {
    include uwsgi_params;
#    ...
}
```

如果使用 `if_not_empty` 指定指令,则仅当参数值不为空时才会将该参数传递给服务器:

```nginx
uwsgi_param HTTPS $https if_not_empty;
```

<a id="index-35"></a>

<a id="uwsgi-pass"></a>

### uwsgi_pass

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_pass` [protocol://] address;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | —                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location, if in location              |

设置 uwsgi 服务器的协议和地址。作为协议，可以指定 `uwsgi` 或 `suwsgi` （安全 uwsgi，基于 SSL 的 uwsgi）。地址可以指定为域名或 IP 地址以及端口：

```nginx
uwsgi_pass localhost:9000;
uwsgi_pass uwsgi://localhost:9000;
uwsgi_pass suwsgi://[2001:db8::1]:9090;
```

或者指定为 UNIX 域套接字路径，在单词 `unix` 之后并用冒号括起来：

```nginx
uwsgi_pass unix:/tmp/uwsgi.socket;
```

如果域名解析为多个地址，则所有地址都将以轮询方式使用。此外，地址可以指定为 [服务器组](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream)。

参数值可以包含变量。在这种情况下，如果地址指定为域名，则会在描述的服务器组中搜索该名称，如果未找到，则使用 [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 确定。

#### NOTE
如果在带有尾部斜杠的前缀的 `location` 中指定了 `uwsgi_pass`（例如 :samp:`location /name/`），并且 [auto_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#auto-redirect) 指令设置为 `default`，则不带尾部斜杠的请求将被重定向（`/name -> /name/`）。

<a id="index-36"></a>

<a id="uwsgi-pass-header"></a>

### uwsgi_pass_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_pass_header` field ...;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location           |

允许将 [原本被禁用的](#uwsgi-hide-header) 头字段从 uwsgi 服务器传递给客户端。

<a id="index-37"></a>

<a id="uwsgi-pass-request-body"></a>

### uwsgi_pass_request_body

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_pass_request_body` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | `uwsgi_pass_request_body on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                    |

指示是否将原始请求体传递给 uwsgi 服务器。另请参阅 [uwsgi_pass_request_headers](#uwsgi-pass-request-headers) 指令。

<a id="index-38"></a>

<a id="uwsgi-pass-request-headers"></a>

### uwsgi_pass_request_headers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_pass_request_headers` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------------|
| 默认值                                                                                  | `uwsgi_pass_request_headers on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                       |

启用或禁用将原始请求的头字段传递给 uwsgi 服务器。另请参阅 [uwsgi_pass_request_body](#uwsgi-pass-request-body) 指令。

<a id="index-39"></a>

<a id="uwsgi-read-timeout"></a>

### uwsgi_read_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_read_timeout` time;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `uwsgi_read_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

定义从 uwsgi 服务器读取响应的超时时间。超时仅在两次连续读取操作之间设置，而不是用于整个响应的传输。如果 uwsgi 服务器在此时间内未传输任何内容，则连接将被关闭。

<a id="index-40"></a>

<a id="uwsgi-request-buffering"></a>

### uwsgi_request_buffering

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_request_buffering` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | `uwsgi_request_buffering on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                    |

启用或禁用客户端请求体的缓冲。

| `on`   | 在将请求发送到 uwsgi 服务器之前，从客户端完全 [读取](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-body-buffer-size) 请求体。   |
|--------|-------------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 请求体在接收时立即发送到 uwsgi 服务器。在这种情况下，如果 Angie 已经开始发送请求体，则请求无法传递到 [下一个服务器](#uwsgi-next-upstream)。                                                 |

当使用 HTTP/1.1 分块传输编码发送原始请求体时，无论指令值如何，请求体都将被缓冲。

<a id="index-41"></a>

<a id="uwsgi-send-timeout"></a>

### uwsgi_send_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_send_timeout` time;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `uwsgi_send_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location       |

设置向 uwsgi 服务器传输请求的超时时间。超时仅在两次连续写入操作之间设置，而不是用于整个请求的传输。如果 uwsgi 服务器在此时间内未接收任何内容，则连接将被关闭。

<a id="index-42"></a>

<a id="uwsgi-socket-keepalive"></a>

### uwsgi_socket_keepalive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_socket_keepalive` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `uwsgi_socket_keepalive off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                   |

配置到 uwsgi 服务器的出站连接的 "TCP keepalive" 行为。

| `off`   | 默认情况下，套接字使用操作系统的设置。        |
|---------|----------------------------|
| `on`    | 为套接字启用 SO_KEEPALIVE 套接字选项。 |

<a id="index-43"></a>

<a id="uwsgi-ssl-certificate"></a>

### uwsgi_ssl_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_certificate` file;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | —                               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

指定一个 PEM 格式的证书文件，用于向安全的 uwsgi 服务器进行身份验证。文件名中可以使用变量。

<a id="index-44"></a>

<a id="uwsgi-ssl-certificate-cache"></a>

### uwsgi_ssl_certificate_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_certificate_cache` `off`;<br/><br/>`uwsgi_ssl_certificate_cache` `max=`N [`inactive=`time] [`valid=`time];   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `uwsgi_ssl_certificate_cache off;`                                                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                  |

定义一个缓存，用于存储使用变量指定的 [SSL 证书](#uwsgi-ssl-certificate) 和 [密钥](#uwsgi-ssl-certificate-key)。

该指令支持以下参数：

- `max` — 设置缓存中的最大元素数量。当缓存溢出时，最近最少使用（LRU）的元素将被移除。
- `inactive` — 定义元素在未被访问后被移除的时间。默认为 10 秒。
- `valid` — 定义缓存元素被视为有效并可重用的时间。默认为 60 秒。在此期间之后，证书将被重新加载或重新验证。
- `off` — 禁用缓存。

示例：

```nginx
uwsgi_ssl_certificate       $uwsgi_ssl_server_name.crt;
uwsgi_ssl_certificate_key   $uwsgi_ssl_server_name.key;
uwsgi_ssl_certificate_cache max=1000 inactive=20s valid=1m;
```

<a id="index-45"></a>

<a id="uwsgi-ssl-certificate-key"></a>

### uwsgi_ssl_certificate_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_certificate_key` file;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | —                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location              |

指定一个 PEM 格式的密钥文件，用于向安全的 uwsgi 服务器进行身份验证。

可以指定值 `engine:`name`:id` 来代替文件，这将从 OpenSSL 引擎 name 中加载具有指定 id 的密钥。

可以指定值 `store:scheme:id` 来代替文件，用于从 OpenSSL 提供程序注册的 URI 方案（如 [pkcs11](https://datatracker.ietf.org/doc/html/rfc7512)）加载具有指定 id 的密钥。

文件名中可以使用变量。

<a id="index-46"></a>

<a id="uwsgi-ssl-ciphers"></a>

### uwsgi_ssl_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_ciphers` ciphers;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `uwsgi_ssl_ciphers DEFAULT;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location         |

指定向安全的 uwsgi 服务器发送请求时启用的加密套件。加密套件以 OpenSSL 库理解的格式指定。

加密套件列表取决于安装的 OpenSSL 版本。
可以使用 `openssl ciphers` 命令查看完整列表。

#### WARNING
使用 OpenSSL 时，`uwsgi_ssl_ciphers` 指令  *不* 配置 TLS 1.3 的加密套件。要使用 OpenSSL 调整 TLS 1.3 加密套件，请使用 [uwsgi_ssl_conf_command](#uwsgi-ssl-conf-command) 指令，该指令是为支持高级 SSL 配置而添加的。

- 在 LibreSSL 中，TLS 1.3 加密套件  *可以* 使用 `uwsgi_ssl_ciphers` 配置。
- 在 BoringSSL 中，TLS 1.3 加密套件完全无法配置。

<a id="index-47"></a>

<a id="uwsgi-ssl-conf-command"></a>

### uwsgi_ssl_conf_command

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_conf_command` name value;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

在与安全的 uwsgi 服务器建立连接时设置任意 OpenSSL 配置 [命令](https://docs.openssl.org/master/man3/SSL_CONF_cmd/)。

#### NOTE
使用 OpenSSL 1.0.2 或更高版本时支持该指令。
要在 OpenSSL 中配置 TLS 1.3 加密套件，请使用 `ciphersuites` 命令。

可以在同一级别指定多个 uwsgi_ssl_conf_command 指令。当且仅当当前级别没有定义 uwsgi_ssl_conf_command 指令时，这些指令才会从上一级配置继承。

#### WARNING
请注意，直接重新配置 OpenSSL 可能会导致意外行为。

<a id="index-48"></a>

<a id="uwsgi-ssl-crl"></a>

### uwsgi_ssl_crl

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_crl` file;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | —                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location  |

指定一个 PEM 格式的吊销证书（CRL）文件，用于 [验证](#uwsgi-ssl-verify) 安全的 uwsgi 服务器的证书。

<a id="index-49"></a>

<a id="uwsgi-ssl-name"></a>

### uwsgi_ssl_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_name` name;                |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `uwsgi_ssl_name `uwsgi_pass 中的主机名`;\` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                |

允许覆盖用于 [验证](#uwsgi-ssl-verify) 安全的 uwsgi 服务器证书的服务器名称，以及在与安全的 uwsgi 服务器建立连接时 [通过 SNI 传递](#uwsgi-ssl-server-name) 的服务器名称。

默认情况下，使用 [uwsgi_pass](#uwsgi-pass) 指令中的主机名。

<a id="index-50"></a>

<a id="uwsgi-ssl-password-file"></a>

### uwsgi_ssl_password_file

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_password_file` file;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location            |

指定一个包含 [密钥](#uwsgi-ssl-certificate-key) 口令的文件，每个口令单独占一行。加载密钥时依次尝试这些口令。

<a id="index-51"></a>

<a id="uwsgi-ssl-protocols"></a>

### uwsgi_ssl_protocols

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_protocols` [`SSLv2`] [`SSLv3`] [`TLSv1`] [`TLSv1.1`] [`TLSv1.2`] [`TLSv1.3`];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `uwsgi_ssl_protocols TLSv1.2 TLSv1.3;`                                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                     |

#### Versionchanged
在 1.2.0 版本发生变更: `TLSv1.3` 参数已添加到默认设置中。

启用向安全的 uwsgi 服务器发送请求时使用的指定协议。

<a id="index-52"></a>

<a id="uwsgi-ssl-server-name"></a>

### uwsgi_ssl_server_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_server_name` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `uwsgi_ssl_server_name off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

启用或禁用在与安全 uwsgi 服务器建立连接时，通过 [服务器名称指示](http://en.wikipedia.org/wiki/Server_Name_Indication) TLS 扩展（SNI，[RFC 6066](https://datatracker.ietf.org/doc/html/rfc6066.html)）传递由 [uwsgi_ssl_name](#uwsgi-ssl-name) 指令设置的服务器名称。

<a id="index-53"></a>

<a id="uwsgi-ssl-session-reuse"></a>

### uwsgi_ssl_session_reuse

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_session_reuse` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | `uwsgi_ssl_session_reuse on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                    |

确定在与安全 uwsgi 服务器通信时是否可以重用 SSL 会话。如果日志中出现 "SSL3_GET_FINISHED:digest check failed" 错误，请尝试禁用会话重用。

<a id="index-54"></a>

<a id="uwsgi-ssl-trusted-certificate"></a>

### uwsgi_ssl_trusted_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_trusted_certificate` file;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | —                                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                  |

指定包含 PEM 格式受信任 CA 证书的文件，用于 [验证](#uwsgi-ssl-verify) 安全的 uwsgi 服务器的证书。

<a id="index-55"></a>

<a id="uwsgi-ssl-verify"></a>

### uwsgi_ssl_verify

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_verify` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `uwsgi_ssl_verify off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

启用或禁用 uwsgi 服务器证书的验证。

<a id="index-56"></a>

<a id="uwsgi-ssl-verify-depth"></a>

### uwsgi_ssl_verify_depth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_ssl_verify_depth` number;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `uwsgi_ssl_verify_depth 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location             |

设置 uwsgi 服务器证书链的验证深度。

<a id="index-57"></a>

<a id="uwsgi-store"></a>

### uwsgi_store

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_store` `on` | `off` | string;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `uwsgi_store off;`                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

启用将文件保存到磁盘。

| `on`   | 使用与 [alias](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#alias) 或 [root](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#root) 指令对应的路径保存文件   |
|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `off`  | 禁用文件保存                                                                                                                                                                                              |

可以使用带变量的 string 显式设置文件名：

```nginx
uwsgi_store /data/www$original_uri;
```

文件的修改时间根据接收到的 `Last-Modified` 响应头字段设置。响应首先写入临时文件，然后重命名该文件。临时文件和持久存储可以放在不同的文件系统上。但是请注意，在这种情况下，文件会在两个文件系统之间复制，而不是进行廉价的重命名操作。因此建议对于任何给定位置，保存的文件和由 [uwsgi_temp_path](#uwsgi-temp-path) 指令设置的临时文件目录都放在同一文件系统上。

此指令可用于创建静态不可变文件的本地副本，例如：

```nginx
location /images/ {
    root               /data/www;
    error_page         404 = /fetch$uri;
}

location /fetch/ {
    internal;

    uwsgi_pass         backend:9000;
    ...

    uwsgi_store        on;
    uwsgi_store_access user:rw group:rw all:r;
    uwsgi_temp_path    /data/temp;

    alias              /data/www/;
}
```

<a id="index-58"></a>

<a id="uwsgi-store-access"></a>

### uwsgi_store_access

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_store_access` users:permissions ...;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | `uwsgi_store_access user:rw;`                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                        |

设置新创建的文件和目录的访问权限，例如：

```nginx
uwsgi_store_access user:rw group:rw all:r;
```

如果指定了任何 `group` 或 `all` 访问权限，则可以省略用户权限：

```nginx
uwsgi_store_access group:rw all:r;
```

<a id="index-59"></a>

<a id="uwsgi-temp-file-write-size"></a>

### uwsgi_temp_file_write_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_temp_file_write_size` size;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `uwsgi_temp_file_write_size 8k|16k;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

当启用将来自 uwsgi 服务器的响应缓冲到临时文件时,限制一次写入临时文件的数据大小。默认情况下,大小受 [uwsgi_buffer_size](#uwsgi-buffer-size) 和 [uwsgi_buffers](#uwsgi-buffers) 指令设置的两个缓冲区限制。临时文件的最大大小由 [uwsgi_max_temp_file_size](#uwsgi-max-temp-file-size) 指令设置。

<a id="index-60"></a>

<a id="uwsgi-temp-path"></a>

### uwsgi_temp_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `uwsgi_temp_path` path [level1 [level2 [level3]]]\`;                                                                                               |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `uwsgi_temp_path uwsgi_temp;`<br/>(路径取决于 [构建参数](https://cn.angie.software//angie/docs/installation/sourcebuild.md#paths) `--http-uwsgi-temp-path`) |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                                                                                                                             |

定义用于存储从 uwsgi 服务器接收的数据的临时文件的目录。在指定目录下最多可以使用三级子目录层次结构。例如,在以下配置中

```nginx
uwsgi_temp_path /spool/angie/uwsgi_temp 1 2;
```

临时文件可能如下所示:

```nginx
/spool/angie/uwsgi_temp/7/45/00000123457
```

另请参阅 [uwsgi_cache_path](#uwsgi-cache-path) 指令的 use_temp_path 参数。


# https://cn.angie.software/angie/docs/configuration/modules/http/http_v2.md

<!-- review: finished -->

<a id="http-v2"></a>

# HTTP/2

提供对 [HTTP/2](https://datatracker.ietf.org/doc/html/rfc9113) 的支持。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时,
默认不构建此模块;
应使用
`‑‑with‑http_v2_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用它。

在来自 [我们仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中,
该模块已包含在构建中。

<a id="configuration-example-49"></a>

## 配置示例

```nginx
server {
    listen 443 ssl;

    http2 on;

    ssl_certificate server.crt;
    ssl_certificate_key server.key;
}
```

#### NOTE
请注意,通过 TLS 接受 HTTP/2 连接需要"应用层协议协商"(ALPN)TLS 扩展支持,该功能从 [OpenSSL](http://www.openssl.org/) 1.0.2 版本开始提供。

如果 [ssl_prefer_server_ciphers](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-prefer-server-ciphers) 指令设置为值"on",则应配置 [密码套件](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-ciphers) 以符合 [RFC 9113 附录 A](https://datatracker.ietf.org/doc/html/rfc9113#appendix-A) 黑名单,并且客户端需要支持。

<a id="directives-52"></a>

## 指令

<a id="index-0"></a>

<a id="http2"></a>

### http2

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | `http2 off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server            |

启用 [HTTP/2](https://datatracker.ietf.org/doc/html/rfc9113) 协议。

<a id="index-1"></a>

<a id="http2-body-preread-size"></a>

### http2_body_preread_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_body_preread_size` size;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                      |

设置每个请求的缓冲区大小,在开始处理请求之前,请求体可以保存在该缓冲区中。

<a id="index-2"></a>

<a id="http2-chunk-size"></a>

### http2_chunk_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_chunk_size` size;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `http2_chunk_size 8k;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location     |

设置响应体被切分成的块的最大大小。值过低会导致更高的开销。值过高会由于 [队头阻塞](http://en.wikipedia.org/wiki/Head-of-line_blocking) 而影响优先级处理。

<a id="index-3"></a>

<a id="http2-max-concurrent-pushes"></a>

### http2_max_concurrent_pushes

#### Deprecated
自 1.2.0 版本弃用.

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_max_concurrent_pushes` number;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `http2_max_concurrent_pushes 10;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                            |

限制连接中并发 [推送](#http2-push) 请求的最大数量。

<a id="index-4"></a>

<a id="http2-max-concurrent-streams"></a>

### http2_max_concurrent_streams

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_max_concurrent_streams` number;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `http2_max_concurrent_streams 128;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                             |

设置连接中并发 HTTP/2 流的最大数量。

<a id="index-5"></a>

<a id="http2-push"></a>

### http2_push

#### Deprecated
自 1.2.0 版本弃用.

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_push` uri | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `http2_push off;`           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location      |

抢先发送([推送](https://datatracker.ietf.org/doc/html/rfc9113#name-server-push))对指定 uri 的请求,连同对原始请求的响应一起发送。只会处理带有绝对路径的相对 URI,例如:

```nginx
http2_push /static/css/main.css;
```

`uri` 值可以包含变量。

可以在同一配置级别指定多个 http2_push 指令。`off` 参数取消从上一级配置继承的 http2_push 指令的效果。

<a id="index-6"></a>

<a id="http2-push-preload"></a>

### http2_push_preload

#### Deprecated
自 1.2.0 版本弃用.

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_push_preload` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `http2_push_preload off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

启用将"Link"响应头字段中指定的 [预加载链接](https://www.w3.org/TR/preload/#server-push-http-2) 自动转换为 [推送](https://datatracker.ietf.org/doc/html/rfc9113#name-server-push) 请求。

<a id="index-7"></a>

<a id="http2-recv-buffer-size"></a>

### http2_recv_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http2_recv_buffer_size` size;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `http2_recv_buffer_size 256k;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http                             |

设置每个 [工作进程](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-processes) 的输入缓冲区大小。

<a id="built-in-variables-17"></a>

## 内置变量

http_v2 模块支持以下内置变量:

<a id="v-http2"></a>

### `$http2`

协商的协议标识符:

| `h2`   | 表示基于 TLS 的 HTTP/2   |
|--------|---------------------|
| `h2c`  | 表示基于明文 TCP 的 HTTP/2 |
| `""`   | 否则为空字符串             |


# https://cn.angie.software/angie/docs/configuration/modules/http/http_v3.md

<!-- review: finished -->

<a id="http-v3"></a>

# HTTP/3

为客户端连接提供 [HTTP/3](https://datatracker.ietf.org/doc/html/rfc9114)
协议支持,
同时也支持与使用以下
[Proxy](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy) 模块指令
配置的代理服务器的连接:

- [proxy_http3_hq](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http3-hq)
- [proxy_http3_max_concurrent_streams](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http3-max-concurrent-streams)
- [proxy_http3_max_table_capacity](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http3-max-table-capacity)
- [proxy_http3_stream_buffer_size](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http3-stream-buffer-size)
- [proxy_http_version](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http-version)
- [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass)
- [proxy_quic_active_connection_id_limit](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-quic-active-connection-id-limit)
- [proxy_quic_gso](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-quic-gso)
- [proxy_quic_host_key](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-quic-host-key)

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时,
此模块默认不会被构建;
需要使用
`‑‑with‑http_v3_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 来启用。

在来自 [我们仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中,
该模块已包含在构建中。

<a id="configuration-example-50"></a>

## 配置示例

```nginx
http {
    log_format quic '$remote_addr - $remote_user [$time_local] '
                    '"$request" $status $body_bytes_sent '
                    '"$http_referer" "$http_user_agent" "$http3"';

    access_log logs/access.log quic;

    server {
        # 为了更好的兼容性,建议
        # 对 http/3 和 https 使用相同的端口
        listen 8443 quic reuseport;
        listen 8443 ssl;

        ssl_certificate     certs/example.com.crt;
        ssl_certificate_key certs/example.com.key;

        location / {
            # 用于通告 HTTP/3 的可用性
            add_header Alt-Svc 'h3=":8443"; ma=86400';
        }
    }
}
```

#### NOTE
请注意,通过 TLS 接受 HTTP/3 连接需要 TLSv1.3 协议支持,该协议从 [OpenSSL](http://www.openssl.org/) 1.1.1 版本开始可用。

0-RTT 支持需要 OpenSSL 3.5.1 或更高版本。或者,可以使用 [BoringSSL](https://boringssl.googlesource.com/boringssl/)、[LibreSSL](https://www.libressl.org) 或 [QuicTLS](https://github.com/quictls/openssl) 来构建和运行此模块。

在 1.29.1 版本之前,无论 [ssl_early_data](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-early-data) 指令的值如何,都无法通过 OpenSSL 启用 0-RTT 支持。

对于 HTTP/3 请求,如果未传递 `Host` 头,则 `$http_host` 变量会从 `:authority` 伪头初始化。

此外,:samp:reuseport 选项只能在服务器上的一个 `listen ... quic` 指令中指定。所有其他 `listen ... quic` 指令必须不带此选项。

<a id="directives-53"></a>

## 指令

<a id="index-0"></a>

<a id="http3"></a>

### http3

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http3` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | `http3 on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server            |

启用 HTTP/3 协议协商。

<a id="index-1"></a>

<a id="http3-hq"></a>

### http3_hq

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http3_hq` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `http3_hq off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server               |

启用在 [QUIC 互操作性测试](https://github.com/marten-seemann/quic-interop-runner) 中使用的 HTTP/0.9 协议协商。

#### WARNING
仅在运行明确需要此模式的专门测试时才启用。

<a id="index-2"></a>

<a id="http3-max-concurrent-streams"></a>

### http3_max_concurrent_streams

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http3_max_concurrent_streams` number;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `http3_max_concurrent_streams 128;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                             |

初始化 HTTP/3 和 QUIC 设置,
并设置一个连接中并发 HTTP/3 请求流的最大数量。

<a id="index-3"></a>

<a id="http3-max-table-capacity"></a>

### http3_max_table_capacity

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http3_max_table_capacity` number;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `http3_max_table_capacity 4096;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                         |

设置服务器连接的 [动态表](https://www.ietf.org/archive/id/draft-ietf-quic-qpack-20.html#name-dynamic-table)
容量。

#### NOTE
类似的 [proxy_http3_max_table_capacity](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http3-max-table-capacity) 指令
用于代理连接。
为避免错误,
当启用带缓存的代理时,动态表使用会被禁用。

<a id="index-4"></a>

<a id="http3-stream-buffer-size"></a>

### http3_stream_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `http3_stream_buffer_size` size;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `http3_stream_buffer_size 64k;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                       |

设置用于读取和写入 QUIC 流的缓冲区 [大小](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)。

<a id="index-5"></a>

<a id="quic-active-connection-id-limit"></a>

### quic_active_connection_id_limit

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `quic_active_connection_id_limit` number;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `quic_active_connection_id_limit 2;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                                |

设置 QUIC active_connection_id_limit 传输参数值。这是可以存储在服务器上的连接 ID 的最大数量。

<a id="index-6"></a>

<a id="quic-bpf"></a>

### quic_bpf

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `quic_bpf` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `quic_bpf off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                       |

启用使用 [eBPF](https://ebpf.io/) 路由 QUIC 数据包。启用后,可以支持 QUIC 连接迁移。

#### NOTE
该指令仅在 Linux 5.7+ 上支持。

<a id="index-7"></a>

<a id="quic-gso"></a>

### quic_gso

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `quic_gso` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `quic_gso off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server               |

启用使用分段卸载的优化批量发送模式。

#### NOTE
优化发送仅在支持 `UDP_SEGMENT` 的 Linux 上受支持。

<a id="index-8"></a>

<a id="quic-host-key"></a>

### quic_host_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `quic_host_key` file;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | —                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server            |

设置包含用于加密无状态重置和地址验证令牌的密钥的 file 文件。默认情况下,每次重新加载时都会生成一个随机密钥。使用旧密钥生成的令牌不会被接受。

<a id="index-9"></a>

<a id="quic-retry"></a>

### quic_retry

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `quic_retry` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `quic_retry off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                 |

启用 [QUIC 地址验证](https://datatracker.ietf.org/doc/html/rfc9000#name-address-validation) 功能。这包括在 Retry 数据包或 NEW_TOKEN 帧中发送新令牌,以及验证在 Initial 数据包中收到的令牌。

<a id="built-in-variables-18"></a>

## 内置变量

http_v3 模块支持以下内置变量:

<a id="v-http3"></a>

### `$http3`

协商的协议标识符:

| `h3`   | 用于 HTTP/3 连接   |
|--------|----------------|
| `hq`   | 用于 hq 连接       |
| `""`   | 否则为空字符串        |

<a id="v-quic-connection"></a>

### `$quic_connection`

QUIC 连接序列号


# https://cn.angie.software/angie/docs/configuration/modules/http/http_xslt.md

<!-- review: finished -->

<a id="http-xslt"></a>

# XSLT

该模块是一个过滤器，使用一个或多个 XSLT 样式表转换 XML 响应。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，默认不构建此模块；应使用 `‑‑with‑http_xslt_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用它。

在我们的代码库中，该模块是 [动态构建](https://cn.angie.software//angie/docs/installation/index.md#install-dynamicmodules) 的，并作为一个名为 `angie-module-xslt` 或 `angie-pro-module-xslt` 的独立包提供。

#### NOTE
该模块需要 [libxml2](http://xmlsoft.org/) 和 [libxslt](http://xmlsoft.org/XSLT/) 库。

<a id="configuration-example-51"></a>

## 配置示例

```nginx
location / {
    xml_entities    /site/dtd/entities.dtd;
    xslt_stylesheet /site/xslt/one.xslt param=value;
    xslt_stylesheet /site/xslt/two.xslt;
}
```

<a id="directives-54"></a>

## 指令

<a id="index-0"></a>

<a id="xml-entities"></a>

### xml_entities

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `xml_entities` path;   |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | —                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location |

指定声明字符实体的 DTD 文件。该文件在配置阶段编译。出于技术原因，该模块无法使用在处理的 XML 中声明的外部子集，因此被忽略，并使用专门定义的文件。该文件不应描述 XML 结构。只需声明所需的字符实体，例如：

```xml
<!ENTITY nbsp "&#xa0;">
```

<a id="index-1"></a>

<a id="xslt-last-modified"></a>

### xslt_last_modified

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `xslt_last_modified` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `xslt_last_modified off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location               |

在 XSLT 转换期间允许保留原始响应中的 `Last-Modified` 头字段，以便于响应缓存。

默认情况下，头字段被移除，因为响应的内容在转换期间被修改，可能包含动态生成的元素或与原始响应独立更改的部分。

<a id="index-2"></a>

<a id="xslt-param"></a>

### xslt_param

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `xslt_param` parameter value;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | —                               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location          |

定义 XSLT 样式表的参数。值被视为 XPath 表达式。值可以包含变量。要将字符串值传递给样式表，可以使用 [xslt_string_param](#xslt-string-param) 指令。

可以有多个 `xslt_param` 指令。如果当前级别没有定义 `xslt_param` 和 [xslt_string_param](#xslt-string-param) 指令，则这些指令将从上一个配置级别继承。

<a id="index-3"></a>

<a id="xslt-string-param"></a>

### xslt_string_param

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `xslt_string_param` parameter value;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location                 |

定义 XSLT 样式表的字符串参数。值中的 XPath 表达式不被解释。值可以包含变量。

可以有多个 `xslt_string_param` 指令。如果当前级别没有定义 [xslt_param](#xslt-param) 和 `xslt_string_param` 指令，则这些指令将从上一个配置级别继承。

<a id="index-4"></a>

<a id="xslt-stylesheet"></a>

### xslt_stylesheet

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `xslt_stylesheet` stylesheet [parameter=value ...];   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------|
| 默认值                                                                                  | —                                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | location                                              |

定义 XSLT 样式表及其可选参数。样式表在配置阶段编译。

参数可以单独指定，也可以使用 ":" 分隔符在一行中分组。如果参数包含 ":" 字符，应转义为 "%3A"。此外，libxslt 要求将包含非字母数字字符的参数用单引号或双引号括起来，例如：

```console
param1='http%3A//www.example.com':param2=value2
```

参数描述可以包含变量，例如，整个参数行可以从一个变量中取得：

```nginx
location / {
    xslt_stylesheet /site/xslt/one.xslt
                    $arg_xslt_params
                    param1='$value1':param2=value2
                    param3=value3;
}
```

可以指定多个样式表。它们将按指定的顺序依次应用。

<a id="index-5"></a>

<a id="xslt-types"></a>

### xslt_types

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `xslt_types` mime-type ...;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `xslt_types text/xml;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server, location        |

启用对指定 MIME 类型的响应进行转换，除了 `text/xml` 之外。特殊值 "\*" 匹配任何 MIME 类型。如果转换结果是 HTML 响应，则其 MIME 类型更改为 `text/html`。


# https://cn.angie.software/legal/info-about-IT.md

# Information about IT Activities

| Full name of the organization                              | Limited Liability Company "Web Server"                                                             |
|------------------------------------------------------------|----------------------------------------------------------------------------------------------------|
| Abbreviated name                                           | Web Server, LLC                                                                                    |
| Organization address                                       | 127015, Moscow, intra-city territory of Savelovskiy Municipal District, Vyatskaya St., 27, Bldg. 7 |
| TIN                                                        | 9704151517                                                                                         |
| PSRN                                                       | 1227700436578                                                                                      |
| OKVED                                                      | 62.01 Computer software development                                                                |
| Email address                                              | [info@wbsrv.ru](mailto:info@wbsrv.ru)                                                              |
| Contact phone                                              | +7 (495) 120 50 33                                                                                 |
| Types of activities in the field of information technology | 1.01, 1.05, 1.06, 2.01                                                                             |

Web Server, LLC is the developer of the Angie software; advances solutions for
high-load and infrastructure systems; grants rights to use software; and provides
technical support.

The software development process employs modern programming languages, software tools,
and development instruments, including: programming languages (among them C, Go, and
others); Linux-family operating systems; version control systems (including Git);
containerization tools (including Docker, Kubernetes); and other tools for software
development, testing, and maintenance. The specific set of technologies used is
determined by development requirements and may change as software products evolve.

Web Server, LLC holds exclusive rights to the Angie software developed by the company.
The right to use the software is granted to users under a license agreement
(non-exclusive license), and for certain products or versions also under the terms of
the applicable open-source license, where this is explicitly stated for such a product
or version. The scope of rights granted, permitted methods of use, term, territory,
and conditions for receiving updates and technical support are governed by the terms of
the applicable license agreement, technical support agreement, open-source license,
and/or other applicable documentation.

The software is included in the Unified Register of Russian Software for Electronic
Computers and Databases:

- Angie PRO: [Registry entry No. 17604 dated 17.05.2023](https://reestr.digital.gov.ru/reestr/1484113/)
- Angie Ingress Controller (ANIC): [Registry entry No. 20891 dated 29.12.2023](https://reestr.digital.gov.ru/reestr/2057228/)
- Angie ADC: [Registry entry No. 24972 dated 27.11.2024](https://reestr.digital.gov.ru/reestr/2839952/)

The pricing for software and services of Web Server, LLC is determined individually
and depends on a combination of factors, including the composition and configuration of
the software; the number of instances (servers) and usage parameters; the selected
license type; the level and duration of technical support; functional and integration
requirements; and other conditions of use. Commercial terms, including the specific
price calculation, are formed taking into account the above parameters and may
constitute a trade secret.

Current information on software and service pricing is provided upon request. Information
about the price of the software product, the terms of its acquisition, and the license
agreement can be obtained by writing to us at: [info@wbsrv.ru](mailto:info@wbsrv.ru).


# https://cn.angie.software/news/integrations/ingress-controller-anic-voshel-v-reestr-otechestvennogo-po.md

# Angie Ingress Controller (ANIC) 已加入国产软件名录

*12.01.2024*

大家好！我们用于 Kubernetes 云环境的解决方案 Angie Ingress Controller (ANIC) 已被添加到 [国产软件名录](https://reestr.digital.gov.ru/reestr/2057228/)。

大家好！

我们用于 Kubernetes 云环境的解决方案 Angie Ingress Controller (ANIC) 已被添加到 [国产软件名录](https://reestr.digital.gov.ru/reestr/2057228/)。

目前，ANIC 可以作为 Ingress 资源部署在任何 Kubernetes 平台上，包括俄罗斯的云平台 VK Cloud、Yandex Cloud、MTS (Containerum Kubernetes Service)、Selectel 等。

ANIC 基于 Angie PRO 开发。

关于 ANIC 功能的更多详情，请阅读 [我们的文章](https://wbsrv.ru/tpost/x5osxccja1-ingress-kontroller-anic-voshel-v-reestr)。


# https://cn.angie.software/angie/docs/installation.md

<!-- review: finished -->
<!-- Legacy links -->

<a id="install-dynamicmodules"></a>

<a id="install-packages"></a>

# 安装

<a id="angie"></a>

## Angie

免费开源版本提供多种安装选项：

| [二进制软件包](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)   | 推荐的安装方法；<br/>我们为大多数 Linux 发行版和 FreeBSD 构建并发布软件包。<br/><br/>此外，我们还为许多<br/>[流行的第三方模块](https://cn.angie.software//angie/docs/installation/external-modules/index.md#install-thirdpartymodules)<br/>准备并发布我们自己的构建版本。   |
|---------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Docker 镜像](https://cn.angie.software//angie/docs/installation/docker.md#docker-images)     | 要在容器中运行，您可以从我们的仓库下载 Docker 镜像。<br/>我们基于多种发行版从我们自己的软件包构建镜像。<br/><br/>仓库中的镜像包含我们构建的\*所有\*模块，<br/>包括第三方模块；<br/>还有一个不包含额外模块的最小镜像。                                                                                    |
| [源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild)      | 如果前面的选项由于某种原因不适合您，<br/>您可以随时从源代码创建自己的构建版本。                                                                                                                                                                       |

您可以在
[论坛](https://forum.angie.support)
或
[GitHub](https://github.com/webserver-llc/angie/issues)
上建议新的安装方法、模块和发行版。

<a id="angie-pro"></a>

## Angie PRO

商业版本的主要安装选项是
[二进制软件包](https://cn.angie.software//angie/docs/installation/pro_packages.md#pro-packages)，
存储在安全的私有仓库中；
要访问它，您需要签订合同并购买许可证。

构建版本适用于大多数 POSIX 兼容系统；
此外，我们可以为特定发行版和安装方法
创建并测试您的构建版本。

<a id="third-party-modules-and-other-sources"></a>

## 第三方模块和其他来源

我们在我们的仓库中为许多
[流行的第三方模块](https://cn.angie.software//angie/docs/installation/external-modules/index.md#install-thirdpartymodules) 准备并发布构建版本。

此外，对于许多操作系统和发行版，
可以从它们
[自己的仓库](https://cn.angie.software//angie/docs/installation/thirdparty.md#thirdparty) 安装 Angie。


# https://cn.angie.software/news/integrations.md

# 集成

## [SolidWall Web应用程序防护解决方案兼容Angie PRO](https://cn.angie.software//news/integrations/reshenie-po-zaschite-web-prilojenii-solidwall-sovmestimo-s-angie-pro.md)

*15.07.2024*

与Angie PRO的集成增强了SolidWall WAF的功能，例如，实现了对HTTP/3协议的支持。

## [X-Config负责监控Angie PRO配置的安全性](https://cn.angie.software//news/integrations/bezopastnost-configuracii-angie-pro-kontroliruet-x-config.md)

*08.02.2024*

Angie PRO的安全配置标准将使客户能够自动监控Web服务器设置，接收按优先级排序的漏洞识别报告，并提供修复建议。

## [Angie Ingress Controller (ANIC) 已加入国产软件名录](https://cn.angie.software//news/integrations/ingress-controller-anic-voshel-v-reestr-otechestvennogo-po.md)

*12.01.2024*

大家好！我们用于 Kubernetes 云环境的解决方案 Angie Ingress Controller (ANIC) 已被添加到 [国产软件名录](https://reestr.digital.gov.ru/reestr/2057228/)。

## [扩充第三方模块库：新增ModSecurity](https://cn.angie.software//news/integrations/popolnyaem-kollektsiyu-storonnih-modulei.md)

*04.12.2023*

大家好！在我们为即将发布的Angie和Angie PRO网络服务器更新版本进行工作的同时，我们也在持续扩充我们的第三方模块库。

![Alternative text](../../_images/news/popolnyaem-kollektsiyu-storonnih-modulei.webp)

## [Angie PRO 获得 ROSA Chrome 12 Server 操作系统认证](https://cn.angie.software//news/integrations/angie-pro-sertifitsirovan-dlya-os-rosa-chrome-12-server.md)

*01.12.2023*

俄罗斯网络服务器开发商Web Server与 ROSA IT 研究中心已确认 Angie PRO 网络服务器与 ROSA Chrome 12 Server 操作系统的兼容性，这一点已通过双方签发的证书得到证实，凸显了产品的高度兼容性和可靠性。

## [获得Alt SP Server操作系统兼容性证书](https://cn.angie.software//news/integrations/poluchili-sertifikat-sovmestimosti-s-os-Alt-SP-Server.md)

*10.11.2023*

该证书不仅证实了测试的成功完成，也是我们产品对部分客户实施的必需文件。

![Alternative text](../../_images/news/poluchili-sertifikat-sovmestimosti-s-os-Alt-SP-Server.jpeg)

## [WebmonitorEx平台与俄罗斯网络服务器Angie PRO实现兼容](https://cn.angie.software//news/integrations/platforma-vebmonitoreks-sovmestima-s-rossijskim-veb-serverom-Angie-Pro.md)

*06.09.2023*

WebmonitorEx已确保其平台与俄罗斯网络服务器Angie PRO的兼容性。这为企业提供了更高的可靠性和安全性，以防御网络威胁。

## [在贝加尔测试Angie PRO](https://cn.angie.software//news/integrations/testiruem-angie-pro-na-baikale.md)

*31.08.2023*

我们成功地在ARM处理器架构上编译、构建软件包并测试了我们的产品Angie/Angie PRO。

![Alternative text](../../_images/news/testiruem-angie-pro-na-baikale.jpeg)

## [Angie Web服务器成为"俄罗斯版GitHub"的参与者](https://cn.angie.software//news/integrations/veb-server-angie-stal-uchastnikom-rossijskogo-GitHub.md)

*06.06.2023*

由前nginx团队开发的俄罗斯Web服务器Angie已成为创建俄罗斯代码仓库实验的参与者。俄罗斯数字发展部于2023年5月31日发布了相关命令。

## [Web服务器Angie PRO被列入国产软件名录](https://cn.angie.software//news/integrations/veb-server-angie-pro-voshel-v-reestr-otechestvennogo-PO.md)

*24.05.2023*

由前nginx团队开发的Web服务器Angie PRO已被列入国产软件名录。

## ["网络服务器"团队推出企业级产品 — Angie PRO](https://cn.angie.software//news/integrations/komanda-veb-servera-predstavlyaet-produkt-dlya-korporativnyh-zakazchikov-Angie-Pro.md)

*27.03.2023*

Angie已通过RED OS和Astra Linux特别版的兼容性认证。


# https://cn.angie.software/news/interviews.md

# 访谈

## [备受尊敬的Ivan Panchenko的精彩访谈](https://cn.angie.software//news/interviews/prekrasnoe-intervyu-gluboko-uvazhaemogo-ivana-panchenko.md)

*07.02.2024*

从第25分钟开始，Ivan [谈论](https://www.youtube.com/watch?app=desktop&v=d9joPLRULeA) 我们的事情，
虽然他没有直接提到我们的名字。不过，这个一小时长的访谈中其他内容对所有从事开源项目的人来说都同样重要。

![Alternative text](../../_images/news/prekrasnoe-intervyu-gluboko-uvazhaemogo-ivana-panchenko.jpeg)

## [研发部负责人访谈](https://cn.angie.software//news/interviews/intervyu-s-rukovoditelem-otdela-razrabotki.md)

*16.11.2023*

大家好！今天我们在Habr上发布了一篇对研发部负责人Valentin Bartenyev的访谈。

![Alternative text](../../_images/news/intervyu-s-rukovoditelem-otdela-razrabotki.jpg)


# https://cn.angie.software/news/interviews/intervyu-s-rukovoditelem-otdela-razrabotki.md

# 研发部负责人访谈

*16.11.2023*

大家好！今天我们在Habr上发布了一篇对研发部负责人Valentin Bartenyev的访谈。

![Alternative text](../../_images/news/intervyu-s-rukovoditelem-otdela-razrabotki.jpg)![Alternative text](../../_images/news/intervyu-s-rukovoditelem-otdela-razrabotki.jpg)

大家好！

今天我们在Habr上发布了一篇对研发部负责人Valentin Bartenyev的访谈。

一年多以来，Web Server公司在信息领域掀起波澜，开发了国产开源Web服务器Angie及其商业版本Angie PRO。Habr信息服务部与Web Server公司研发部负责人Valentin Bartenyev进行了交谈。我们了解到了公司的历史、开发细节、未来计划，现在准备与大家分享。

[阅读更多](https://habr.com/ru/articles/774274/)


# https://cn.angie.software/angie/docs/installation/external-modules/jwt.md

<!-- review: finished -->

<a id="external-jwt"></a>

# JWT

该模块使用指定的密钥验证 JSON Web Token (JWT)。
它与 [Auth JWT](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt) 模块 **不兼容**。

<a id="installation-14"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-jwt`
- Angie PRO:`angie-pro-module-jwt`

<a id="loading-the-module-14"></a>

## 加载模块

在 `main{}` 上下文中启用该模块:

```nginx
load_module modules/ngx_http_auth_jwt_module.so;
```

<a id="configuration-example-91"></a>

## 配置示例

```nginx
http {
    server {
        auth_jwt_key "0123456789abcdef" hex;
        auth_jwt     off;

        # Authorization via the Authentication header
        location /secured-by-auth-header/ {
            auth_jwt on;
        }

        # Authorization via cookie
        location /secured-by-cookie/ {
            auth_jwt $cookie_MyCookieName;
        }

        # Key inheritance and override
        location /secured-by-auth-header-too/ {
            auth_jwt_key "another-secret";
            auth_jwt on;
        }

        # Authorization via RSA key
        location /secured-by-rsa-key/ {
            auth_jwt_key /etc/keys/rsa-public.pem file;
            auth_jwt on;
        }

        location /not-secure/ {}
    }
}
```

<a id="additional-information-15"></a>

## 其他信息

详细文档和源代码,请参阅:
[https://github.com/max-lt/nginx-jwt-module](https://github.com/max-lt/nginx-jwt-module)


# https://cn.angie.software/angie/docs/installation/external-modules/keyval.md

<!-- review: finished -->

<a id="external-keyval"></a>

# Keyval

该模块允许使用从"键值"对中获取值的变量,
这些键值对存储在共享内存或 Redis 存储中。

<a id="installation-15"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie: `angie-module-keyval`
- Angie PRO: `angie-pro-module-keyval`

<a id="loading-the-module-15"></a>

## 加载模块

要使用该模块,必须在 `main{}` 上下文中加载它:

```nginx
load_module modules/ngx_http_keyval_module.so;
```

<a id="configuration-example-92"></a>

## 配置示例

```nginx
keyval_zone zone=one:32k;
keyval $arg_key $value zone=one;

server {
    listen 80;
    server_name localhost;

    location /get {
        return 200 "key '$arg_key' has value = '$value'\\n";
    }

    location /set {
        set $value $arg_value;
        return 200 "'$arg_key' key added with '$arg_value' value\\n";
    }
}
```

通过给 `$value` 变量赋值来添加和修改共享内存区域 'one' 中的条目。键值
存储在 `$arg_key` 变量中。在此配置中,这是通过
`set` 指令完成的:

```nginx
set $value $arg_value;
```

<a id="demonstration-1"></a>

## 演示

让我们使用请求定义一些值:

```console
$ curl "localhost/set/?key=one&value=TextForKeyOne"

  'one' key added with 'TextForKeyOne' value
```

```console
$ curl "localhost/set/?key=two&value=TextForKeyTwo"

  'two' key added with 'TextForKeyTwo' value
```

让我们检查一下:

```console
$ curl "localhost/get/?key=one"

  key 'one' has value = 'TextForKeyOne'
```

```console
$ curl "localhost/get/?key=two"

  key 'two' has value = 'TextForKeyTwo'
```

<a id="using-redis"></a>

## 使用 Redis

让我们修改配置以将"键值"对存储在 Redis 存储中:

```nginx
keyval_zone_redis zone=oneredis;
keyval $arg_key $value zone=oneredis;

server {
    listen 80;
    server_name localhost;

    location /get {
        return 200 "key '$arg_key' has value = '$value'\\n";
    }

    location /set {
        set $value $arg_value;
        return 200 "'$arg_key' key added with '$arg_value' value\\n";
    }
}
```

让我们通过请求向 Redis 存储添加一个"键值"对:

```console
$ curl "localhost/set/?key=one&value=TextForKeyOne"

  'one' key added with 'TextForKeyOne' value
```

也可以直接使用 Redis 来完成:

```console
$ redis-cli

  127.0.0.1:6379> set oneredis:two 'text for key two'

  OK

  127.0.0.1:6379>
```

让我们检查一下:

```console
$ redis-cli --scan

  "oneredis:one"
  "oneredis:two"
```

```console
$ curl "localhost/get/?key=one"

  key 'one' has value = 'TextForKeyOne'
```

```console
$ curl "localhost/get/?key=two"

  key 'two' has value = 'text for key two'
```

<a id="additional-information-16"></a>

## 其他信息

指令的完整说明和源代码可在以下位置获取:
[https://github.com/kjdev/nginx-keyval](https://github.com/kjdev/nginx-keyval)。


# https://cn.angie.software/news/integrations/komanda-veb-servera-predstavlyaet-produkt-dlya-korporativnyh-zakazchikov-Angie-Pro.md

# "网络服务器"团队推出企业级产品 — Angie PRO

*27.03.2023*

Angie已通过RED OS和Astra Linux特别版的兼容性认证。

`"网络服务器"` 公司推出了Angie PRO — Angie网络服务器的商业版本，旨在替代俄罗斯市场上的国外解决方案，确保国内企业的基础设施安全。您可以在 [此页面](https://cn.angie.software/angie/pro/) 了解更多发布信息。

Angie PRO是唯一获得RED OS和Astra Linux特别版操作系统兼容性认证的俄罗斯商业网络服务器。

Angie PRO与流行的网络服务器nginx完全兼容。因此，任何现有的nginx用户都可以在不产生重大成本或服务中断的情况下过渡到Angie PRO。`"网络服务器"` 的工程技术支持团队将确保无缝迁移和适配。

Angie PRO具备完整的实时服务器负载监控功能，可根据负载配置文件进行动态配置管理，确保服务的完全可用性。

Angie PRO的功能包括：

* 与客户监控系统的高级集成能力；
* 通过便捷的REST接口管理后端服务器设置；
* 通过用户友好的API实现灵活的网络服务器缓存管理，无需服务中断；
* 在网络流量负载均衡期间配置持久会话；

您可以在 [此页面](https://cn.angie.software/angie/docs/) 查看商业版本的完整功能。

除了多功能网络服务器Angie PRO外，公司客户还可以获得以下服务：

* 具有不同响应级别(SLA)的技术支持，包括继续使用nginx网络服务器及其版本的客户；
* 根据客户需求提供迁移、适配和修改的专业服务；
* 稳定版本的长期支持，无需更新；
* 在公开发布之前提前获取关键漏洞修复；
* 能够影响产品开发路线图中功能的优先级；
* 访问已编译和测试过的第三方动态模块库。

"商业版本Angie PRO的推出并不意味着"网络服务器"将放弃开源版本Angie的开发。这两个版本将在扩展设置方面有所不同，专业版本具有优势。PRO版本的某些功能将在开源版本中延迟提供。我们认为支持开源软件和需要最高服务水平的商业客户都很重要。因此，技术支持等服务将向安装了开源版本但尚未购买Angie PRO的客户开放" - "网络服务器"公司CEO Zaur Abasmirzoev如是说。

Angie网络服务器是由开发者为开发者创建的。Angie的核心团队由高级工程师和技术支持专家组成。"网络服务器"的专家们拥有开发nginx及其商业版本的独特经验，并为财富500强公司提供全天候不间断的技术支持。许多人获得过国际奖项。

您可以通过 [此链接](https://cn.angie.software/) 了解更多关于Angie的信息


# https://cn.angie.software/news/releases/kompaniya-veb-server-obnovila-veb-server.md

# 公司Web Server更新开源Web服务器Angie

*08.06.2023*

俄罗斯开源Web服务器Angie 1.2.0新版本发布。

由前NGINX员工于2022年成立的公司Web Server宣布发布俄罗斯开源Web服务器 [Angie 1.2.0](https://cn.angie.software/) 的新版本。

此次更新 [包括](https://cn.angie.software/) 对最新HTTP协议（HTTP/3）的支持，以及从NGINX项目1.25版本代码库中累积的变更。此外，Angie用户现在可以使用其商业版本Angie PRO中的一项功能：开发人员添加了sticky指令。该指令支持会话亲和性，当存在多个后端服务器时，可以将与单个会话相关的所有请求都重定向到同一服务器。同时还实现了对中国加密标准的支持。

Web Server公司首席执行官Zaur Abasmirzoev表示，新的更新扩展了这款俄罗斯Web服务器的应用范围。 *"现在Angie可以在需要更复杂负载均衡方法的高负载基础设施中无缝运行。对中国加密标准的支持使我们能够实现公司在中国市场推广产品的战略目标，包括在国家层面，"* Zaur Abasmirzoev强调。


# https://cn.angie.software/news/releases/kompaniya-veb-server-predstavila-angie-ingress-controller.md

# Web Server公司推出Angie入口控制器

*29.06.2023*

Web Server公司推出了新产品Angie入口控制器（ANIC），可实现Kubernetes网络中的高效流量管理。

Web Server公司是开源Web服务器Angie及其专有版本Angie PRO的俄罗斯开发商，该公司推出了新产品Angie入口控制器（ANIC）。ANIC是一款允许企业在Kubernetes网络中高效管理流量的软件。ANIC可以作为入口资源部署在任何Kubernetes平台上，包括俄罗斯的云平台VK Cloud、Yandex Cloud、MTS（Containerum Kubernetes Service）、Selectel等。

 *"当前我们正在开发能够在俄罗斯替代进口解决方案的软件。这类软件分为系统软件和应用软件两种。系统软件是计算机运行所必需的，包括操作系统、编程语言、虚拟化系统等。应用软件用于管理业务流程，例如1C公司生产的产品就属于这类。系统软件使用范围更广，因为它不依赖于用户的具体使用方式。比如，所有计算机都需要操作系统。许多公司，如Ozon、Avito、Yandex、VK等，都在其产品中使用微服务架构。为此，他们采用容器编排系统——Kubernetes。在这个框架内，入口控制器软件用于帮助将网络流量路由到适当的微服务。我们的产品Angie入口控制器（ANIC）就是基于这项技术，并与Kubernetes集成。"* Web Server公司首席执行官Zaur Abasmirzoev强调。

ANIC的主要特点：

- 负载均衡：ANIC支持TCP、UDP、TLS、HTTP和gRPC协议的流量分配，在应用程序更新期间提供灵活性和平滑的流量迁移。
- TLS会话终止：ANIC对服务进行身份验证，并通过TLS会话终止确保在线交易的安全性。
- 灵活日志记录：ANIC允许灵活的日志配置，以管理现代动态应用程序。
- 请求响应修改：ANIC提供在HTTP负载均衡器级别修改请求响应的功能。
- DDoS攻击缓解工具：ANIC提供基于各种标准的流量限制，以保护应用程序免受DDoS攻击。
- 高级统计和实时监控：具备完整实时监控入口控制器负载的能力，允许基于负载配置文件进行配置管理，确保服务完全可用。

ANIC支持VirtualServer和VirtualServerRoute资源作为入口控制器的替代方案，支持使用流量分割配置和基于内容的高级路由。通过Annotations和ConfigMap资源可以使用其他入口控制器功能。


# https://cn.angie.software/legal.md

<a id="legal"></a>

# 法律文件

* [使用条款](https://cn.angie.software//legal/terms-of-use.md)
* [隐私政策](https://cn.angie.software//legal/privacy-policy.md)

## 安吉法律信息和文档

[安吉软件产品许可证](https://cn.angie.software//angie/license-angie.md)

[授权组件通知](https://cn.angie.software//angie/doc-license.md)

[贡献者许可证协议](https://cn.angie.software//angie/contributor-agreement.md)

## 安吉PRO文档

该软件产品以商业许可证分发。
有关软件费用、购买条件和许可证协议的信息，请通过info@wbsrv.ru与我们联系。

- [`安吉PRO安装指南`](https://cn.angie.software//angie/pro/Angie_PRO_|angie_pro_pdf_version|_installation_guide.pdf)
- [`安吉PRO功能规范`](https://cn.angie.software//angie/pro/Angie_PRO_|angie_pro_pdf_version|_functional_description.pdf)
- [`安吉PRO操作指南`](https://cn.angie.software//angie/pro/Angie_PRO_|angie_pro_pdf_version|_operating_guide.pdf)

## ANIC文档

该软件产品以商业许可证分发。
有关软件费用、购买条件和许可证协议的信息，请通过info@wbsrv.ru与我们联系。

您可以在下面找到俄语原始文档：

- [`Angie Ingress Controller (ANIC) 安装指南`](https://cn.angie.software//anic/ANIC_|anic_pdf_version|_installation_guide.pdf)
- [`Angie Ingress Controller (ANIC) 功能规范`](https://cn.angie.software//anic/ANIC_|anic_pdf_version|_functional_description.pdf)
- [`Angie Ingress Controller (ANIC) 操作指南`](https://cn.angie.software//anic/ANIC_|anic_pdf_version|_operating_guide.pdf)

## 安吉控制台文档

该软件产品以商业许可证分发。
有关软件费用、购买条件和许可证协议的信息，请通过info@wbsrv.ru与我们联系。

您可以在下面找到俄语原始文档：

- [`安吉控制台安装指南`](https://cn.angie.software//legal/Angie_Console_|console_pdf_version|_installation_guide.pdf)
- [`安吉控制台功能规范`](https://cn.angie.software//legal/Angie_Console_|console_pdf_version|_functional_description.pdf)
- [`安吉控制台操作指南`](https://cn.angie.software//legal/Angie_Console_|console_pdf_version|_operating_guide.pdf)

## 安吉ADC文档

该软件产品以商业许可证分发。
有关软件费用、购买条件和许可证协议的信息，请通过info@wbsrv.ru与我们联系。

您可以在下面找到俄语原始文档：

- [`安吉ADC安装指南`](https://cn.angie.software//adc/Angie_ADC_|adc_pdf_version|_installation_guide.pdf)
- [`安吉ADC功能规范`](https://cn.angie.software//adc/Angie_ADC_|adc_pdf_version|_functional_description.pdf)
- [`安吉ADC操作指南`](https://cn.angie.software//adc/Angie_ADC_|adc_pdf_version|_operating_guide.pdf)

© 2022-2025 Web Server, LLC. 保留所有权利。


# https://cn.angie.software/angie/license-angie.md

<a id="license-angie"></a>

# Angie 软件产品许可证

版权所有 (C) 2022-2025 Web Server, LLC

版权所有 (C) 2002-2021 Igor Sysoev

版权所有 (C) 2011-2025 Nginx, Inc.

保留所有权利。

在满足以下条件的情况下，允许以源代码和二进制形式重新分发和使用本软件，无论是否修改：

1. 源代码的重新分发必须保留上述版权声明、本条件列表和以下免责声明。
2. 二进制形式的重新分发必须在随分发提供的文档和/或其他材料中复制上述版权声明、本条件列表和以下免责声明。

本软件由作者和贡献者按"原样"提供，不提供任何明示或暗示的保证，包括但不限于对适销性和特定用途适用性的暗示保证。在任何情况下，作者或贡献者均不对任何直接、间接、偶然、特殊、示范性或后果性损害（包括但不限于采购替代商品或服务；使用、数据或利润损失；或业务中断）承担责任，无论是基于合同、严格责任或侵权（包括疏忽或其他）的任何责任理论，即使事先被告知可能发生此类损害，也不承担责任。


# https://cn.angie.software/angie/docs/installation/external-modules/lua.md

<!-- review: finished -->

<a id="external-lua"></a>

# Lua

Lua 软件包将 Lua 编程语言集成到 Angie 的事件驱动处理模型中,允许使用 Lua 脚本扩展服务器的功能。
它由两个模块组成:

- `lua-nginx-module` — [https://github.com/openresty/lua-nginx-module](https://github.com/openresty/lua-nginx-module)
- `stream-lua-nginx-module` —
  [https://github.com/openresty/stream-lua-nginx-module](https://github.com/openresty/stream-lua-nginx-module)

<a id="installation-16"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-lua`;
- Angie PRO:`angie-pro-module-lua`。

<a id="features"></a>

## 功能特性

示例用例:

- 聚合和处理来自各种 `upstream` 服务器的输出
  (proxy、drizzle、postgres、redis、memcached 等);
- 在将请求传递给后端之前实现访问控制和安全逻辑;
- 修改响应头;
- 从外部源检索上游服务器数据并动态选择 `upstream`;
- 在 `content handler` 内构建完整的 Web 应用程序;
- 在重写阶段执行 URL 路由;
- 为子请求和 `location` 块实现高级缓存。

LuaJIT 环境提供与 C 语言相当的性能,具有高执行速度和低内存使用率。这使得 Lua 集成在 Angie 中特别高效。

<a id="loading-the-module-16"></a>

## 加载模块

使用 Lua 模块需要预先加载 `ndk` 模块。
模块在 `main{}` 上下文中加载,如下所示:

```nginx
load_module modules/ndk_http_module.so;
load_module modules/ngx_http_lua_module.so;    # 用于 HTTP
load_module modules/ngx_stream_lua_module.so;  # 用于 Stream
```

<a id="bundled-lua-libraries"></a>

## 捆绑的 Lua 库

以下第三方库与 Lua 模块一起安装:

1. [luajit2](https://github.com/openresty/luajit2)
2. [lua_chronos](https://github.com/ldrumm/chronos)
3. [lua_cjson](https://github.com/mpx/lua-cjson)
4. [lua-dumper](https://github.com/edubart/lua-dumper)
5. [lua-ffi-zlib](https://github.com/hamishforbes/lua-ffi-zlib)
6. [inspect.lua](https://github.com/kikito/inspect.lua)
7. [lua-resty-core](https://github.com/openresty/lua-resty-core)
8. [lua-resty-hmac](https://github.com/jkeys089/lua-resty-hmac)
9. [lua-resty-http](https://github.com/ledgetech/lua-resty-http)
10. [lua-resty-jwt](https://github.com/cdbattags/lua-resty-jwt)
11. [lua-resty-lrucache](https://github.com/openresty/lua-resty-lrucache)
12. [lua-resty-openidc](https://github.com/zmartzone/lua-resty-openidc)
13. [lua-resty-openssl](https://github.com/fffonion/lua-resty-openssl)
14. [lua-resty-session](https://github.com/bungle/lua-resty-session)
15. [lua-resty-string](https://github.com/openresty/lua-resty-string)

<a id="additional-information-17"></a>

## 其他信息

完整的文档和源代码可在以下位置获取:

- [https://github.com/openresty/lua-nginx-module](https://github.com/openresty/lua-nginx-module)
- [https://github.com/openresty/stream-lua-nginx-module](https://github.com/openresty/stream-lua-nginx-module)


# https://cn.angie.software/angie/docs/configuration/modules/mail.md

<!-- review: finished -->

<a id="mail-core"></a>

# 邮件模块

核心邮件模块实现了邮件代理服务器的基本功能:
包括对 SMTP、IMAP 和 POP3 协议的支持、配置服务器块、邮件请求路由、用户身份验证,以及用于保护邮件连接的 SSL/TLS 支持。

本节中的其他模块扩展了此功能,允许您灵活地配置和优化邮件服务器以适应各种场景和需求。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时,
此模块默认不会被构建;
应使用
`--with-mail`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用它。
在来自 [我们的软件仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中,
该模块已包含在构建中。

<a id="configuration-example-52"></a>

## 配置示例

```nginx
worker_processes auto;

error_log /var/log/angie/error.log info;

events {
    worker_connections  1024;
}

mail {
    server_name       mail.example.com;
    auth_http         localhost:9000/cgi-bin/auth.cgi;

    imap_capabilities IMAP4rev1 UIDPLUS IDLE LITERAL+ QUOTA;

    pop3_auth         plain apop cram-md5;
    pop3_capabilities LAST TOP USER PIPELINING UIDL;

    smtp_auth         login plain cram-md5;
    smtp_capabilities "SIZE 10485760" ENHANCEDSTATUSCODES 8BITMIME DSN;
    xclient           off;

    server {
        listen   25;
        protocol smtp;
    }
    server {
        listen   110;
        protocol pop3;
        proxy_pass_error_message on;
    }
    server {
        listen   143;
        protocol imap;
    }
    server {
        listen   587;
        protocol smtp;
    }
}
```

<a id="directives-56"></a>

## 指令

<a id="index-0"></a>

<a id="m-listen"></a>

### listen

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `listen` address[:port] [`ssl`] [`proxy_protocol`] [`backlog=`number] [`rcvbuf=`size] [`sndbuf=`size] [`bind`] [`ipv6only=``on` | `off`] [`reuseport`] [`so_keepalive=`on|off|[`keepidle`]:[`keepintvl`]:[`keepcnt`]];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                                                                                                                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                                                                                                                                                                                                                   |

设置服务器将接受连接的套接字的 address 和 port。可以只指定 port,Angie 将监听所有可用的 IPv4 接口(如果启用,还包括 IPv6)。address 也可以是主机名,例如:

```nginx
listen 127.0.0.1:110;
listen *:110;
listen 110;     # 与 *:110 相同
listen localhost:110;
```

IPv6 地址用方括号指定:

```nginx
listen [::1]:110;
listen [::]:110;
```

UNIX 域套接字使用 `unix:` 前缀指定:

```nginx
listen unix:/var/run/angie.sock;
```

#### NOTE
不同的服务器必须监听不同的 address:port 对。

| `ssl`            | 指定在此端口上接受的所有连接都应在 SSL 模式下工作。                                                                                                                                                                                                                                    |
|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `proxy_protocol` | 指定在此端口上接受的所有连接都应使用 PROXY 协议。获取的信息将传递给 [身份验证服务器](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_auth_http.md#mail-auth-http),并可用于 [更改客户端地址](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_realip.md#mail-realip)。 |

`listen` 指令可以有几个与套接字相关的系统调用特定的附加参数。

| `backlog=`number      | 在 `listen()` 调用中设置 backlog 参数,该参数限制待处理连接队列的最大长度。默认情况下,在 FreeBSD、DragonFly BSD 和 macOS 上 backlog 设置为 -1,在其他平台上设置为 511。                                                                                                                                                                                    |
|-----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `rcvbuf=`size         | 为监听套接字设置接收缓冲区大小(SO_RCVBUF 选项)。                                                                                                                                                                                                                                                                           |
| `sndbuf=`size         | 为监听套接字设置发送缓冲区大小(SO_SNDBUF 选项)。                                                                                                                                                                                                                                                                           |
| `bind`                | 指示为给定的 address:port 对进行单独的 `bind()` 调用。事实上,如果有多个具有相同端口但不同地址的 `listen` 指令,并且其中一个 `listen` 指令监听给定端口的所有地址(\*:port),Angie 将只 `bind()` 到 \*:port。应该注意的是,在这种情况下将进行 `getsockname()` 系统调用以确定接受连接的地址。如果使用了 backlog、rcvbuf、sndbuf、ipv6only、reuseport 或 so_keepalive 参数,那么对于给定的 address:port 对将始终进行单独的 `bind()` 调用。 |
| `ipv6only=on` | `off` | 确定(通过 IPV6_V6ONLY 套接字选项)监听通配符地址 [::] 的 IPv6 套接字是只接受 IPv6 连接还是同时接受 IPv6 和 IPv4 连接。此参数默认开启。它只能在启动时设置一次。                                                                                                                                                                                                    |
| `multipath`           | 启用通过 [Multipath TCP](https://en.wikipedia.org/wiki/Multipath_TCP) (MPTCP)接受连接,<br/>在 Linux 内核 5.6 及更高版本中支持。                                                                                                                                                                                              |

`so_keepalive=on` | `off` | [`keepidle`]:[`keepintvl`]:[`keepcnt`]

为监听套接字配置"TCP keepalive"行为。

| `''`   | 如果省略此参数,则套接字将使用操作系统的设置   |
|--------|--------------------------|
| `on`   | 为套接字开启 `SO_KEEPALIVE` 选项 |
| `off`  | 为套接字关闭 `SO_KEEPALIVE` 选项 |

某些操作系统支持使用 `TCP_KEEPIDLE`、`TCP_KEEPINTVL` 和 `TCP_KEEPCNT` 套接字选项
在每个套接字的基础上设置 TCP keepalive 参数。在这些系统上,可以使用
`keepidle`、`keepintvl` 和 `keepcnt` 参数进行配置。可以省略一个或两个参数,在这种
情况下,相应套接字选项的系统默认设置将生效。

例如,

```nginx
so_keepalive=30m::10
```

将空闲超时(`TCP_KEEPIDLE`)设置为 30 分钟,将探测间隔(`TCP_KEEPINTVL`)保留为系统默认值,并将探测次数(`TCP_KEEPCNT`)设置为 10 次探测。

不同的服务器必须监听不同的 address:port 对。

<a id="index-1"></a>

<a id="m-mail"></a>

### mail

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `mail` { ... }   |
|--------------------------------------------------------------------------------------|------------------|
| 默认值                                                                                  | —                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main             |

提供配置文件上下文,在其中指定邮件服务器指令。

<a id="index-2"></a>

<a id="max-commands"></a>

### max_commands

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `max_commands` number;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | `max_commands 1000;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server             |

设置身份验证期间发出的最大命令数,以增强对 DoS 攻击的防护。

<a id="index-3"></a>

<a id="m-max-errors"></a>

### max_errors

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `max_errors` number;   |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | `max_errors 5;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server           |

设置协议错误的次数,超过此次数后将关闭连接。

<a id="index-4"></a>

<a id="m-protocol"></a>

### protocol

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `protocol` imap | pop3 | smtp;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                           |

设置代理服务器的协议。支持的协议有 [IMAP](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_imap.md#mail-imap)、[POP3](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_pop3.md#mail-pop3) 和 [SMTP](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_smtp.md#mail-smtp)。

如果未设置该指令,可以根据 `listen` 指令中指定的知名端口自动检测协议:

```console
imap: 143, 993
pop3: 110, 995
smtp: 25, 587, 465
```

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时,可以使用
`‑‑without‑mail_imap_module`、`‑‑without‑mail_pop3_module` 和
`‑‑without‑mail_smtp_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 禁用不需要的协议。

<a id="index-5"></a>

<a id="m-resolver"></a>

### resolver

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `resolver` address ... [`valid=`time] [`ipv4=``on` | `off`] [`ipv6=``on` | `off`] [`status_zone=`zone] | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `resolver off;`                                                                                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                                                                                                      |

配置用于查找客户端主机名的名称服务器,以将其传递给 [身份验证服务器](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_auth_http.md#mail-auth-http),并在代理 SMTP 时用于 [XCLIENT](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_proxy.md#m-xclient) 命令。例如:

```nginx
resolver 127.0.0.53 [::1]:5353;
```

特殊值 `off` 会禁用客户端主机名解析,并取消继承的指令值。

地址可以指定为域名或 IP 地址,带有可选端口。如果未指定端口,则使用端口 53。名称服务器以轮询方式查询。

#### NOTE
建议使用本地可信解析器，例如 `127.0.0.53` (systemd-resolved)，而非
公共解析器（如 `8.8.8.8`）。公共解析器会将 DNS 查询暴露给第三方，
并增加缓存投毒攻击的风险。

#### NOTE
指令值会被嵌套块继承,
并且可以在嵌套块中根据需要进行覆盖。
在单个块内,指令只能指定一次。
如果重复指定,则最后一次定义生效。

默认情况下,Angie 使用响应的 TTL 值来缓存答案。如果
未指定 `resolver` 指令且不执行动态 DNS 查询(例如,在 [Proxy](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_proxy.md#mail-proxy) 中使用固定名称而不使用
变量时),则不需要指定解析器:名称将在启动时
使用系统解析器进行解析。可选的 `valid` 参数允许
覆盖此行为:

| `valid`   |  *可选* 参数,允许覆盖缓存条目的有效期   |
|-----------|-------------------------|
```nginx
resolver 127.0.0.53 [::1]:5353 valid=30s;
```

默认情况下,Angie 在解析时会同时查找 IPv4 和 IPv6 地址。

| `ipv4=off`    | 禁用 IPv4 地址查找                       |
|---------------|------------------------------------|
| `ipv6=off`    | 禁用 IPv6 地址查找                       |
| `status_zone` | *可选* 参数,在指定区域中启用 DNS 服务器请求和响应信息的收集 |

<a id="index-6"></a>

<a id="m-resolver-timeout"></a>

### resolver_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `resolver_timeout` time;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `resolver_timeout 30s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server               |

设置名称解析的超时时间,例如:

```nginx
resolver_timeout 5s;
```

<a id="index-7"></a>

<a id="m-server"></a>

### server

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server` { ... }   |
|--------------------------------------------------------------------------------------|--------------------|
| 默认值                                                                                  | —                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail               |

设置服务器的配置。

<a id="index-8"></a>

<a id="m-server-name"></a>

### server_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server_name` name;     |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | `server_name hostname`; |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server            |

设置服务器名称,用于:

* POP3/SMTP 服务器的初始问候语;
* SASL CRAM-MD5 认证期间的盐值;
* 连接到 SMTP 后端时的 EHLO 命令,如果启用了 [XCLIENT](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_proxy.md#m-xclient) 命令的传递。

如果未指定该指令,则使用机器的 hostname。

<a id="index-9"></a>

<a id="m-timeout"></a>

### timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `timeout` time;   |
|--------------------------------------------------------------------------------------|-------------------|
| 默认值                                                                                  | `timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server      |

设置开始代理到后端之前使用的超时时间。


# https://cn.angie.software/angie/docs/configuration/modules/mail/mail_auth_http.md

<!-- review: finished -->

<a id="mail-auth-http"></a>

# Auth HTTP

该模块通过在处理主请求之前发送额外的 HTTP 请求来实现基于子请求的认证。如果子请求返回 2xx 状态,主请求将继续处理;如果返回 401 或 403,相应的错误将发送给用户,而任何其他响应都会触发 500 错误。这种方法通常用于将认证委托给外部服务,统一跨应用程序的认证,或与 OAuth 或 LDAP 等第三方系统集成。

<a id="directives-57"></a>

## 指令

<a id="index-0"></a>

<a id="m-auth-http"></a>

### auth_http

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `auth_http` uri;   |
|--------------------------------------------------------------------------------------|--------------------|
| 默认值                                                                                  | —                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server       |

设置 HTTP 认证服务器的 URL。协议描述见 [下文](#v-m-protocol)。

<a id="index-1"></a>

<a id="m-auth-http-header"></a>

### auth_http_header

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `auth_http_header` header value;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | —                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                       |

将指定的头部附加到发送给认证服务器的请求中。此头部可以用作共享密钥,以验证请求是否来自 Angie。例如:

```nginx
auth_http_header X-Auth-Key "secret_string";
```

<a id="index-2"></a>

<a id="m-auth-http-pass-client-cert"></a>

### auth_http_pass_client_cert

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `auth_http_pass_client_cert` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------------|
| 默认值                                                                                  | `auth_http_pass_client_cert off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                                 |

将 `Auth-SSL-Cert` 头部与 PEM 格式(urlencoded)的 [客户端证书](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_ssl.md#m-ssl-verify-client) 附加到发送给认证服务器的请求中。

<a id="index-3"></a>

<a id="m-auth-http-timeout"></a>

### auth_http_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `auth_http_timeout` time;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `auth_http_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                |

设置与认证服务器通信的超时时间。

<a id="v-m-protocol"></a>

## 协议

HTTP 协议用于与认证服务器通信。响应体中的数据被忽略,仅在头部传递信息。

<a id="examples-of-requests-and-responses"></a>

### 请求和响应示例:

请求:

```console
GET /auth HTTP/1.0
Host: localhost
Auth-Method: plain # plain/apop/cram-md5/external/xoauth2/oauthbearer/none
Auth-User: user
Auth-Pass: password
Auth-Protocol: imap # imap/pop3/smtp
Auth-Login-Attempt: 1
Client-IP: 192.0.2.42
Client-Host: client.example.org
```

成功响应:

```console
HTTP/1.0 200 OK
Auth-Status: OK
Auth-Server: 198.51.100.1
Auth-Port: 143
```

失败响应:

```console
HTTP/1.0 200 OK
Auth-Status: Invalid login or password
Auth-Wait: 3
```

如果没有 `Auth-Wait` 头部,将返回错误并关闭连接。当前实现为每次认证尝试分配内存。内存仅在会话结束时释放。因此,单个会话中的无效认证尝试次数必须有限制——在 10-20 次尝试后,服务器必须响应不带 `Auth-Wait` 头部(尝试次数在 `Auth-Login-Attempt` 头部中传递)。

当使用 APOP 或 CRAM-MD5 时,请求响应如下所示:

```console
GET /auth HTTP/1.0
Host: localhost
Auth-Method: apop
Auth-User: user
Auth-Salt: <238188073.1163692009@mail.example.com>
Auth-Pass: auth_response
Auth-Protocol: imap
Auth-Login-Attempt: 1
Client-IP: 192.0.2.42
Client-Host: client.example.org
```

成功响应:

```console
HTTP/1.0 200 OK
Auth-Status: OK
Auth-Server: 198.51.100.1
Auth-Port: 143
Auth-Pass: plain-text-pass
```

当使用 XOAUTH2 或 OAUTHBEARER 时,:samp:Auth-User 和 `Auth-Pass` 头部包含从初始 SASL 响应中提取的用户身份和持有者令牌。

如果响应中存在 `Auth-User` 头部,它将覆盖用于与后端认证的用户名。

对于 SMTP,响应还会考虑 `Auth-Error-Code` 头部——如果存在,它将在错误情况下用作响应代码。否则,\`535 5.7.0\` 代码将默认添加到 `Auth-Status` 头部。

对于 XOAUTH2 和 OAUTHBEARER,错误响应还可能包含 `Auth-Error-SASL` 头部。其值作为额外的 SASL 质询发送给客户端(SMTP:334,IMAP/POP3:+)。在客户端对 XOAUTH2 响应空响应或对 OAUTHBEARER 响应 `AQ==` 后,返回来自 `Auth-Status` 的错误。

例如,如果从认证服务器收到以下响应:

```console
HTTP/1.0 200 OK
Auth-Status: Temporary server problem, try again later
Auth-Error-Code: 451 4.3.0
Auth-Wait: 3
```

则 SMTP 客户端将收到错误

```console
451 4.3.0 Temporary server problem, try again later
```

如果代理 SMTP 不需要认证,请求将如下所示:

```console
GET /auth HTTP/1.0
Host: localhost
Auth-Method: none
Auth-User:
Auth-Pass:
Auth-Protocol: smtp
Auth-Login-Attempt: 1
Client-IP: 192.0.2.42
Client-Host: client.example.org
Auth-SMTP-Helo: client.example.org
Auth-SMTP-From: MAIL FROM: <>
Auth-SMTP-To: RCPT TO: <postmaster@mail.example.com>
```

对于 SSL/TLS 客户端连接,添加 `Auth-SSL` 头部,并且 `Auth-SSL-Verify` 将包含客户端证书验证的结果,如果 [启用](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_ssl.md#m-ssl-verify-client):`SUCCESS`,:samp:FAILED:reason,以及如果没有证书则为 `NONE`。

当存在客户端证书时,其详细信息将通过以下请求头部传递:`Auth-SSL-Subject`、`Auth-SSL-Issuer`、`Auth-SSL-Serial` 和 `Auth-SSL-Fingerprint`。如果启用了 [auth_http_pass_client_cert](#m-auth-http-pass-client-cert),证书本身将通过 `Auth-SSL-Cert` 头部传递。已建立连接的协议和密码将通过 `Auth-SSL-Protocol` 和 `Auth-SSL-Cipher` 头部传递。请求将如下所示:

```console
GET /auth HTTP/1.0
Host: localhost
Auth-Method: plain
Auth-User: user
Auth-Pass: password
Auth-Protocol: imap
Auth-Login-Attempt: 1
Client-IP: 192.0.2.42
Auth-SSL: on
Auth-SSL-Protocol: TLSv1.3
Auth-SSL-Cipher: TLS_AES_256_GCM_SHA384
Auth-SSL-Verify: SUCCESS
Auth-SSL-Subject: /CN=example.com
Auth-SSL-Issuer: /CN=example.com
Auth-SSL-Serial: C07AD56B846B5BFF
Auth-SSL-Fingerprint: 29d6a80a123d13355ed16b4b04605e29cb55a5ad
```

当使用 [PROXY 协议](https://cn.angie.software//angie/docs/configuration/modules/mail/index.md#m-listen-ssl-proxy) 时,其详细信息将通过以下请求头部传递:`Proxy-Protocol-Addr`、`Proxy-Protocol-Port`、`Proxy-Protocol-Server-Addr` 和 `Proxy-Protocol-Server-Port`。


# https://cn.angie.software/angie/docs/configuration/modules/mail/mail_imap.md

<!-- review: finished -->

<a id="mail-imap"></a>

# IMAP

该模块启用 IMAP 邮件协议支持,允许服务器与邮件存储系统交互。它建立与 IMAP 服务器的连接,处理常见命令如列出邮箱和检索消息,并提供安全的身份验证和消息状态管理。

<a id="directives-58"></a>

## 指令

<a id="index-0"></a>

<a id="m-imap-auth"></a>

### imap_auth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `imap_auth` method ...;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `imap_auth plain;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server              |

设置 IMAP 客户端允许的身份验证方法。支持的方法有:

| `plain`       | [LOGIN](https://datatracker.ietf.org/doc/html/rfc3501), [AUTH=PLAIN](https://datatracker.ietf.org/doc/html/rfc4616)   |
|---------------|-----------------------------------------------------------------------------------------------------------------------|
| `login`       | [AUTH=LOGIN](https://datatracker.ietf.org/doc/html/draft-murchison-sasl-login-00)                                     |
| `cram-md5`    | [AUTH=CRAM-MD5](https://datatracker.ietf.org/doc/html/rfc2195)。为了使此方法正常工作,密码必须以未加密的形式存储。                              |
| `external`    | [AUTH=EXTERNAL](https://datatracker.ietf.org/doc/html/rfc4422)                                                        |
| `xoauth2`     | [AUTH=XOAUTH2](https://developers.google.com/gmail/imap/xoauth2-protocol)                                             |
| `oauthbearer` | [AUTH=OAUTHBEARER](https://datatracker.ietf.org/doc/html/rfc7628)                                                     |

明文身份验证方法(`LOGIN` 命令、`AUTH=PLAIN` 和 `AUTH=LOGIN`)始终启用,尽管如果未指定 `plain` 和 `login` 方法,:samp:AUTH=PLAIN 和 `AUTH=LOGIN` 将不会自动包含在 [imap_capabilities](#m-imap-capabilities) 中。

<a id="index-1"></a>

<a id="m-imap-capabilities"></a>

### imap_capabilities

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `imap_capabilities` extension ...;           |
|--------------------------------------------------------------------------------------|----------------------------------------------|
| 默认值                                                                                  | `imap_capabilities IMAP4 IMAP4rev1 UIDPLUS;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                                 |

设置在响应 CAPABILITY 命令时传递给客户端的 [IMAP 协议](https://datatracker.ietf.org/doc/html/rfc3501) 扩展列表。根据 [starttls](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_ssl.md#m-starttls) 指令的值,:ref:m_imap_auth 指令中指定的身份验证方法和 [STARTTLS](https://datatracker.ietf.org/doc/html/rfc2595) 会自动添加到此列表中。

指定客户端代理到的 IMAP 后端所支持的扩展是有意义的(如果这些扩展与身份验证后使用的命令相关,即当 Angie 透明地将客户端连接代理到后端时)。

<!-- 当前标准化扩展列表发布在 `www.iana.org <http://www.iana.org/assignments/imap4-capabilities>`_。 -->

<a id="index-2"></a>

<a id="m-imap-client-buffer"></a>

### imap_client_buffer

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `imap_client_buffer` size;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `imap_client_buffer 4k|8k;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                 |

设置用于读取 IMAP 命令的缓冲区大小。默认情况下,缓冲区大小等于一个内存页。这是 4K 或 8K,具体取决于平台。


# https://cn.angie.software/angie/docs/configuration/modules/mail/mail_pop3.md

<!-- review: finished -->

<a id="mail-pop3"></a>

# POP3

该模块启用 POP3 邮件协议支持,允许服务器从邮件服务器下载消息。它连接到 POP3 服务器,检索消息头和内容,提供安全认证,并管理消息状态,如已下载或已删除。

<a id="directives-59"></a>

## 指令

<a id="index-0"></a>

<a id="m-pop3-auth"></a>

### pop3_auth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `pop3_auth` method ...;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认                                                                                   | `pop3_auth plain;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server              |

设置允许的 POP3 客户端身份验证方法。支持的方法有:

| `plain`       | [USER/PASS](https://datatracker.ietf.org/doc/html/rfc1939)、[AUTH PLAIN](https://datatracker.ietf.org/doc/html/rfc4616)、[AUTH LOGIN](https://datatracker.ietf.org/doc/html/draft-murchison-sasl-login-00)   |
|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `apop`        | [APOP](https://datatracker.ietf.org/doc/html/rfc1939)。为了使此方法生效,密码必须以未加密形式存储。                                                                                                                               |
| `cram-md5`    | [AUTH=CRAM-MD5](https://datatracker.ietf.org/doc/html/rfc2195)。为了使此方法生效,密码必须以未加密形式存储。                                                                                                                      |
| `external`    | [AUTH=EXTERNAL](https://datatracker.ietf.org/doc/html/rfc4422)                                                                                                                                             |
| `xoauth2`     | [AUTH=XOAUTH2](https://developers.google.com/gmail/imap/xoauth2-protocol)                                                                                                                                  |
| `oauthbearer` | [AUTH=OAUTHBEARER](https://datatracker.ietf.org/doc/html/rfc7628)                                                                                                                                          |

明文身份验证方法(`USER/PASS`、`AUTH PLAIN` 和 `AUTH LOGIN`)始终启用,尽管如果没有指定 `plain` 方法,:samp:AUTH PLAIN 和 `AUTH LOGIN` 将不会自动包含在 [pop3_capabilities](#m-pop3-capabilities) 中。

<a id="index-1"></a>

<a id="m-pop3-capabilities"></a>

### pop3_capabilities

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `pop3_capabilities` extension ...;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认                                                                                   | `pop3_capabilities TOP USER UIDL;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                         |

设置在响应 CAPA 命令时传递给客户端的 [POP3 协议](https://datatracker.ietf.org/doc/html/rfc2449) 扩展列表。根据 [starttls](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_ssl.md#m-starttls) 指令的值,:ref:m_pop3_auth 指令中指定的身份验证方法([SASL](https://datatracker.ietf.org/doc/html/rfc2449) 扩展)和 [STLS](https://datatracker.ietf.org/doc/html/rfc2595) 会自动添加到此列表中。

指定 POP3 后端支持的扩展是有意义的,这些后端是客户端代理的目标(如果这些扩展与身份验证后使用的命令相关,当 Angie 透明地将客户端连接代理到后端时)。


# https://cn.angie.software/angie/docs/configuration/modules/mail/mail_proxy.md

<!-- review: finished -->

<a id="mail-proxy"></a>

# Proxy

该模块提供对邮件协议（POP3、IMAP、SMTP）的支持，使服务器能够充当客户端和邮件服务器之间的代理。它与服务器建立连接，使用明文、SSL/TLS 或 STARTTLS 执行安全身份验证，正确路由客户端流量，并支持灵活选择身份验证方法和服务器。

<a id="directives-60"></a>

## 指令

<a id="index-0"></a>

<a id="m-proxy-buffer"></a>

### proxy_buffer

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_buffer` size;   |
|--------------------------------------------------------------------------------------|------------------------|
| 默认值                                                                                  | `proxy_buffer 4k|8k;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server           |

设置用于代理的缓冲区大小。默认情况下，缓冲区大小等于一个内存页。根据平台的不同，它是 4K 或 8K。

<a id="index-1"></a>

<a id="m-proxy-pass-error-message"></a>

### proxy_pass_error_message

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_pass_error_message` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | `proxy_pass_error_message off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                               |

指示是否将后端在身份验证过程中获得的错误消息传递给客户端。

通常，如果在 Angie 中身份验证成功，则后端无法返回错误。如果它仍然返回错误，则意味着发生了一些内部错误。在这种情况下，后端消息可能包含不应显示给客户端的信息。然而，对于某些 POP3 服务器，正确密码的错误响应是正常行为。在这种情况下，应启用该指令。

<a id="index-2"></a>

<a id="m-proxy-protocol"></a>

### proxy_protocol

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_protocol` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `proxy_protocol off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                     |

为与后端的连接启用 [PROXY 协议](http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt)。

<a id="index-3"></a>

<a id="m-proxy-smtp-auth"></a>

### proxy_smtp_auth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_smtp_auth` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `proxy_smtp_auth off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                      |

启用或禁用使用 AUTH 命令在 SMTP 后端进行用户身份验证。

如果 [XCLIENT](#m-xclient) 也启用，则 XCLIENT 命令将不会发送 LOGIN 参数。

<a id="index-4"></a>

<a id="m-proxy-timeout"></a>

### proxy_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_timeout` time;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | `proxy_timeout 24h;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server            |

设置客户端或代理服务器连接之间两个连续读或写操作的超时。如果在此时间内未传输任何数据，则连接将被关闭。

<a id="index-5"></a>

<a id="m-xclient"></a>

### xclient

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `xclient` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `xclient on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server              |

启用或禁用在连接到 SMTP 后端时传递带有客户端参数的 [XCLIENT](http://www.postfix.org/XCLIENT_README.html) 命令。

使用 `XCLIENT`，邮件传输代理能够将客户端信息写入日志，并根据这些数据应用各种限制。

如果启用 `XCLIENT`，则在连接到后端时 Angie 会传递以下命令：

* `EHLO` 与 [服务器名称](https://cn.angie.software//angie/docs/configuration/modules/mail/index.md#m-server-name)
* `XCLIENT`
* `EHLO` 或 `HELO`，如客户端所传递

如果通过客户端 IP 地址 [找到](https://cn.angie.software//angie/docs/configuration/modules/mail/index.md#m-resolver) 的名称指向相同地址，则它会在 `XCLIENT` 命令的 `NAME` 参数中传递。如果找不到名称，指向不同的地址，或未指定 [解析器](https://cn.angie.software//angie/docs/configuration/modules/mail/index.md#m-resolver)，则在 `NAME` 参数中传递 `[UNAVAILABLE]`。如果在解析过程中发生错误，则使用 `[TEMPUNAVAIL]` 值。

如果禁用 `XCLIENT`，则在连接到后端时，如果客户端传递了 `EHLO`，Angie 会与 [服务器名称](https://cn.angie.software//angie/docs/configuration/modules/mail/index.md#m-server-name) 一起传递 `EHLO` 命令，否则会与服务器名称一起传递 `HELO`。


# https://cn.angie.software/angie/docs/configuration/modules/mail/mail_realip.md

<!-- review: finished -->

<a id="mail-realip"></a>

# RealIP

该模块用于将客户端地址和端口更改为在 PROXY 协议头中发送的地址和端口。必须通过在 [listen](https://cn.angie.software//angie/docs/configuration/modules/mail/index.md#m-listen) 指令中设置 proxy_protocol 参数来先前启用 PROXY 协议。

<a id="configuration-example-53"></a>

## 配置示例

```nginx
listen 110 proxy_protocol;

set_real_ip_from  192.168.1.0/24;
set_real_ip_from  192.168.2.1;
set_real_ip_from  2001:0db8::/32;
```

<a id="directives-61"></a>

## 指令

<a id="index-0"></a>

<a id="m-set-real-ip-from"></a>

### set_real_ip_from

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `set_real_ip_from` address | CIDR | `unix`:;   |
|------------------------------------------------------------------------------------------|------------------------------------------------|
| Default                                                                                  | —                                              |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                                   |

定义已知发送正确替换地址的受信任地址。如果指定了特殊值 `unix:`，则所有 UNIX 域套接字都将被信任。


# https://cn.angie.software/angie/docs/configuration/modules/mail/mail_smtp.md

<!-- review: finished -->

<a id="mail-smtp"></a>

# SMTP

该模块启用对SMTP邮件协议的支持，允许服务器代理客户端和邮件服务器之间的出站电子邮件流量。它建立与SMTP服务器的连接，支持使用LOGIN或PLAIN方法进行安全认证，提供STARTTLS和SSL/TLS加密，并根据认证结果路由客户端请求。

<a id="directives-62"></a>

## 指令

<a id="index-0"></a>

<a id="m-smtp-auth"></a>

### smtp_auth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `smtp_auth` method ...;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `smtp_auth plain login;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server              |

设置SMTP客户端允许的 [SASL认证](https://datatracker.ietf.org/doc/html/rfc2554) 方法。支持的方法包括：

| `plain`       | [AUTH PLAIN](https://datatracker.ietf.org/doc/html/rfc4616)                              |
|---------------|------------------------------------------------------------------------------------------|
| `login`       | [AUTH LOGIN](https://datatracker.ietf.org/doc/html/draft-murchison-sasl-login-00)        |
| `cram-md5`    | [AUTH CRAM-MD5](https://datatracker.ietf.org/doc/html/rfc2195)。为了使此方法正常工作，密码必须以未加密的形式存储。 |
| `external`    | [AUTH EXTERNAL](https://datatracker.ietf.org/doc/html/rfc4422)                           |
| `xoauth2`     | [AUTH XOAUTH2](https://developers.google.com/gmail/imap/xoauth2-protocol)                |
| `oauthbearer` | [AUTH OAUTHBEARER](https://datatracker.ietf.org/doc/html/rfc7628)                        |
| `none`        | 不需要认证                                                                                    |

明文认证方法 (`AUTH PLAIN` 和 `AUTH LOGIN`) 始终启用，但如果未指定 `plain` 和 `login` 方法，则 `AUTH PLAIN` 和 `AUTH LOGIN` 将不会自动包含在 [smtp_capabilities](#m-smtp-capabilities) 中。

<a id="index-1"></a>

<a id="m-smtp-capabilities"></a>

### smtp_capabilities

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `smtp_capabilities` extension ...;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | —                                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                         |

设置在响应EHLO命令时传递给客户端的SMTP协议扩展列表。根据 [starttls](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_ssl.md#m-starttls) 指令的值，[smtp_auth](#m-smtp-auth) 指令中指定的认证方法和 [STARTTLS](https://datatracker.ietf.org/doc/html/rfc3207) 会自动添加到此列表中。

指定客户端被代理到的MTA所支持的扩展是有意义的（如果这些扩展与认证后使用的命令相关，当Angie透明地将客户端连接代理到后端时）。

<a id="index-2"></a>

<a id="m-smtp-client-buffer"></a>

### smtp_client_buffer

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `smtp_client_buffer` size;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `smtp_client_buffer 4k|8k;`  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                 |

设置用于读取SMTP命令的缓冲区大小。默认情况下，缓冲区大小等于一个内存页面。根据平台不同，这通常是4K或8K。

<a id="index-3"></a>

<a id="m-smtp-greeting-delay"></a>

### smtp_greeting_delay

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `smtp_greeting_delay` time;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `smtp_greeting_delay 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                  |

允许在发送SMTP问候语之前设置延迟，以拒绝在发送SMTP命令之前未能等待问候的客户端。


# https://cn.angie.software/angie/docs/configuration/modules/mail/mail_ssl.md

<!-- review: finished -->

<a id="mail-ssl"></a>

# SSL

该模块为邮件代理协议(POP3、IMAP、SMTP)启用 SSL/TLS 加密支持,允许客户端和服务器之间进行安全通信。它为传入连接提供 SSL/TLS 加密,支持 STARTTLS 升级,管理证书和密钥,并控制 SSL 设置,如密码和协议版本。

当从 [源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时,
该模块默认不会构建;
应该使用 `‑‑with‑mail_ssl_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用它。

在来自 [我们仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中,
该模块已包含在构建中。

#### NOTE
此模块需要 OpenSSL 库。

<a id="configuration-example-54"></a>

## 配置示例

为了减少处理器负载,建议

* 将 [工作进程数量](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-processes) 设置为与处理器数量相等,
* 启用 [共享](#m-ssl-session-cache) 会话缓存,
* 禁用 [内置](#m-ssl-session-cache) 会话缓存,
* 并可能增加会话 [生命周期](#m-ssl-session-timeout) (默认为 5 分钟):

```nginx
worker_processes auto;

mail {

    ...

    server {
        listen              993 ssl;

        ssl_protocols       TLSv1.2 TLSv1.3;
        ssl_ciphers         AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
        ssl_certificate     /usr/local/angie/conf/cert.pem;
        ssl_certificate_key /usr/local/angie/conf/cert.key;
        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 10m;

    #    ...
    }
```

<a id="directives-63"></a>

## 指令

<a id="index-0"></a>

<a id="m-ssl-certificate"></a>

### ssl_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_certificate` file;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | —                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server              |

指定给定服务器的 PEM 格式证书文件。如果除了主证书外还需要指定中间证书,应按以下顺序在同一文件中指定:主证书在前,然后是中间证书。PEM 格式的密钥可以放在同一文件中。

此指令可以多次指定,以加载不同类型的证书,例如 RSA 和 ECDSA:

```nginx
server {
    listen              993 ssl;

    ssl_certificate     example.com.rsa.crt;
    ssl_certificate_key example.com.rsa.key;

    ssl_certificate     example.com.ecdsa.crt;
    ssl_certificate_key example.com.ecdsa.key;

#    ...
}
```

只有 OpenSSL 1.0.2 或更高版本支持不同证书的单独证书链。对于旧版本,只能使用一个证书链。

可以指定值 `data:`certificate`` 来代替 `file`,这会加载证书而不使用中间文件。

请注意,不当使用此语法可能会带来安全隐患,例如将密钥数据写入 [错误日志](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log)。

<a id="index-1"></a>

<a id="m-ssl-certificate-compression"></a>

### ssl_certificate_compression

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_certificate_compression` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | `ssl_certificate_compression off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                                  |

启用 TLS 1.3 服务器证书 [压缩](https://datatracker.ietf.org/doc/html/rfc8879)。

#### NOTE
该指令在使用 OpenSSL 3.2 或更高版本时受支持;支持的压缩算法列表由库提供。

#### NOTE
该指令在使用 [BoringSSL](https://boringssl.googlesource.com/boringssl/) 时受支持;支持的压缩算法列表包括 `zlib`。

<a id="index-2"></a>

<a id="m-ssl-certificate-key"></a>

### ssl_certificate_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_certificate_key` file;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | —                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                  |

指定给定服务器的 PEM 格式密钥文件。

可以指定值 `engine:`name`:id` 来代替 `file`,这会从 OpenSSL 引擎 name 加载指定 id 的密钥。

可以指定值 `store:scheme:id` 来代替 `file`,用于加载具有指定 id 和 OpenSSL 提供程序注册 URI scheme 的密钥,例如 [pkcs11](https://datatracker.ietf.org/doc/html/rfc7512)。

可以指定值 `data:`key`` 来代替 `file`,这会加载密钥而不使用中间文件。请注意,不当使用此语法可能会带来安全隐患,例如将密钥数据写入 [错误日志](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log)。

<a id="index-3"></a>

<a id="m-ssl-ciphers"></a>

### ssl_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ciphers` ciphers;          |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `ssl_ciphers HIGH:!aNULL:!MD5;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                    |

指定启用的密码。密码以 OpenSSL 库理解的格式指定,例如:

```nginx
ssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
```

密码列表取决于已安装的 OpenSSL 版本。可以使用 `openssl ciphers` 命令查看完整列表。

#### WARNING
当使用 OpenSSL 时,:samp:ssl_ciphers 指令\*不会\*配置 TLS 1.3 的密码。要使用 OpenSSL 调整 TLS 1.3 密码,请使用 [ssl_conf_command](#m-ssl-conf-command) 指令,该指令是为支持高级 SSL 配置而添加的。

- 在 LibreSSL 中,\*可以\* 使用 `ssl_ciphers` 配置 TLS 1.3 密码。
- 在 BoringSSL 中,完全无法配置 TLS 1.3 密码。

<a id="index-4"></a>

<a id="m-ssl-client-certificate"></a>

### ssl_client_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_client_certificate` file;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                     |

指定用于 [验证](#m-ssl-verify-client) 客户端证书的 PEM 格式受信任 CA 证书文件。

证书列表将发送给客户端。如果不希望这样,可以使用 [ssl_trusted_certificate](#m-ssl-trusted-certificate) 指令。

<a id="index-5"></a>

<a id="m-ssl-conf-command"></a>

### ssl_conf_command

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_conf_command` name value;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                     |

设置任意 OpenSSL 配置 [命令](https://docs.openssl.org/master/man3/SSL_CONF_cmd/)。

#### NOTE
该指令在使用 OpenSSL 1.0.2 或更高版本时受支持。
要使用 OpenSSL 配置 TLS 1.3 密码,请使用 `ciphersuites` 命令。

可以在同一级别上指定多个 ssl_conf_command 指令:

```nginx
ssl_conf_command Options PrioritizeChaCha;
ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;
```

这些指令仅在当前级别没有定义 ssl_conf_command 指令时,才会从前一个配置级别继承。

#### WARNING
请注意,直接配置 OpenSSL 可能会导致意外行为。

<a id="index-6"></a>

<a id="m-ssl-crl"></a>

### ssl_crl

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_crl` file;   |
|--------------------------------------------------------------------------------------|-------------------|
| 默认值                                                                                  | —                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server      |

指定用于 [验证](#m-ssl-verify-client) 客户端证书的 PEM 格式撤销证书(CRL)文件。

<a id="index-7"></a>

<a id="m-ssl-dhparam"></a>

### ssl_dhparam

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_dhparam` file;   |
|--------------------------------------------------------------------------------------|-----------------------|
| 默认值                                                                                  | —                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server          |

指定 DHE 密码的 DH 参数文件。

#### WARNING
默认情况下未设置参数,因此不会使用 DHE 密码。

<a id="index-8"></a>

<a id="m-ssl-ecdh-curve"></a>

### ssl_ecdh_curve

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ecdh_curve` curve;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `ssl_ecdh_curve auto;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server              |

指定 ECDHE 密码的曲线。

#### NOTE
当使用 OpenSSL 1.0.2 或更高版本时,可以指定多个曲线,例如:

```nginx
ssl_ecdh_curve prime256v1:secp384r1;
```

特殊值 `auto` 指示 Angie 在使用 OpenSSL 1.0.2 或更高版本时使用 OpenSSL 库内置的列表,或在较旧版本中使用 prime256v1。

#### NOTE
当使用 OpenSSL 1.0.2 或更高版本时,此指令设置服务器支持的曲线列表。因此,为了使 ECDSA 证书正常工作,包含证书中使用的曲线非常重要。

<a id="index-9"></a>

<a id="m-ssl-password-file"></a>

### ssl_password_file

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_password_file` file;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                |

指定一个文件,其中包含 [密钥](#m-ssl-certificate-key) 的密码短语,每个密码短语单独一行。加载密钥时会依次尝试这些密码短语。

示例:

```nginx
mail {
    ssl_password_file /etc/keys/global.pass;
    ...

    server {
        server_name mail1.example.com;
        ssl_certificate_key /etc/keys/first.key;
    }

    server {
        server_name mail2.example.com;

        # 也可以使用命名管道代替文件
        ssl_password_file /etc/keys/fifo;
        ssl_certificate_key /etc/keys/second.key;
    }
}
```

<a id="index-10"></a>

<a id="m-ssl-prefer-server-ciphers"></a>

### ssl_prefer_server_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_prefer_server_ciphers` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `ssl_prefer_server_ciphers off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                                |

指定在使用 SSLv3 和 TLS 协议时,服务器密码应优先于客户端密码。

<a id="index-11"></a>

<a id="m-ssl-protocols"></a>

### ssl_protocols

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_protocols` [`SSLv2`] [`SSLv3`] [`TLSv1`] [`TLSv1.1`] [`TLSv1.2`] [`TLSv1.3`];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|
| 默认值                                                                                  | `ssl_protocols TLSv1.2 TLSv1.3;`                                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                                                                         |

#### Versionchanged
在 1.2.0 版本发生变更: 默认设置中添加了 `TLSv1.3` 参数。

启用指定的协议。

#### NOTE
`TLSv1.1` 和 `TLSv1.2` 参数仅在使用 OpenSSL 1.0.1 或更高版本时有效。

`TLSv1.3` 参数仅在使用 OpenSSL 1.1.1 或更高版本时有效。

<a id="index-12"></a>

<a id="m-ssl-session-cache"></a>

### ssl_session_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_cache` `off` | `none` | [builtin[:size]] [shared:name:size];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| 默认值                                                                                  | `ssl_session_cache none;`                                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                                                                |

设置存储会话参数的缓存类型和大小。缓存可以是以下任意类型:

| `off`     | 严格禁止使用会话缓存:Angie 明确告知客户端会话不可重用。                                                                                                                                                |
|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `none`    | 温和地禁止使用会话缓存:Angie 告知客户端会话可以重用,但实际上不在缓存中存储会话参数。                                                                                                                                 |
| `builtin` | OpenSSL 内置缓存;仅由一个工作进程使用。缓存大小以会话数指定。如果未指定大小,则等于 20480 个会话。使用内置缓存可能导致内存碎片。                                                                                                       |
| `shared`  | 在所有工作进程之间共享的缓存。缓存大小以字节指定;一兆字节可以存储约 4000 个会话。每个共享缓存应有一个任意名称。具有相同名称的缓存可以在多个服务器中使用。除非使用 [ssl_session_ticket_key](#m-ssl-session-ticket-key) 指令显式配置,否则它还用于自动生成、存储和定期轮换 TLS 会话票证密钥。 |

两种缓存类型可以同时使用,例如:

```nginx
ssl_session_cache builtin:1000 shared:SSL:10m;
```

但仅使用共享缓存而不使用内置缓存应该更高效。

<a id="index-13"></a>

<a id="m-ssl-session-ticket-key"></a>

### ssl_session_ticket_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_ticket_key` file;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                     |

设置包含用于加密和解密 TLS 会话票证的密钥的文件。如果需要在多个服务器之间共享相同的密钥,则此指令是必需的。默认情况下,使用随机生成的密钥。

如果指定了多个密钥,则仅使用第一个密钥来加密 TLS 会话票证。这允许配置密钥轮换,例如:

```nginx
ssl_session_ticket_key current.key;
ssl_session_ticket_key previous.key;
```

该文件必须包含 80 或 48 字节的随机数据,可以使用以下命令创建:

```console
openssl rand 80 > ticket.key
```

根据文件大小,使用 AES256(用于 80 字节密钥)或 AES128(用于 48 字节密钥)进行加密。

<a id="index-14"></a>

<a id="m-ssl-session-tickets"></a>

### ssl_session_tickets

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_tickets` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `ssl_session_tickets on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                          |

启用或禁用通过 [TLS 会话票证](https://datatracker.ietf.org/doc/html/rfc5077) 恢复会话。

<a id="index-15"></a>

<a id="m-ssl-session-timeout"></a>

### ssl_session_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_timeout` time;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `ssl_session_timeout 5m;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                  |

指定客户端可以重用会话参数的时间。

<a id="index-16"></a>

<a id="m-ssl-trusted-certificate"></a>

### ssl_trusted_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_trusted_certificate` file;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                      |

指定包含 PEM 格式的受信任 CA 证书的文件,用于 [验证](#m-ssl-verify-client) 客户端证书。

与 [ssl_client_certificate](#m-ssl-client-certificate) 设置的证书集不同,这些证书列表不会发送给客户端。

<a id="index-17"></a>

<a id="m-ssl-verify-client"></a>

### ssl_verify_client

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_verify_client` `on` | `off` | `optional` | `optional_no_ca`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| 默认值                                                                                  | `ssl_verify_client off;`                                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                                                        |

启用客户端证书的验证。验证结果将通过 [认证](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_auth_http.md#m-auth-http) 请求的 `Auth-SSL-Verify` 头传递。如果在客户端证书验证过程中发生错误,或者客户端未提供所需的证书,则连接将被关闭。

| `optional`       | 请求客户端证书,并在证书存在时进行验证                                                                                                                                                                                  |
|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `optional_no_ca` | 请求客户端证书,但不要求其由受信任的 CA 证书签名。这适用于由 Angie 外部的服务执行实际证书验证的情况。证书的内容可以通过 [发送](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_auth_http.md#m-auth-http-pass-client-cert) 到认证服务器的请求访问。 |

<a id="index-18"></a>

<a id="m-ssl-verify-depth"></a>

### ssl_verify_depth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_verify_depth` number;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `ssl_verify_depth 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                 |

设置客户端证书链中的验证深度。

<a id="index-19"></a>

<a id="m-starttls"></a>

### starttls

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `starttls` `on` | `off` | `only`;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `starttls off;`                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | mail, server                        |

| `on`   | 允许对 POP3 使用 STLS 命令,对 IMAP 和 SMTP 使用 STARTTLS 命令;   |
|--------|-----------------------------------------------------|
| `off`  | 拒绝使用 STLS 和 STARTTLS 命令;                            |
| `only` | 要求预先进行 TLS 转换。                                      |


# https://cn.angie.software/news/mi-rastem-i-priglashaem-na-rabotu-spetsialistov.md

# 我们在发展并诚邀专业人才加入我们的团队

*16.06.2023*

我们在发展并诚邀专业人才加入我们的团队 - 招聘Angie网络服务器的C语言开发工程师和QA专家（Perl）

我们在发展并诚邀专业人才加入我们的团队 - 招聘Angie网络服务器的C语言开发工程师和QA专家（Perl）。

我们是谁？
我们是一家俄罗斯认证的IT公司，由Nginx开发和技术支持团队成员创立。我们的目标是开发世界级标准的网络服务器产品和技术。

职位要求
C语言开发工程师：至少3年工作经验，精通C语言和算法数据结构，具有Linux/Unix使用经验，能够使用Git，了解HTTP/HTTPS协议。[C语言开发工程师职位描述](https://disk.yandex.ru/i/Tvy-5wnW4IgpSw)。
QA专家（Perl）：至少2年工作经验，精通Perl，具有Web应用测试经验，了解HTTP/HTTPS协议，熟悉Linux/Unix。[Angie网络服务器QA（Perl）职位描述](https://disk.yandex.ru/i/SoNVKsdTiqSX-g)。

我们提供
在一个稳定且快速发展的公司工作，与高素质的同事共事。
有趣的项目和任务，帮助您在专业领域发展和成长。
位于莫斯科市中心的办公室，灵活的工作时间，以及远程工作的可能性。
具有竞争力的薪资和福利待遇。

如果您准备好接受挑战并加入我们的团队，请将您的简历和问题发送至hr@wbsrv.ru。我们期待审阅您的申请并讨论潜在的合作机会。


# https://cn.angie.software/angie/docs/configuration/migration.md

<!-- review: finished -->

<a id="migration"></a>

# 从 nginx 迁移到 Angie

如果您正在从 nginx 切换到 Angie,恭喜您!
我们为您准备了一份指南。

请注意,本指南针对的是依赖 Angie 软件包版本的基本替换场景。
如果您使用的是 [容器](https://cn.angie.software//angie/docs/installation/docker.md#docker-images)、
虚拟机、自定义路径或
[模块](https://cn.angie.software//angie/docs/installation/index.md#install-dynamicmodules),
您将需要进行额外的调整。

<a id="installing-angie"></a>

## 安装 Angie

我们建议使用来自 [我们仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的官方软件包;
请参阅适用于您的发行版的 Angie 安装步骤。
暂时不要启动服务器;
而是使用命令 **sudo angie -V** 检查它:

```console
$ sudo angie -V

  Angie version: Angie/|version|
  nginx version: nginx/|nginxversion|
  built by gcc 11.4.0
  configure arguments: --prefix=/etc/angie --conf-path=/etc/angie/angie.conf ...
```

如上所示,
当从软件包安装 Angie 时,
[配置](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile) 位于 `/etc/angie/` 中。

<a id="updating-angie-configuration"></a>

## 更新 Angie 配置

Angie 通常只需要对现有 nginx 配置进行最小的更改。

1. 将整个 nginx 配置复制到 `/etc/angie/`:
   ```console
   $ sudo rsync -a --no-links /etc/nginx/ /etc/angie/
   ```

   我们假设 nginx 配置存储在 `/etc/nginx/` 中;
   如果您的路径不同,请调整这些步骤。
2. 按照 Angie 的要求重命名主配置文件:
   ```console
   $ sudo mv /etc/angie/nginx.conf /etc/angie/angie.conf
   ```
3. 更新整个 Angie 配置中的路径,
   从主配置文件开始。
   具体细节取决于 nginx 的安装方式,
   但至少需要更新以下内容。

   任何仍然指向 `/etc/nginx/` 的 [include](https://cn.angie.software//angie/docs/configuration/modules/core.md#include) 路径:
   ```nginx
   # include /etc/nginx/conf.d/*.conf;
   # include /etc/nginx/default.d/*.conf;
   # include /etc/nginx/http.d/*.conf;
   # include /etc/nginx/stream.d/*.conf;
   include /etc/angie/conf.d/*.conf;
   include /etc/angie/default.d/*.conf;
   include /etc/angie/http.d/*.conf;
   include /etc/angie/stream.d/*.conf;

   # include /etc/nginx/sites-enabled/*;
   include /etc/angie/sites-enabled/*;

   # include /etc/nginx/modules-enabled/*;
   include /etc/angie/modules-enabled/*;

   # include /etc/nginx/mime.types;
   include /etc/angie/mime.types;
   ```

   [PID](https://cn.angie.software//angie/docs/configuration/modules/core.md#pid) 文件,这对 Angie 进程管理很重要:
   ```nginx
   # pid /var/run/nginx.pid;
   # -- 或 --
   # pid /run/nginx.pid;
   pid /run/angie.pid;
   ```

   最后,
   [访问日志](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#access-log) 和 [错误日志](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log):
   ```nginx
   # access_log /var/log/nginx/access.log;
   access_log /var/log/angie/access.log;

   # error_log /var/log/nginx/error.log;
   error_log /var/log/angie/error.log;
   ```

<a id="migration-sites"></a>

### 虚拟主机

如果使用 `sites-enabled/` 目录来包含虚拟主机,
也需要更新它:

```nginx
# include /etc/nginx/sites-enabled/*;
include /etc/angie/sites-enabled/*;
```

然后在 `/etc/angie/sites-enabled/` 中重新创建符号链接
以使一切正常工作。

列出原始虚拟主机文件,例如:

```console
$ ls -l /etc/nginx/sites-enabled/

  default -> /etc/nginx/sites-available/default
```

注意它们的实际位置;
这里是 `/etc/nginx/sites-available/`。

如果之前没有将它们复制到 `/etc/angie/`,
现在复制它们:

```console
$ sudo rsync -a /etc/nginx/sites-available/ /etc/angie/sites-available/
```

最后,重新创建每个符号链接:

```console
$ sudo ln -s /etc/angie/sites-available/default \
             /etc/angie/sites-enabled/default
```

<a id="dynamic-modules"></a>

### 动态模块

为 nginx 配置中引用的所有动态模块
查找并 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-dynamicmodules) Angie 等效模块,
例如:

```console
$ sudo nginx -T | grep load_module

  load_module modules/ngx_http_geoip2_module.so;
  load_module modules/ngx_stream_geoip2_module.so;
  ...
```

这意味着您需要安装 `angie-module-geoip2` 包,
依此类推。

有两种常见的方式来包含动态模块配置:

`/usr/share/nginx/modules/`

如果通过 `/usr/share/nginx/modules/` 包含动态模块,
更新路径:

```nginx
# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
# include /usr/share/nginx/modules/*.conf;

include /usr/share/angie/modules/*.conf;
```

然后复制模块配置文件:

```console
$ sudo rsync -a /usr/share/nginx/modules/ /usr/share/angie/modules/
```

最后,在每个文件中更改 [load_module](https://cn.angie.software//angie/docs/configuration/modules/core.md#load-module) 路径:

```nginx
# load_module "/usr/lib64/nginx/modules/ngx_http_geoip2_module.so";
load_module "/usr/lib64/angie/modules/ngx_http_geoip2_module.so";
```

`/etc/nginx/modules-enabled/`

如果通过 `/etc/nginx/modules-enabled/` 包含动态模块,
更新路径:

```nginx
# include /etc/nginx/modules-enabled/*.conf;
include /etc/angie/modules-enabled/*.conf;
```

然后在 `/etc/angie/modules-enabled/` 中重新创建符号链接
以使一切正常工作。

列出原始模块配置文件,例如:

```console
$ ls -l /etc/nginx/modules-enabled/

  mod-http-geoip2.conf -> /usr/share/nginx/modules-available/mod-http-geoip2.conf
```

注意它们的实际位置;
这里是 `/usr/share/nginx/modules-available/`。

将它们复制到 `/usr/share/angie/`:

```console
$ sudo rsync -a /usr/share/nginx/modules-available/ /usr/share/angie/modules-available/
```

最后,重新创建每个符号链接:

```console
$ sudo ln -s /usr/share/angie/modules-available/mod-http-geoip2.conf \
             /etc/angie/modules-enabled/mod-http-geoip2.conf
```

<a id="root-directory-optional"></a>

### 根目录(可选)

如果 [root](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#root) 指向 `/usr/share/nginx/html/` 目录,
您可以更改该指令以指向 Angie。

复制目录并更新 Angie 配置中的 `root` 值:

```console
$ sudo rsync -a /usr/share/nginx/html/ /usr/share/angie/html/
```

```nginx
# root /usr/share/nginx/html;
root /usr/share/angie/html;
```

<a id="user-and-group-optional"></a>

### 用户和组(可选)

虽然保持 [user](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 指令不变就足够了,
但您可以使用 Angie 账户以获得灵活性。

更新 Angie 配置中的 `user` 设置:

```nginx
# user www-data www-data;
user angie angie;
```

更改\*所有\*配置文件的所有者,
包括 `/usr/share/angie/` 中的文件,
例如:

```console
$ sudo chown -R angie:angie /etc/angie/
$ sudo chown -R angie:angie /usr/share/angie/
```

如果 Angie 配置中有 [root](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#root) 指令,
更改其中指定目录的所有者,
例如:

```console
$ sudo chown -R angie:angie /var/www/html/
```

<a id="wrapping-up"></a>

### 收尾工作

为确保没有遗漏,
在 Angie 配置中查找并修复剩余的 `nginx` 引用:

```console
$ grep -rn --include='*.conf' 'nginx' /etc/angie/
```

<a id="testing-and-switching"></a>

## 测试和切换

更新 Angie 配置后,
下一步是检查其语法
以确保 Angie 可以使用它,
然后进行切换。
验证 Angie 接受新配置:

```console
$ sudo angie -t
```

此命令解析配置
并报告会阻止 Angie 启动的错误;
修复任何问题并重新运行该命令。

<a id="stopping-nginx-starting-angie"></a>

### 停止 nginx,启动 Angie

为了最小化停机时间,在停止 nginx 后立即启动 Angie:

```console
$ sudo systemctl stop nginx && sudo systemctl start angie
```

如果需要,启用 Angie 服务以在重启后自动启动:

```console
$ sudo systemctl enable angie
```

迁移完成!就是这样;您真棒。

<a id="disabling-nginx"></a>

### 禁用 nginx

在确认 Angie 稳定运行后,
您可以禁用或删除 nginx 以避免冲突。

您至少可以禁用该服务:

```console
$ sudo systemctl disable nginx
```

<a id="working-with-ssl-certificates"></a>

## 使用 SSL 证书

如果您使用 Certbot 管理 nginx 的 SSL 证书,
它将继续与 Angie 一起工作。

<a id="using-certbot-with-angie"></a>

### 在 Angie 中使用 Certbot

在 Certbot 中支持 Angie 只需最少的工作,
因为 Angie 向后兼容 nginx。
要使 Certbot 工作,只需创建一个符号链接
并指定适当的参数:

```console
# 创建符号链接以实现 Certbot 兼容性
$ sudo ln -s /etc/angie/angie.conf /etc/angie/nginx.conf

# 为域名获取证书
$ sudo certbot --nginx --nginx-server-root=/etc/angie --nginx-ctl=angie -d example.com -d www.example.com

# 自动续订证书
$ sudo certbot renew

# 检查证书状态
$ sudo certbot certificates
```

迁移到 Angie 后,Certbot 将继续通过配置的 **cron** 作业或 **systemd** 定时器自动续订证书。

<a id="migrating-from-certbot-to-the-built-in-acme-module"></a>

### 从 Certbot 迁移到内置 ACME 模块

Angie 包含内置的 [ACME 模块](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme),
它允许您自动获取和续订 SSL 证书,
而无需使用 Certbot 等外部工具。

内置 ACME 模块的优势:

- 与 Angie 配置完全集成;
- 无需额外服务即可自动续订证书;
- 支持 HTTP 和 DNS 验证;
- 能够获取通配符证书。

有关从 Certbot 迁移到内置 ACME 模块的详细说明,
请参阅 [从 certbot 迁移](https://cn.angie.software//angie/docs/configuration/acme.md#acme-config-certbot) 部分。

<a id="configuring-angie-features"></a>

## 配置 Angie 功能

可以肯定地说,您迁移是有原因的。
为什么不更进一步,配置一些 [Angie](https://cn.angie.software//angie/docs/oss_changes.md#oss-changes) 和 [Angie PRO](https://cn.angie.software//angie/docs/pro_changes.md#pro-changes) 中可用的附加功能,
这些功能在 nginx 中是没有的?


# https://cn.angie.software/angie/docs/installation/external-modules/modsecurity.md

<!-- review: finished -->

<a id="external-modsec"></a>

# ModSecurity

该模块添加了一个连接器,用于使用 [ModSecurity](https://modsecurity.org/) 规则。

<a id="installation-17"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-modsecurity`
- Angie PRO:`angie-pro-module-modsecurity`

<a id="loading-the-module-17"></a>

## 加载模块

要使用该模块,需要在 `main{}` 上下文中加载它:

```nginx
load_module modules/ngx_http_modsecurity_module.so;
```

<a id="configuration-example-93"></a>

## 配置示例

在适当的上下文中指定 `modsecurity` 和 `modsecurity_rules_file` 指令,
例如 `server`:

> ```nginx
> server {
>     modsecurity on;
>     modsecurity_rules_file /etc/angie/modsecurity/rules.conf;
>     # ...
> }
> ```

将 [OWASP ModSecurity 核心规则集 (CRS)](https://coreruleset.org/)
复制到 `/var/lib/angie/modsecurity/` 目录:

> ```console
> $ cd /var/lib/angie/modsecurity/
> $ sudo git clone -b v4.1.0 https://github.com/coreruleset/coreruleset
> ```

在核心规则目录中,
复制最低要求的 ModSecurity 配置示例:

```console
$ sudo cp coreruleset/crs-setup.conf.example coreruleset/crs-setup.conf
$ sudo cp coreruleset/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf.example \
      coreruleset/rules/REQUEST-900-EXCLUSION-RULES-BEFORE-CRS.conf
$ sudo cp coreruleset/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf.example \
      coreruleset/rules/RESPONSE-999-EXCLUSION-RULES-AFTER-CRS.conf
```

在 `/etc/angie/modsecurity/rules.conf` 文件中
取消注释以下 `Include` 指令:

```apache
Include /var/lib/angie/modsecurity/coreruleset/crs-setup.conf
Include /var/lib/angie/modsecurity/coreruleset/rules/*.conf
```

<a id="additional-information-18"></a>

## 其他信息

详细文档和源代码可在以下位置获取:
[https://github.com/owasp-modsecurity/ModSecurity](https://github.com/owasp-modsecurity/ModSecurity).


# https://cn.angie.software/angie/docs/configuration/modules.md

<!-- review: finished -->

<a id="modules"></a>

# 原生模块

本指南介绍 Angie 的原生模块,
提供配置示例,列出其指令和参数,
以及内置变量。

<a id="core-module"></a>

## 核心模块

| [Core](https://cn.angie.software//angie/docs/configuration/modules/core.md#core)   | 管理服务文件、进程和其他 Angie 模块。   |
|------------------------------------------------------------------------------------|--------------------------|

<a id="modules-http"></a>

## HTTP 模块

| [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#http-core)                                                  | 处理 HTTP 请求和响应的核心功能,<br/>管理 HTTP 服务器、连接和静态文件。                        |
|----------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| [Access](https://cn.angie.software//angie/docs/configuration/modules/http/http_access.md#http-access)                                        | 基于 IP 地址和 CIDR 范围的访问控制。                                             |
| [ACME](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme)                                              | 使用 ACME 协议为 HTTP 服务器<br/>自动获取和续期 SSL 证书。                            |
| [Docker](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker)                                        | 基于 Docker 容器标签<br/>动态更新代理服务器组。                                      |
| [Addition](https://cn.angie.software//angie/docs/configuration/modules/http/http_addition.md#http-addition)                                  | 在响应正文之前或之后插入指定的代码片段。                                                |
| [API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#http-api)                                                 | RESTful HTTP 接口,用于获取基本 Web 服务器信息和<br/>JSON 格式的统计数据,<br/>以及管理代理服务器组。 |
| [Auth Basic](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_basic.md#http-auth-basic)                            | 基于用户名和密码的基本 HTTP 身份验证<br/>用于访问控制。                                   |
| [Auth Request](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_request.md#http-auth-request)                      | 使用对外部 HTTP 服务的子请求进行授权。                                              |
| [AutoIndex](https://cn.angie.software//angie/docs/configuration/modules/http/http_autoindex.md#http-autoindex)                               | 在没有索引文件时自动生成目录列表。                                                   |
| [Browser](https://cn.angie.software//angie/docs/configuration/modules/http/http_browser.md#http-browser) (已弃用)                               | 基于 `User-Agent` 头的浏览器识别。                                            |
| [Charset](https://cn.angie.software//angie/docs/configuration/modules/http/http_charset.md#http-charset)                                     | 配置和转换响应编码。                                                          |
| [DAV](https://cn.angie.software//angie/docs/configuration/modules/http/http_dav.md#http-dav)                                                 | 使用 WebDAV 协议在服务器上进行文件管理。                                            |
| [Empty GIF](https://cn.angie.software//angie/docs/configuration/modules/http/http_empty_gif.md#http-empty-gif)                               | 提供一个单像素透明 GIF。                                                      |
| [FastCGI](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#http-fastcgi)                                     | 将请求代理到 FastCGI 服务器。                                                 |
| [FLV](https://cn.angie.software//angie/docs/configuration/modules/http/http_flv.md#http-flv)                                                 | Flash Video (FLV) 文件的伪流式传输。                                         |
| [Geo](https://cn.angie.software//angie/docs/configuration/modules/http/http_geo.md#http-geo)                                                 | 将 IP 地址转换为指定的变量值。                                                   |
| [GeoIP](https://cn.angie.software//angie/docs/configuration/modules/http/http_geoip.md#http-geoip)                                           | 使用 MaxMind GeoIP 数据库<br/>基于地理位置获取 IP 地址数据。                          |
| [gRPC](https://cn.angie.software//angie/docs/configuration/modules/http/http_grpc.md#http-grpc)                                              | 将请求代理到 gRPC 服务器。                                                    |
| [GunZIP](https://cn.angie.software//angie/docs/configuration/modules/http/http_gunzip.md#http-gunzip)                                        | 解压 GZip 压缩的响应以进行修改,以及在<br/>客户端不支持压缩的情况下使用。                          |
| [GZip](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#http-gzip)                                              | 使用 GZip 方法压缩响应以节省流量。                                                |
| [GZip Static](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip_static.md#http-gzip-static)                         | 提供使用 GZip 方法预压缩的静态文件。                                               |
| [Headers](https://cn.angie.software//angie/docs/configuration/modules/http/http_headers.md#http-headers)                                     | 修改响应头字段。                                                            |
| [HTTP2](https://cn.angie.software//angie/docs/configuration/modules/http/http_v2.md#http-v2)                                                 | 使用 HTTP/2 协议处理请求。                                                   |
| [HTTP3](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#http-v3)                                                 | 使用 HTTP/3 协议处理请求。                                                   |
| [Image Filter](https://cn.angie.software//angie/docs/configuration/modules/http/http_image_filter.md#http-image-filter) <sup>[1](#id8)</sup> | 图像转换。                                                               |
| [Index](https://cn.angie.software//angie/docs/configuration/modules/http/http_index.md#http-index)                                           | 配置索引文件,<br/>用于处理以斜杠 (`/`) 结尾的请求。                                    |
| [Limit Conn](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_conn.md#http-limit-conn)                            | 限制并发请求数(活动连接数)<br/>以防止过载。                                           |
| [Limit Req](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_req.md#http-limit-req)                               | 限制请求频率<br/>以防止过载和密码猜测。                                              |
| [Log](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#http-log)                                                 | 配置请求日志以跟踪资源访问<br/>用于监控和分析目的。                                        |
| [Map](https://cn.angie.software//angie/docs/configuration/modules/http/http_map.md#http-map)                                                 | 基于预定义的键值对转换变量。                                                      |
| [Metric](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#http-metric)                                        | 实时统计 API 中的自定义数值指标。                                                 |
| [Memcached](https://cn.angie.software//angie/docs/configuration/modules/http/http_memcached.md#http-memcached)                               | 从 Memcached 服务器检索响应。                                                |
| [Mirror](https://cn.angie.software//angie/docs/configuration/modules/http/http_mirror.md#http-mirror)                                        | 将请求镜像到其他服务器。                                                        |
| [MP4](https://cn.angie.software//angie/docs/configuration/modules/http/http_mp4.md#http-mp4)                                                 | MP4 文件的伪流式传输。                                                       |
| [Perl](https://cn.angie.software//angie/docs/configuration/modules/http/http_perl.md#http-perl) <sup>[1](#id8)</sup>                         | 通过在 Perl 语言中指定附加逻辑<br/>来扩展功能的处理程序。                                  |
| [Prometheus](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#http-prometheus)                            | Prometheus 兼容格式的服务器指标<br/>用于监控和统计收集。                                |
| [Proxy](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy)                                           | 将请求反向代理到其他 HTTP 服务器。                                                |
| [Random Index](https://cn.angie.software//angie/docs/configuration/modules/http/http_random_index.md#http-random-index)                      | 为以斜杠 (`/`) 结尾的请求<br/>随机选择索引文件。                                      |
| [RealIP](https://cn.angie.software//angie/docs/configuration/modules/http/http_realip.md#http-realip)                                        | 在另一个代理服务器后运行时<br/>确定客户端地址和端口。                                       |
| [Referer](https://cn.angie.software//angie/docs/configuration/modules/http/http_referer.md#http-referer)                                     | 验证 `Referer` 头值。                                                    |
| [Rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#http-rewrite)                                     | 请求 URI 修改、重定向、变量设置<br/>和条件配置选择。                                     |
| [SCGI](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#http-scgi)                                              | 将请求代理到 SCGI 服务器。                                                    |
| [Secure Link](https://cn.angie.software//angie/docs/configuration/modules/http/http_secure_link.md#http-secure-link)                         | 创建具有限制访问时间能力的安全链接。                                                  |
| [Slice](https://cn.angie.software//angie/docs/configuration/modules/http/http_slice.md#http-slice)                                           | 将请求拆分为多个子请求以获取单个片段,<br/>以便更好地缓存大型响应。                                |
| [Split Clients](https://cn.angie.software//angie/docs/configuration/modules/http/http_split_clients.md#http-split-clients)                   | 创建用于 A/B 测试、金丝雀发布、分片<br/>和其他需要按比例分组的场景的变量。                          |
| [SSI](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssi.md#http-ssi)                                                 | 处理响应中的 SSI(服务器端包含)命令。                                               |
| [SSL](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#http-ssl)                                                 | 用于处理 HTTPS 请求的 SSL/TLS 配置。                                          |
| [Stub Status](https://cn.angie.software//angie/docs/configuration/modules/http/http_stub_status.md#http-stub-status) (已弃用)                   | 文本格式的全局连接和请求计数器。                                                    |
| [Sub](https://cn.angie.software//angie/docs/configuration/modules/http/http_sub.md#http-sub)                                                 | 在响应正文中搜索和替换片段。                                                      |
| [Upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream)                                  | 配置用于负载均衡的代理服务器组。                                                    |
| [Upstream Probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#http-upstream-probe)                | 为代理服务器组<br/>配置主动健康探测。                                               |
| [UserID](https://cn.angie.software//angie/docs/configuration/modules/http/http_userid.md#http-userid)                                        | 发放和处理带有唯一客户端标识符的 Cookie<br/>用于会话跟踪和分析。                              |
| [uWSGI](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#http-uwsgi)                                           | 将请求代理到 uWSGI 服务器。                                                   |
| [XSLT](https://cn.angie.software//angie/docs/configuration/modules/http/http_xslt.md#http-xslt) <sup>[1](#id8)</sup>                         | 使用 XSLT 语言转换 XML 文档。                                                |

<a id="modules-stream"></a>

## Stream 模块

| [Stream](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#stream-core)                                   | 用于在 L4 层面平衡 TCP 和 UDP 协议的<br/>核心流服务器功能。                         |
|-------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [Access](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_access.md#stream-access)                         | 基于 IP 地址和 CIDR 范围的访问控制。                                         |
| [ACME](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_acme.md#stream-acme)                               | 使用 ACME 协议为流服务器<br/>自动获取和续期 SSL 证书。                             |
| [Geo](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_geo.md#stream-geo)                                  | 将 IP 地址转换为指定的变量值。                                               |
| [GeoIP](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_geoip.md#stream-geoip)                            | 使用 MaxMind GeoIP 数据库<br/>基于地理位置获取 IP 地址数据。                      |
| [Limit Conn](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_limit_conn.md#stream-limit-conn)             | 限制并发连接数<br/>以防止过载。                                              |
| [Log](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_log.md#stream-log)                                  | 配置会话日志以跟踪资源访问<br/>用于监控和分析目的。                                    |
| [Map](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_map.md#stream-map)                                  | 基于预定义的键值对转换变量。                                                  |
| [MQTT Preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#stream-mqtt-preread)       | 在做出负载均衡决策之前<br/>从 MQTT 连接中读取客户端标识符和用户名。                         |
| [Pass](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_pass.md#stream-pass)                               | 将接受的连接<br/>直接传递到配置的监听套接字。                                       |
| [Proxy](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#stream-proxy)                            | 配置到其他服务器的代理。                                                    |
| [RDP Preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#stream-rdp-preread)          | 在做出负载均衡决策之前<br/>从 RDP 连接中读取 Cookie。                             |
| [RealIP](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_realip.md#stream-realip)                         | 在另一个代理服务器后运行时<br/>确定客户端地址和端口。                                   |
| [Return](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_return.md#stream-return)                         | 在连接时向客户端发送指定值<br/>而不进行进一步代理。                                    |
| [Set](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_set.md#stream-set)                                  | 设置指定的变量值。                                                       |
| [Split Clients](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_split_clients.md#stream-split-clients)    | 创建用于 A/B 测试、金丝雀发布、分片<br/>和其他需要按比例分组的场景的变量。                      |
| [SSL](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#stream-ssl)                                  | SSL/TLS 和 DTLS 协议终止。                                            |
| [SSL Preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#stream-ssl-preread)          | 在不进行 SSL/TLS 终止的情况下从 `ClientHello` 消息中提取信息,<br/>并在做出负载均衡决策之前使用。 |
| [Upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream)                   | 配置用于负载均衡的代理服务器组。                                                |
| [Upstream Probe](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#stream-upstream-probe) | 为代理服务器组<br/>配置主动健康探测。                                           |

<a id="modules-mail"></a>

## 邮件模块

| [Mail](https://cn.angie.software//angie/docs/configuration/modules/mail/index.md#mail-core)                    | 核心邮件代理服务器功能。                                |
|----------------------------------------------------------------------------------------------------------------|---------------------------------------------|
| [Auth HTTP](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_auth_http.md#mail-auth-http) | 使用 HTTP 请求向外部服务器进行用户身份验证和服务器选择,<br/>以便后续代理。 |
| [IMAP](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_imap.md#mail-imap)                | IMAP 协议支持。                                  |
| [POP3](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_pop3.md#mail-pop3)                | POP3 协议支持。                                  |
| [Proxy](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_proxy.md#mail-proxy)             | 配置到其他服务器的代理。                                |
| [RealIP](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_realip.md#mail-realip)          | 在另一个代理服务器后运行时<br/>确定客户端地址和端口。               |
| [SMTP](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_smtp.md#mail-smtp)                | SMTP 协议支持。                                  |
| [SSL](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_ssl.md#mail-ssl)                   | SSL/TLS 和 StartTLS 协议支持。                    |

<a id="google-perftools-module"></a>

## Google PerfTools 模块

| [Google PerfTools](https://cn.angie.software//angie/docs/configuration/modules/google_perftools.md#google-perftools)   | 负责与 Google Performance Tools 库集成,<br/>用于应用程序性能分析。   |
|------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------|

<a id="modules-wasm"></a>

## WASM 模块

| [WASM](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#wasm-core) <sup>[1](#id8)</sup>   | 核心 WASM 功能,在 Angie 中启用 WASM 代码执行。                                                                 |
|--------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------|
| [WAMR](https://cn.angie.software//angie/docs/configuration/modules/wasm/wasm_wamr.md#wasm-wamr)                    | 与<br/>[WebAssembly Micro Runtime](https://github.com/bytecodealliance/wasm-micro-runtime)<br/>集成。 |
| [Wasmtime](https://cn.angie.software//angie/docs/configuration/modules/wasm/wasm_wasmtime.md#wasm-wasmtime)        | 与 [Wasmtime](https://wasmtime.dev/) 运行时环境集成。                                                      |

### 脚注

* <a id='id8'>**[1]**</a> 在我们的构建中,这些模块是动态编译的, 并作为 [独立软件包](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 安装; 详细信息请参阅每个模块的说明。


# https://cn.angie.software/angie/docs/configuration/monitoring.md

<!-- review: finished -->

<a id="monitoring"></a>

# Console Light Web 监控面板

Angie 提供了广泛的监控工作方式;除了 [指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics) API 和 [Prometheus](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#http-prometheus) 模块外,您还可以使用安装在服务器旁边的可视化控制台。

<a id="console-light"></a>

## Console Light

Console Light 是一个轻量级的实时活动监控界面,显示关键的服务器负载和性能指标。该控制台基于 Angie 的 [API
功能](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#http-api);活动监控数据实时生成。此外,该控制台允许您在 API 本身提供此功能的情况下动态 [修改](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config) Angie 配置。

已部署和配置的控制台示例:[https://console.angie.software/](https://console.angie.software/)

<a id="version-history"></a>

## 版本历史

| 版本    | 发布日期       | 变更                                                                                                                                                                                                                                      |
|-------|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1.8.2 | 23.01.2026 | 修复了指向 Angie ADC 文档的链接。                                                                                                                                                                                                                  |
| 1.8.1 | 08.09.2025 | 修复了 Settings 和工具提示中的错误术语。                                                                                                                                                                                                               |
| 1.8.0 | 03.07.2025 | 显示代理 HTTP 和 TCP/UDP 服务器的响应时间指标                                                                                                                                                                                                          |
| 1.7.2 | 07.04.2025 | 在 HTTP/TCP/UDP Upstreams 页面的过滤器控制器中添加了"busy"选项。                                                                                                                                                                                         |
| 1.7.1 | 04.04.2025 | 修复了 HTTP Zones 页面上 HTTP/Location Zones 表中的错误值。                                                                                                                                                                                          |
| 1.7.0 | 02.04.2025 | - 鼠标悬停时显示精确的字节数据量<br/>- 统计 API 中上游对等节点的新 `busy` 状态,表示对等节点已达到 `max_conns` 参数配置的限制<br/>- 修复了文档链接                                                                                                                                          |
| 1.6.1 | 27.01.2025 | - 修复了拼写错误<br/>- 修复了开发时项目构建问题                                                                                                                                                                                                            |
| 1.6.0 | 23.01.2025 | - 国际化支持,可用语言环境:`en`、`ru`。<br/>- 为表格组件添加了粘性标题功能。<br/>- 支持 pebibytes (PiB) 数据测量单位。<br/>- 修复了主页面 [HTTP Upstreams](#console-http-upstreams-widget) 小部件中的错误值计数器。<br/>- 现在在响应上下文中的 [HTTP Upstreams](#console-http-upstreams-page) 页面上正确使用默认值。 |
| 1.5.0 |            | 未公开发布。                                                                                                                                                                                                                                  |
| 1.4.0 | 08.08.2024 | 在网站图标中添加了监控状态显示。                                                                                                                                                                                                                        |
| 1.3.0 | 28.04.2024 | 添加了在上游上下文中将服务器设置为 `draining` 状态的功能。                                                                                                                                                                                                     |
| 1.2.1 | 26.12.2023 | 在 `Stream` 上下文中添加了主动健康检查。                                                                                                                                                                                                               |
| 1.2.0 | 25.12.2023 | 在 `Stream` 上下文中添加了服务器编辑功能。                                                                                                                                                                                                              |

<a id="installation-and-configuration"></a>

## 安装和配置

Console Light 以
`angie-console-light` (Angie)
和
`angie-pro-console-light` (Angie PRO)
软件包的形式发布在
[我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 中,
可以像安装任何其他软件包一样安装;
或者,您可以从
[我们的网站](https://download.angie.software/files/angie-console-light/)
或
[GitHub](https://github.com/webserver-llc/angie-console-light)
下载源代码。

安装后,
通过在 [服务器配置](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile) 的
[server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 块内添加以下 [location](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#location)
来配置控制台
(注意注释):

```nginx
location /console/ {

    # 仅本地访问
    allow 127.0.0.1;
    deny all;

    auto_redirect on;

    alias /usr/share/angie-console-light/html/;
    # 仅 FreeBSD:
    # alias /usr/local/www/angie-console-light/html/;
    index index.html;

    location /console/api/ {
        api /status/;
    }

    # 为了在身份验证后使编辑功能正常工作(仅 PRO)
    location /console/api/config/ {

        auth_basic           "Protected site";
        auth_basic_user_file conf/htpasswd;

        api /config/;
    }
}
```

不要忘记应用修改后的配置:

```console
$ sudo angie -t && sudo service angie reload
```

之后,控制台将在 `server` 块指定的服务器上可用,
路径为 `location` 指定的路径;
在上面的示例中,路径设置为 `/console/`。

可以为任何 API 部分启用身份验证,
类似于上面的示例,例如:

```nginx
location /console/server_zones/ {
    auth_basic           "Protected site";
    auth_basic_user_file conf/htpasswd;
}
```

您还可以限制对已配置控制台 `location` 的任何部分的访问,例如:

```nginx
location /console/api/resolvers/ {
    deny all;
}
```

<a id="interface"></a>

## 界面

控制台是一个带有一组选项卡的单一屏幕,
每个选项卡包含多个带有监控数据的小部件。

<a id="angie-tab"></a>

### Angie 选项卡

![Console Light - 主屏幕](../../_images/console_light/en/main.webp)

这是主选项卡,其中以摘要形式显示关键的 Angie 监控指标,基于来自多个 API 部分的数据。

#### NOTE
如果在 [Angie 配置](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile) 中配置了相应的块,
则会显示统计小部件。

<a id="about-widget"></a>

#### About 小部件

显示 Angie 版本号及指向相应文档的链接,以及服务器地址和上次 [配置重新加载](https://cn.angie.software//angie/docs/configuration/runtime.md#control-config-change) 的时间。

此外,如果启用了 [api_config_files](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api-config-files) 指令,
*Configs* 链接会打开服务器上加载的配置文件列表。
然后可以以紧凑格式查看每个文件,并带有语法高亮显示。

<a id="connections-widget"></a>

#### Connections 小部件

显示基本的服务器连接统计信息,从
`/status/connections/` API 部分生成:

| `Current`    | 当前连接数    |
|--------------|----------|
| `Accepted/s` | 每秒接受的连接数 |
| `Active`     | 活动连接数    |
| `Idle`       | 空闲连接数    |
| `Dropped`    | 丢弃的连接数   |

还可用:

| `Accepted`   | 自上次服务器重新加载以来接受的连接总数   |
|--------------|-----------------------|

<a id="http-zones-widget"></a>

#### HTTP Zones 小部件

#### WARNING
需要在 `server` 或 `location` 上下文中设置 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令。

显示 `http` 上下文的共享内存区域统计信息,
从 [/status/http/server_zones/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-server-zones) API 部分生成:

| `Total`    | 区域总数       |
|------------|------------|
| `Problems` | 存在任何问题的区域数 |
| `Traffic`  | 传入和传出流量总量  |

<a id="console-http-upstreams-widget"></a>

#### HTTP Upstreams 小部件

#### WARNING
需要在 `http` 上下文的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 块中设置 [zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-zone) 指令。

显示 `http` 上下文的上游统计信息,从 [/status/http/upstreams/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-upstreams) API 部分生成:

| Total    | 上游总数          |
|----------|---------------|
| Problems | 存在任何问题的上游数量   |
| Servers  | 按状态细分的服务器统计信息 |

<a id="tcp-udp-zones-widget"></a>

#### TCP/UDP Zones 小部件

#### WARNING
需要设置以下指令:

- 在 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 或 [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-status-zone) 上下文中设置 `status_zone`;
- 在 [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#limit-conn) 或 [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_limit_conn.md#s-limit-conn) 上下文中设置 `limit_conn`;
- 在 `stream` 上下文中设置 [limit_conn_zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_conn.md#limit-conn-zone)。

示例:

```nginx
stream {

    # ...
    limit_conn_zone $connection zone=limit-conn-stream:10m;

    server {

        # ...
        limit_conn limit-conn-stream 1;
        status_zone foo;
    }
}
```

显示 `stream` 上下文的共享内存区域统计信息,从 [/status/stream/server_zones/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-stream-server-zones) API 部分生成:

| Conn total   | 客户端连接总数   |
|--------------|-----------|
| Conn current | 当前客户端连接数  |
| Conn/s       | 每秒处理的连接数  |

<a id="tcp-udp-upstreams-widget"></a>

#### TCP/UDP Upstreams 小部件

#### WARNING
需要在 `stream` 上下文的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-upstream) 块中设置 [zone](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-zone) 指令。

显示 `stream` 上下文的上游统计信息,从 [/status/stream/upstreams/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-stream-upstreams) API 部分生成:

| Total    | 上游总数          |
|----------|---------------|
| Problems | 存在任何问题的上游数量   |
| Servers  | 按状态细分的服务器统计信息 |

<a id="http-zones-tab"></a>

### HTTP Zones 选项卡

#### WARNING
需要在 `server` 或 `location` 上下文中设置 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令。

<a id="server-zones-section"></a>

#### Server Zones 部分

![Console Light — "HTTP Zones"选项卡上的"Server Zones"部分](../../_images/console_light/en/http-server-zones.webp)

汇总 `http` 中 `server` 上下文的共享内存区域监控统计信息,从 [/status/http/server_zones/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-server-zones) API 部分生成。为每个区域显示以下数据:

| Zone      | 区域名称                                              |
|-----------|---------------------------------------------------|
| Requests  | 请求总数和每秒请求数                                        |
| Responses | 按状态码细分的响应数量及其总数                                   |
| Traffic   | 出站和入站流量速率,以及出站和入站流量的总量                            |
| SSL       | 汇总计数:成功的 SSL 握手;SSL 会话重用;超时过期的 SSL 握手;不成功的 SSL 握手 |

<a id="location-zones-section"></a>

#### Location Zones 部分

![Console Light — "HTTP Zones"选项卡上的"Location Zones"部分](../../_images/console_light/en/http-location-zones.webp)

汇总 `http` 中 `location` 上下文的共享内存区域监控统计信息,从 [/status/http/location_zones/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-location-zones) API 部分生成。为每个区域显示以下数据:

| Zone      | 区域名称                   |
|-----------|------------------------|
| Requests  | 请求总数和每秒请求数             |
| Responses | 按状态码细分的响应数量及其总数        |
| Traffic   | 出站和入站流量速率,以及出站和入站流量的总量 |

<a id="connection-limit-zones-limit-conn-section"></a>

#### Connection Limit Zones (Limit Conn) 部分

![Console Light — "HTTP Zones"选项卡上的"Connection Limit Zones"部分](../../_images/console_light/en/http-limit-conn.webp)

显示 `http` 上下文中 `limit_conn` 区域的统计信息,从 [/status/http/limit_conns/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-limit-conns) API 部分生成。为每个区域显示以下数据:

| Zone      | 区域名称                     |
|-----------|--------------------------|
| Passed    | 已代理连接总数                  |
| Rejected  | 已拒绝连接总数                  |
| Exhausted | 由于区域存储溢出而丢弃的连接总数         |
| Skipped   | 使用零字节或大于 255 字节密钥通过的连接总数 |

<a id="request-limit-zones-limit-req-section"></a>

#### Request Limit Zones (Limit Req) 部分

![Console Light — "HTTP Zones"选项卡上的"Request Limit Zones"部分](../../_images/console_light/en/http-limit-req.webp)

显示 `http` 上下文中 `limit_reqs` 区域的统计信息,从 [/status/http/limit_reqs/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-limit-reqs) API 部分生成。为每个区域显示以下数据:

| Zone      | 区域名称                     |
|-----------|--------------------------|
| Passed    | 已代理连接总数                  |
| Delayed   | 已延迟连接总数                  |
| Rejected  | 已拒绝连接总数                  |
| Exhausted | 由于区域存储溢出而丢弃的连接总数         |
| Skipped   | 使用零字节或大于 255 字节密钥通过的连接总数 |

<a id="console-http-upstreams-page"></a>

### HTTP 上游 选项卡

![Console Light — "HTTP 上游"选项卡](../../_images/console_light/en/http-upstreams.webp)

#### WARNING
需要在 `http` 上下文的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 块中设置 [zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-zone) 指令。

此选项卡汇总 `http` 上下文的上游监控统计信息，从 [/status/http/upstreams/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-upstreams)
API 部分生成。在调试模式下,还会显示内存使用百分比。

- Show upstreams list 按钮可切换显示包含问题上游和对等节点数量的简要列表。
- Failed only 开关可切换问题上游统计信息的显示模式。
- 编辑按钮可切换 upstream editing (上游编辑)界面。
- 每个上游表右侧的下拉列表允许您按特定状态(Up、Failed、Checking、
  Down)筛选服务器。

对于每个上游,除了其名称和共享内存区域利用率之外,还显示以下数据:

| Server          | 上游服务器的名称、停机时间和权重                                           |
|-----------------|------------------------------------------------------------|
| Requests        | 请求总数和处理速率                                                  |
| Responses       | 按状态码细分的响应数量                                                |
| Connections     | 活动连接数及其最大限制(如果已设置)                                         |
| Traffic         | 出站和入站流量速率,以及出站和入站流量的总量                                     |
| Server checks   | 联系服务器失败的尝试次数以及服务器被视为不可用的次数(API 中的 `health` 对象)             |
| Health monitors | 服务器检查总数、不成功检查的数量以及最后一次检查的时间                                |
| Response time   | 从请求开始到发送响应的第一个字节的时间;从请求开始到完成发送整个响应的总时间(API 中的 `health` 对象) |

<a id="console-http-upstreams-editing"></a>

#### 编辑上游

在 Angie PRO 中,每个上游旁边都有一个编辑按钮;点击后,
会显示另外两个按钮:

| Edit selected   | 编辑上游中选定的服务器。允许您<br/>一次性为所有服务器设置以下参数:Weight (权重)、<br/>最大连接数限制(Max_conns)、标记服务器为不可用的最大失败<br/>次数限制(Max_fails)、计算最大失败次数限制的失败<br/>时间窗口(Fail_timeout)、状态(active – 启用、<br/>down – 禁用,或 draining – 仅接收<br/>先前通过 sticky 绑定的会话请求)。<br/><br/>您也可以在此处删除选定的服务器。<br/><br/>![Console Light — 在"HTTP Upstreams"选项卡上<br/>编辑服务器](../../_images/console_light/en/http_upstreams_edit_servers.webp)   |
|-----------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Add server      | 向上游添加服务器。允许您设置以下参数:<br/>地址、是否为备份服务器、Weight (权重)、最大连接数<br/>限制(Max_conns)、标记服务器为不可用的最大失败次数限制<br/>(Max_fails)、失败计数时间<br/>窗口(Fail_timeout)、状态(active – 启用、<br/>down – 禁用,或 draining – 仅接收<br/>先前通过 sticky 绑定的会话请求)。<br/><br/>![Console Light — 在"HTTP Upstreams"选项卡上<br/>添加服务器](../../_images/console_light/en/http_upstreams_add_server.webp)                                        |

<a id="samp-tcp-udp-zones-tab"></a>

### TCP/UDP Zones 选项卡

#### WARNING
需要设置以下指令:

- 在 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 或 [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-status-zone) 上下文中设置 `status_zone`;
- 在 [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#limit-conn) 或 [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_limit_conn.md#s-limit-conn) 上下文中设置 `limit_conn`;
- 在 `stream` 上下文中设置 [limit_conn_zone](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_conn.md#limit-conn-zone)。

示例:

```nginx
stream {

    # ...
    limit_conn_zone $connection zone=limit-conn-stream:10m;

    server {

        # ...
        limit_conn limit-conn-stream 1;
        status_zone foo;
    }
}
```

<a id="samp-tcp-udp-zones-section"></a>

#### TCP/UDP Zones 部分

![Console Light — "TCP/UDP Zones"选项卡](../../_images/console_light/en/stream-zones.webp)

汇总 `stream` 中 `server` 上下文的共享内存区域监控统计信息,
由 [/status/stream/server_zones/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-stream-server-zones) API 部分生成。每个区域显示以下数据:

| Zone        | 区域名称                                     |
|-------------|------------------------------------------|
| Connections | 当前和总连接数,以及每秒连接数                          |
| Sessions    | 按状态码细分的会话数,<br/>以及它们的总数                  |
| Traffic     | 出站和入站流量速率,以及出站和入站流量的总量                   |
| SSL         | 汇总计数:成功的 SSL 握手;失败的 SSL 握手;<br/>SSL 会话重用 |

<a id="samp-connection-limit-zones-limit-conn-section"></a>

#### Connection Limit Zones (Limit Conn) 部分

![Console Light — "TCP/UDP Zones"选项卡上的"Connection Limit Zones"部分](../../_images/console_light/en/stream-limit-conn.webp)

显示 `stream` 上下文中 `limit_conn` 区域的统计信息,由
[/status/stream/limit_conns/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-limit-conns) API 部分生成。每个区域显示以下数据:

| Zone      | 区域名称                     |
|-----------|--------------------------|
| Passed    | 代理连接的总数                  |
| Rejected  | 拒绝连接的总数                  |
| Exhausted | 由于区域存储溢出而丢弃的连接总数         |
| Skipped   | 使用零字节或大于 255 字节密钥通过的连接总数 |

<a id="samp-tcp-udp-upstreams-tab"></a>

### TCP/UDP Upstreams 选项卡

![Console Light — "TCP/UDP Upstreams"选项卡](../../_images/console_light/en/stream-upstreams.webp)

#### WARNING
需要在 `stream` 上下文的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-upstream) 块中
设置 [zone](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-zone) 指令。

此选项卡汇总 `stream` 上下文的上游监控统计信息,
由 [/status/stream/upstreams/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-stream-upstreams) API 部分生成。
在调试模式下,还会显示内存使用百分比。

- Show upstreams list 按钮切换显示包含问题上游和对等点数量的简要上游列表。
- Failed only 开关启用和禁用问题上游统计信息的显示模式。
- 编辑按钮打开 upstream editing (上游编辑)小部件。
- 每个上游表右侧的下拉列表允许您
  筛选特定状态的服务器(Up、Failed、Checking、
  Down)。

对于每个上游,显示以下数据:

| Server          | 上游服务器的名称、停机时间和权重                                                                              |
|-----------------|-----------------------------------------------------------------------------------------------|
| Connections     | 活动连接数及其最大限制(如果已设置)                                                                            |
| Traffic         | 出站和入站流量速率,以及出站和入站流量的总量                                                                        |
| Server checks   | 联系服务器失败的尝试次数以及服务器<br/>被视为不可用的次数(API 中的 `health` 对象)                                           |
| Health monitors | 服务器检查的总次数、<br/>失败检查的次数以及最后一次检查的时间                                                             |
| Response time   | 建立与后端连接所花费的时间;<br/>从请求开始到接收响应的第一个字节的时间;<br/>从请求开始到接收响应的最后一个字节所经过的总时间<br/>(API 中的 `health` 对象) |

<a id="console-stream-upstreams-editing"></a>

#### 编辑上游

在 Angie PRO 中,每个上游旁边都有一个编辑按钮;点击后,
会显示另外两个按钮:

| `Edit selected`   | 编辑上游中选定的服务器。允许您一次性为所有服务器设置以下参数:<br/>`Weight` (权重)、最大连接数限制(`Max_conns`)、<br/>将服务器标记为不可用的最大失败次数限制(`Max_fails`)、<br/>计算最大失败次数限制的失败时间窗口(`Fail_timeout`)、<br/>状态(`active` – 启用、`down` – 禁用,或<br/>`draining` – 仅接收先前通过 `sticky` 绑定的会话请求)。<br/><br/>您也可以在此处删除选定的服务器。<br/><br/>![Console Light – 在"TCP/UDP Upstreams"选项卡上编辑服务器](../../_images/console_light/en/http_upstreams_edit_servers.webp)   |
|-------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `Add server`      | 向上游添加服务器。允许您设置以下参数:<br/>地址、是否为备份服务器、`Weight` (权重)、最大连接数限制<br/>(`Max_conns`)、将服务器标记为不可用的最大失败次数限制<br/>(`Max_fails`)、失败计数时间窗口(`Fail_timeout`)、<br/>状态(`active` – 启用、`down` – 禁用,或<br/>`draining` – 仅接收先前通过 `sticky` 绑定的会话请求)。<br/><br/>![Console Light – 在"TCP/UDP Upstreams"选项卡上添加服务器](../../_images/console_light/en/http_upstreams_add_server.webp)                                        |

<a id="samp-caches-tab"></a>

### `Caches` 选项卡

![Console Light – "Caches"选项卡](../../_images/console_light/en/caches.webp)

#### WARNING
需要在 `http` 上下文中设置 [proxy_cache_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-path) 指令。

此选项卡汇总了 `http` 上下文中 `proxy_cache` 区域的监控统计信息,
这些信息从 [/status/http/caches/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-http-caches) API
部分生成。每个区域显示以下数据:

| `Zone`         | 区域名称                                |
|----------------|-------------------------------------|
| `State`        | 缓存状态:cold(元数据正在加载到内存中)或 hot(元数据已加载) |
| `Memory usage` | 内存利用率                               |
| `Max size`     | 最大内存大小                              |
| `Used`         | 已使用内存大小                             |
| `Disk usage`   | 磁盘利用率                               |
| `Traffic`      | 从缓存提供的流量、写入缓存的流量以及绕过缓存返回的流量         |
| `Hit ratio`    | 缓存命中率(从缓存提供的流量与总流量的比率)              |

如果为某个区域启用了 [分片](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache),它将显示为一个
下拉列表,列出各个分片:

| `Path`       | 分片在磁盘上的路径                           |
|--------------|-------------------------------------|
| `State`      | 分片状态:cold(元数据正在加载到内存中)或 hot(元数据已加载) |
| `Max size`   | 最大内存大小                              |
| `Used`       | 已使用内存大小                             |
| `Disk usage` | 磁盘利用率                               |

<a id="samp-shared-zones-tab"></a>

### `Shared Zones` 选项卡

![Console Light – "Shared Zones"选项卡](../../_images/console_light/en/shared_zones.webp)

此选项卡汇总了\*\*所有\*\*上下文中所有共享内存区域的监控统计信息。
每个区域显示以下数据:

| `Zone`               | 区域名称     |
|----------------------|----------|
| `Total memory pages` | 内存页总数    |
| `Used memory pages`  | 已使用的内存页数 |
| `Memory usage`       | 区域的内存利用率 |

<a id="samp-dns-resolvers-tab"></a>

### `DNS Resolvers` 选项卡

![Console Light – "Resolvers" 选项卡](../../_images/console_light/en/resolvers.webp)

#### WARNING
需要在 `http` 上下文中设置 [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 指令。

此选项卡汇总了 DNS 共享内存区域中的查询统计信息,
这些信息从 [/status/resolvers/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-resolvers) API 部分生成。
每个区域显示以下数据:

| `Zone`      | 区域名称                                                                                                           |
|-------------|----------------------------------------------------------------------------------------------------------------|
| `Requests`  | A 和 AAAA、SRV、PTR 类型请求的数量                                                                                       |
| `Responses` | 按相应代码细分的响应数量(`Success`、`Format error`、<br/>`Server failure`、`Name error`、`Not implemented`、<br/>`Refused` 及其他) |

<a id="samp-settings-widget"></a>

### `Settings` 小部件

![Console Light – "Settings" 小部件](../../_images/console_light/en/cog.webp)

允许您配置控制台的常规参数:

- 数据刷新率。默认值 – 1 秒。
- `4xx` 状态的阈值比率。当达到阈值时,
  与服务器响应相关的相应部分将出现"黄色"警告。
  默认值 – 7%。
- 计算缓存命中率的时间窗口。默认值 – 300 秒。
- 解析器的错误阈值。当达到阈值时,解析器将变为"红色"。
  默认值 – 3%。
- 控制台界面语言。可用选项:英语和俄语。
  默认情况下,控制台语言根据浏览器中设置的区域设置选择。

<a id="console-control-panel"></a>

### 控制台控制面板

在所有选项卡上,页面左侧中间位置有一个滑出面板,带有两个按钮 ![Console Light – "About" 选项卡上的控制台控制按钮](../../_images/console_light/en/play.webp)。
顶部按钮用于暂停和恢复从 API 更新数据,
底部按钮允许您在更新暂停时手动更新数据。


# https://cn.angie.software/news/articles/multifaceted-monitoring.md

# 多方位监控 Angie —— nginx Web 服务器的分支

*27.09.2023*

Angie 监控能力的详细概述：用于统计的内置 API、
用于实时可视化的 Console Light，以及无需第三方模块的 Prometheus 集成。

![精美的在线演示胜过任何图片：https://console.angie.software/](news/articles/images/763626/5d5c69da3a437a7327cb448b1836af04.jpg)

你好，亲爱的读者。我叫 Dmitry。我是 Web Server 公司的系统工程师。在我提供技术支持服务的整个经历中，先是在 Nginx 公司，现在是在开发俄罗斯 Web 服务器 Angie 的公司，我们回答一个非常热门的问题："我如何组织对 Web 服务器状态的监控？"方法如下。

1. 监控。"为什么要费心？日志里一切正常！"
2. Angie Web 服务器。"为什么？有 **\*** 不就行了。"如何安装。"有 **\*\*** 的构建版本吗？"
3. API。"我告诉你，有日志！等一下，让我在生产环境中启用它们。"它提供什么。"与日志有什么区别？"如何配置。"它不是自动工作的吗？"获取 Web 服务器配置。"但是有 angie -T。"
4. Console Light – Web 界面。"又一个监控系统？！1？1！！！"它显示什么。"实时是什么意思？"如何安装。"真的只需几行配置？"
5. Prometheus 的 API。"但我已经在使用它了！嗯，是的，我们解析日志..."如何配置 Angie 进行集成。"这怎么不用 njs？"与 Console Light 的比较。"这些值真的匹配吗？"
6. 结论。"所以这就是多方位的意思！"

<a id="monitoring-da-zachem-v-logakh-vsio-normalno-2"></a>

## 1. 监控。"为什么要费心？日志里一切正常！"

所以，我们已经超越了根据用户电话对信息系统运行中的事件做出反应的情况。现在我们的基础设施中有完善的监控系统，包括数据收集、告警系统和"修复一切"按钮。

当回答管理人员、架构师或信息安全专家关于我们如何确保处理基础设施网络请求过程中关键组件之一的可观测性的问题时，我们最常列出以下内容。我们有 Web 服务器进程的系统指标（它消耗多少 CPU 或 RAM，运行了多长时间），我们有来自日志的数据，不太常见的是我们有使用第三方扩展从 Web 服务器导出指标的能力。

获取进程的系统指标是常见做法，是任何基础设施的最低要求。但有时这是极其不够的。我们看到最小的 CPU 消耗，但网站显示 502 Bad Gateway 错误，一切都很糟糕。

从日志获取数据很简单。但架构师指出，本质上，我们是在回顾性地跟踪那个时间点已经被处理的请求。在 DoS 攻击的情况下，我们只会在日志中看到一些请求已经被处理为"处理失败"。但我们需要在 Web 服务器监控中看到已经到达但尚未被上游服务器处理的请求。监控应该显示出拳前的蓄力，而不是显示脸上的瘀伤。

使用第三方解决方案从您的 Web 服务器设置指标导出是一个相当可行的选择。唯一的问题是您需要花时间弄清楚配置，为您的操作系统构建它，并接受明天您的 Web 服务器版本可能与尚未更新的模块不兼容的风险。请记住，信息安全专家从不睡觉。

我们产品的内置功能（我们将在后面讨论）允许实时完整监控 Web/代理服务器负载，并且还具有与客户端基础设施中的监控系统进行高级集成的许多能力。

<a id="veb-server-angie-zachem-esli-est-2"></a>

## 2. Angie Web 服务器。"为什么？有 **\*** 不就行了"

对于那些不知道的人，我要说，对于其他人我要提醒，有一个名为 Angie 的产品，它是从 nginx 分支出来的，由 Web Server 公司开发。该公司汇集了 NGINX 公司的前首席工程师。它在 BSD 许可证下分发，它是合法的，这是我们被告知的。

Angie Web 服务器代码库是从 Nginx 1.23.1 分支出来的。从那时起，我们一直在添加开源 nginx 版本中不存在的新功能。同时，我们尝试将 nginx 更新移植到我们的 Web 服务器，确保用户可以从 nginx 无缝迁移到 Angie。

从 [2022 年 10 月](https://angie.software/news/rossiya-poluchit-nezavisimii-veb-server/) 的第一个版本开始，Angie 就包含一个 API 模块，该模块实现了一个 HTTP RESTful 接口，用于以 JSON 格式获取有关 Web 服务器的基本信息，以及以下统计信息：

* 客户端连接
* 共享内存区域
* DNS 查询
* HTTP 请求
* HTTP 响应缓存
* stream 模块会话
* limit_conn http、limit_conn stream 和 limit_req 模块的区域

完整的指标列表可以在 [文档](https://angie.software/angie/docs/configuration/modules/http/http_api/?ra=yes) 中找到。

最近，发布了新版本 Angie 1.3.0，它实现了对以 Prometheus 格式输出指标的支持。我们准备了一个 Web 界面，用于从选定的实例实时查看指标。现在是时候对 Web 服务器监控能力进行小型比较测试了。

Angie 的独特功能包括：

* [支持收集统计信息、配置等的 API](https://angie.software/angie/docs/configuration/modules/http/http_api/?ra=yes)。
* [支持 DNS SRV 记录转换的动态 DNS](https://angie.software/angie/docs/configuration/modules/http/http_upstream/?ra=yes#reresolve)。
* [使用粘性会话或路由方法的客户端会话绑定](https://angie.software/angie/docs/configuration/modules/http/http_upstream/?ra=yes#u-sticky)。
* [轻量级监控界面 Console Light](https://angie.software/angie/docs/configuration/monitoring/?ra=yes)。
* [以 Prometheus 格式原生输出指标](https://angie.software/angie/docs/configuration/modules/http/http_prometheus/?ra=yes#http-prometheus)。

<a id="kak-ustanovit-a-est-sborka-pod-2"></a>

### 2.1. 如何安装。"有 **\*\*** 的构建版本吗？"

关于如何安装 Angie 的详细说明在 [官方网站](https://angie.software/angie/docs/installation/?ra=yes) 上以俄语和英语提供。

尽管我们在 x86-64 和 arm64 架构上支持 11 个不同版本的发行版，但在本文中，我只提供说明 Web 服务器监控能力所需的步骤。我将在 Debian 操作系统上执行所有安装。

安装 Angie 与从存储库安装任何其他软件包没有什么不同。首先，添加密钥和存储库：

```bash
sudo apt-get update && \
sudo apt-get install --no-install-recommends --no-install-suggests --yes \
                    ca-certificates curl lsb-release && \
sudo curl -o /etc/apt/trusted.gpg.d/angie-signing.gpg \
                    https://angie.software/keys/angie-signing.gpg && \
echo "deb https://download.angie.software/angie/debian/ `lsb_release -cs` main" \
                    | sudo tee /etc/apt/sources.list.d/angie.list >/dev/null
```

然后安装 Angie：

```bash
sudo apt-get update && \
sudo apt-get install --no-install-recommends --no-install-suggests --yes \
                    angie
```

完成。Web 服务器正在运行，欢迎页面可在端口 80 上访问。

curl -I localhost HTTP/1.1 200 OK Server: Angie/1.3.0 ....

<a id="api-govoriu-zhe-logi-est-seichas-tolko-vkliuchu-ikh-na-prode-2"></a>

## 3. API。"我告诉你，有日志！等一下，让我在生产环境中启用它们"

当客户联系技术支持时，他们经常被要求提供日志以进行诊断。经常遇到的情况之一是生产环境中的 Web 服务器日志被禁用。只是为了节省资源。解析日志并将其发送到监控系统的问题根本不会出现。没有日志 – 没有问题。

<a id="chto-pozvoliaet-poluchit-v-chem-raznitsa-s-logami-2"></a>

### 3.1. 它提供了什么。"与日志有什么区别？"

但是，如果我们仍然进行日志分析并基于这些数据构建监控系统呢？与通过 API 使用指标有什么区别？这里有几个细微差别。

首先，日志是在请求处理完成后写入的。换句话说，当最后一个字节已发送到客户端时。在这种情况下，我们应该如何处理长连接或慢速客户端？API 在这里派上用场。"server_zones" 中 "requests" 里的 "processing" 指标可以帮助您了解服务器当前正在处理多少个请求。

其次，日志无法告诉您关于服务器使用的 [共享内存区域](https://angie.software/angie/docs/configuration/modules/http/http_api/?ra=yes#slab) 或 [缓存区域](https://angie.software/angie/docs/configuration/modules/http/http_api/?ra=yes#http-caches) 的任何信息。然而，由于巨大的流量或在各种服务器攻击情况下，它们的溢出可能导致灾难性的结果、段错误，从而导致连接断开甚至服务不可用。

在这里，API 再次拯救了我们。您可以查看和计算区域占用情况，并及时响应意外情况。

第三，通过 API 从运行时获取指标，您只需在当前时刻获得更准确的值。而且它们的数量比您从日志中提取的要多得多。您可以在 [官方网站](https://angie.software/angie/docs/configuration/modules/http/http_api/?ra=yes#id4) 上查看完整的指标树。

回到第三方解决方案的问题，读者可能会问："我为什么要改变什么？我一直在使用基于 vts 模块的综合解决方案。"这里值得注意的是，像 vts 模块这样的解决方案实际上并不提供实时统计信息，因为它们在日志阶段工作，计数器仅在请求处理完成后才计算。换句话说，这种类型的解决方案具有与基于日志的监控相同的缺点。

<a id="kak-nastroit-samo-ne-rabotaet-2"></a>

### 3.2. 如何配置。"它不是自动工作的吗？"

要启用 API，只需在配置中添加 "api" 指令即可。

让我们在配置文件 "/etc/angie/http.d/default.conf" 中注释掉 "location /status/" 中的 "allow" 和 "deny" 指令，这样我们就可以立即在浏览器中看到 API 页面。（在生产环境中，出于安全目的，您仍应正确配置这些指令。这也适用于本文的以下部分）：

```nginx
location /status/ {
  api /status/;
  # allow 127.0.0.1;
  # deny all;
}
```

为了清晰起见，让我们在配置中添加几个区域和上游：

```nginx
upstream foo {
  zone http-upstream-foo 256k;
  server 127.0.0.2 max_conns=10 max_fails=10;
  server 127.0.0.3 max_conns=10 max_fails=10;
  server 127.0.0.4 max_conns=10 max_fails=10;
}

server {
#...
    status_zone example;
#...
    location / {
#...
      status_zone location_zone;
    }
#...
}
```

重启 Angie 以应用配置：

```bash
sudo angie -t && sudo service angie reload
```

然后在您服务器的 /status/ 页面上，您将看到带有 API 指标的 JSON。

<a id="poluchenie-konfiguratsii-veb-servera-tak-est-zhe-angie-t-2"></a>

### 3.3. 获取 Web 服务器配置。"但是有 angie -T"

说到使用 Web 服务器配置。作为额外的奖励，API 现在具有显示服务器配置的能力。[具体来说是 Angie 当前正在运行的配置](https://angie.software/angie/docs/configuration/modules/http/http_api/?ra=yes#api-config-files)。这在许多情况下都很有用，例如，如果由于某种不可思议的原因您从服务器中删除了所有配置并想要恢复它们。在这里，"angie -T" 命令的输出无法帮助您，因为 "angie -T" 命令执行语法检查并从磁盘输出配置。"angie" 二进制文件将尝试解析启动时默认指定的配置文件。

现在，要了解更新的配置是否已应用，您可以比较 API 和 "sudo angie -T" 的输出。

或者您可以做得更简单，跟踪配置生成。Angie 跟踪其每个进程的配置生成；编号从服务器启动时的一开始，并且随着每次配置重新加载而增长，并在进程名称中指示。

成功重新加载配置后（无论是否有更改），接收新配置的进程的生成编号将增加，如果 [先前生成的任何工作进程继续工作](https://angie.software/angie/docs/configuration/runtime/?ra=yes#control-config-change)，这将从 "ps aux | grep angie" 命令的输出中立即显而易见。

/status/angie/ 部分中的 API 输出也将显示配置生成。但与 ps 输出不同，API 输出将仅显示新的配置生成。

![https://angie.software/api/#id5](news/articles/images/763626/3ee00ffc1491c3270761e20b9d056c7a.jpg)

<a id="console-light-veb-interfeis-eshchio-odna-sistema-monitoringa11-2"></a>

## 4. Console Light – Web 界面。"又一个监控系统？！1？1！！！"

从 Angie 版本 1.3.0 开始，添加了 Console Light 功能——一个用于实时活动监控的轻量级可视化控制台，显示关键的服务器负载和性能指标。总的来说，它使管理员更容易跟踪服务器的可用性和状态。

![https://console.angie.software/](news/articles/images/763626/57cd47bf8bfb31f927b80401fec43f5e.jpg)

<a id="chto-pozvoliaet-uvidet-chto-znachit-v-realnom-vremeni-2"></a>

### 4.1. 它允许您看到什么。"实时是什么意思？"

这个简单网页的特点是实时显示特定 Web 服务器实例的指标。页面以一定的周期更新（这可以配置）。请注意，如果您有一个由多个 Web 服务器组成的集群，那么集群中的每个实例都有自己单独配置的可视化控制台。

实际上，前面提到的所有指标都在这里分组到推荐的跟踪选项卡中。例如，您可以在 HTTP Zones 选项卡上的 "requests" 中找到 "processing" 指标。在这里它将被称为 Current。您可以在 Shared Zones 和 Caches 选项卡上查看区域占用情况。

您可以在 [https://console.angie.software/](https://console.angie.software/) 查看我们的 Console Light 演示版本，并且可以在 [文档](https://angie.software/angie/docs/configuration/monitoring/?ra=yes#id3) 部分找到选项卡和在那里收集的指标的详细描述。

<a id="kak-ustanovit-tochno-paru-strochek-konfiga-2"></a>

### 4.2. 如何安装。"真的只需要几行配置？"

此功能作为单独的软件包提供；不要让这个事实困扰您，我的读者。Console Light 与 Angie 和 API 完全集成。让我们安装 Console Light 软件包以查看当前的服务器统计信息。

为此，只需执行：

```bash
sudo apt-get install angie-console-light
```

然后通过在 Angie 配置文件（"/etc/angie/http.d/default.conf"）的 "server" 上下文中放置 "location /console" 来连接 Console Light。像这样：

```nginx
location /console {

  alias /usr/share/angie-console-light/html;
  index index.html;

    location /console/api/ {
      api /status/;
  }
}
```

更详细的信息可以在 [官方网站](https://angie.software/angie/docs/configuration/monitoring/?ra=yes#id2) 上找到。

让我们重启 Angie：

```bash
sudo angie -t && sudo service angie reload
```

然后，转到 /console，我们将看到一个带有指标的页面。在这里，您将立即看到 Requests 和 Responses 指标是如何填充的。由于我们在 "status_zone" 所在的同一个 "server" 中配置控制台，我们看到控制台本身通过访问 API 为我们生成统计信息。我再次注意，在生产环境中您不应该进行这样的配置。最好使用仅用于监控的单独 "server" 块。

<a id="api-dlia-prometheus-da-u-menia-uzhe-ispolzuetsia-nu-da-logi-parsim-2"></a>

## 5. Prometheus 的 API。"但我已经在使用它了！嗯，是的，我们解析日志..."

用于构建监控系统的一个相当流行的解决方案是使用 Prometheus 来收集指标。我们假设您已经安装了此服务。很可能，您通过日志分析或 [使用第三方导出器](https://github.com/martin-helmich/prometheus-nginxlog-exporter/) 来填充它。

在我们的情况下，我们制作了一个内置的解决方案，用于以 Prometheus 格式导出指标。我要注意的是，我们有灵活可配置的模板，因此您可以为指标收集添加自己的特色。可用指标的完整列表收集在 [all 模板](https://angie.software/angie/docs/configuration/modules/http/http_prometheus/?ra=yes#prometheus-all) 中。

<a id="kak-nastroit-angie-dlia-integratsii-kak-eto-bez-njs-2"></a>

### 5.1. 如何配置 Angie 以进行集成。"没有 njs 如何实现？"

新软件包已经包含了一个包含所有可用指标的模板，因此只需在方便的位置添加"prometheus"指令来启用这些指标的传递即可。

```nginx
location /metrics/ {
  prometheus all;
}
```

重启 Angie：

```bash
sudo angie -t && sudo service angie reload
```

通过请求 /metrics/ 地址，我们将看到熟悉的 Prometheus 格式。您可以在网上找到使用 njs 从 nginx 导出指标的示例。在我们的案例中，不使用 js 运行时；计算和传递在 Web 服务器运行时中进行，开销最小。

<a id="sravnenie-s-console-light-znacheniia-deistvitelno-sovpadaiut-2"></a>

### 5.2. 与 Console Light 的比较。"数值真的匹配吗？"

作为一名工程师，我很想看看通过 Prometheus+Grafana 查看指标与通过 Console Light 查看指标之间是否存在差异。我搭建了一个简单的测试环境，配置了 Web 服务器、与 Prometheus 和 Console Light 的集成。我使用 wrk 和脚本在 Web 服务器上创建了人工负载。在下面的截图中，您可以比较相应的指标。结果相当有趣。

总体而言，这些指标在各方面都很相似；当您增加指标收集间隔时，差异就开始出现了。如果 Console Light 每秒获取一次指标，那么在 Grafana 中，2 分钟的间隔会显示有延迟且存在一些差异的指标。因此，截图中存在差异。

![image](news/articles/images/763626/7a4e4d00041837c91b26e9234458a72f.jpg)

在磁盘使用量开始令人担忧地增长时，Grafana 仍然显示一切正常。

![image](news/articles/images/763626/f43b6bc70d9f9868db502245dd791bdd.jpg)

当然，最终指标会对齐。

![image](news/articles/images/763626/396626a6955163cdd3ff2bdb8f559ae8.jpg)![image](news/articles/images/763626/c5a6dbf03d8fb1ed702d8d508e45c857.jpg)

运行时请求指标的情况也类似。

![image](news/articles/images/763626/982ebe9c1275754142f668366242b3bb.jpg)![image](news/articles/images/763626/5d094963d3b500b00518b051cbe69b74.jpg)

很多取决于 Grafana 和 Prometheus 本身的设置；您需要选择适合您的间隔。但请做好准备，间隔越短，服务需要在磁盘上存储的数据就越多。

<a id="itog-tak-vot-chto-znachit-mnogogrannyi-2"></a>

## 6. 结论。"原来多面性是这个意思！"

不能说组织 Web 服务器监控系统有唯一正确的方法。但我们试图在 Angie Web 服务器中提供灵活性，以便配置适合您的解决方案。

作为一名工程师，我经常遇到用户在一切都已经发生且尚未配置设置时寻求帮助的情况。因此，请允许我花点时间提醒您：最好提前进行所有必要的设置，以便为不可预见的情况做好准备。幸运的是，有详细的说明可供参考。

那么，关于多面监控方法。多面性体现在您可以继续分析日志，可以使用提供扩展指标 API 的 Angie Web 服务器。您可以在简单的网页 Console Light 上查看 Web 服务器状态。最后，您可以将 Web 服务器状态信息完整集成到基于 Prometheus 的指标收集系统中。

请使用它！很高兴能帮助您！


# https://cn.angie.software/news/nasha-komanda-prodolzhaet-delat-vklad-v-mirovoj-open-source.md

# 我们的团队持续为全球开源事业做贡献！

*27.12.2023*

我们不仅在开发 Angie — nginx 的一个分支，还偶尔会为 nginx 本身做出贡献。

![Alternative text](../../_images/news/nasha-komanda-prodolzhaet-delat-vklad-v-mirovoj-open-source.jpeg)![Alternative text](../../_images/news/nasha-komanda-prodolzhaet-delat-vklad-v-mirovoj-open-source.jpeg)

我们不仅在开发 Angie — nginx 的一个分支，还偶尔会为 nginx 本身做出贡献。最近，我们的开发人员 [准备](https://mailman.nginx.org/pipermail/nginx-devel/2023-December/THMZAQ36SN5BICJSCLX6FLEUI45FHR4H.html) 了一份新年和圣诞节礼物：他们将 Angie 中的 HTTP/3 代理实现移植回 nginx，并提议将其纳入主分支。

我们提取了 Angie PRO HTTP/3 中的 [所有变更](https://wbsrv.ru/tpost/hh0by73n41-vishli-obnovleniya-rossiiskogo-veb-serve)，并创建了一组可应用于当前 nginx 版本的补丁。我们将这些补丁发送到了 nginx 开发者邮件列表。现在，nginx 用户可以应用我们的补丁来体验这个新功能。


# https://cn.angie.software/angie/docs/installation/external-modules/ndk.md

<!-- review: finished -->

<a id="external-ndk"></a>

# NDK

NDK 是一个旨在扩展核心功能的模块,可以作为其他 Angie 模块的基础。

NDK 本身添加了几个从用户角度不可见的函数——它只是为了帮助减少模块开发者需要编写的代码量。

在 Angie 仓库中提供软件包的模块集合中,以下模块使用了 NDK:

- `lua`
- `set-misc`

使用这些模块时,除了加载必要的模块外,还应加载 NDK 模块。NDK 必须在主模块之前加载。

<a id="installation-18"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie: `angie-module-ndk`
- Angie PRO: `angie-pro-module-ndk`

<a id="loading-the-module-18"></a>

## 加载模块

```nginx
load_module modules/ndk_http_module.so;
```

<a id="additional-information-19"></a>

## 其他信息

详细文档和源代码可在以下链接获取:
[https://github.com/vision5/ngx_devel_kit/](https://github.com/vision5/ngx_devel_kit/)


# https://cn.angie.software/news.md

# 所有新闻

## [Angie 和 Angie PRO 更新至 1.11.0 版本](https://cn.angie.software//news/releases/angie-1-11-0.md)

*24.12.2025*

Angie 和 Angie PRO 1.11.0 已发布 — 这是该项目历史上规模最大的更新。
此版本引入了 Metrics 模块，修复了 `HTTP/3` 可靠性问题，扩展了
ACME 和图像过滤器功能；Angie PRO 改进了具有外部存储的粘性会话，并在
API 中添加了许可证详情。

## [Angie 和 Angie PRO 更新至 1.10.3 版本](https://cn.angie.software//news/releases/angie-1-10-3.md)

*13.11.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 发布了修复版本 1.10.3。
从 nginx 1.29 移植了邮件 SMTP 模块的一个潜在漏洞修复。修复了 ACME 配置
错误，并解决了在 client 块中使用变量访问传入连接时的潜在崩溃问题。
PRO 版本还修复了 UDP 健康检查和 Docker 模块服务器的相关问题。

## [Angie 和 Angie PRO 更新至 1.10.2 版本](https://cn.angie.software//news/releases/angie-1-10-2.md)

*22.08.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 发布了修复版本 1.10.2。
这些版本修复了在 1.10 版本中引入 client 块实现时出现的问题，该问题
可能会干扰 stream 模块中 ACME、Docker 和 sticky remote 模块的功能。
同时修复了通过 Docker API 更新代理服务器组的问题，并添加了两个新的
第三方模块。

## [Angie 和 Angie PRO 更新至 1.10.1 版本](https://cn.angie.software//news/releases/angie-1-10-1.md)

*17.07.2025*

发布了 Angie 和 Angie PRO 的 1.10.1 修复版本。此次更新修复了
reuseport 和 HTTP/3 的相关问题，改进了 client 配置块的逻辑，
增加了对新版本 GCC 的兼容性，并解决了 Angie PRO 中使用特殊变量时的崩溃问题。

## [Angie 和 Angie PRO 更新至 1.10.0 版本](https://cn.angie.software//news/releases/angie-1-10-0.md)

*04.07.2025*

开源 Web 服务器 Angie 及其商业版 Angie PRO 已发布 1.10.0 版本。
主要更新包括自动代理 Docker 容器、改进流模块中的 ACME 支持、
支持多路径 TCP 和带 CUBIC 的 QUIC，以及集群模式下 Angie PRO 的新功能。

## [Angie 和 Angie PRO 更新至版本 1.9.1](https://cn.angie.software//news/releases/angie-1-9-1.md)

*29.05.2025*

开源 Web 服务器 Angie 及其商业版 Angie PRO 发布了 1.9.1 版本。
本次更新重点提升了对 HTTP/3 的支持，并改进了对非标准 ACME 配置的处理，
同时修复了流模块中的一些问题。

## [Angie 和 Angie PRO 更新至 1.9.0 版本](https://cn.angie.software//news/releases/angie-1-9-0.md)

*11.04.2025*

开源网页服务器 Angie 及其商业版本 Angie PRO 已发布 1.9.0 版本。
主要更新包括将缓存索引保存到磁盘以加快重启速度、
在流模块中支持 TLS 1.3 Early Data，以及 Angie PRO 中 HTTP 负载均衡器的新功能。

## [Angie 和 Angie PRO 发布了 1.8.3 版本；Console Light 更新至 1.7.0 版本](https://cn.angie.software//news/releases/angie-1-8-3.md)

*02.04.2025*

开源版 Angie 网络服务器及其商业版 Angie PRO 发布了 1.8.3 版本，修复了统计功能；
Console Light 更新至 1.7.0 版本。

## [Angie 和 Angie PRO 发布 1.8.2 更新](https://cn.angie.software//news/releases/angie-1-8-2.md)

*13.02.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 的 1.8.2 版本包含重要的安全修复，以及其他多项改进。

## [Angie 和 Angie PRO 升级至 1.8.1 版本](https://cn.angie.software//news/releases/angie-1-8-1.md)

*28.12.2024*

开源网络服务器 Angie 和其商业版本 Angie PRO 发布了 1.8.1 版本。
此更新修复了服务器统计区域的问题，改进了 ACME 模块对通配符证书的支持，并包含 HTTP/3 的重要修复。

## [Angie 和 Angie PRO 更新至版本 1.8.0](https://cn.angie.software//news/releases/angie-1-8-0.md)

*19.12.2024*

Angie 网络服务器及其商业版本 Angie PRO 的 1.8.0 版本已发布。此更新包括 ACME 模块的新功能、对 WebAssembly 的支持，以及 API 和功能的改进。

## [Angie 启用 WebAssembly 支持](https://cn.angie.software//news/articles/wasm.md)

*29.11.2024*

此次更新使得可以构建 WASM 模块，以便 Angie 加载并在服务器配置中使用它们。

## [Angie 和 Angie PRO 收到更新 1.7.0](https://cn.angie.software//news/releases/angie-i-angie-pro-poluchili-obnovlenie-1-7-0.md)

*20.09.2024*

新版本的开源网页服务器 Angie 1.7.0 和商业版 Angie PRO 1.7.0 现已推出，提供显著的改进和新功能。

## [Rubytech集团与俄罗斯Web服务器开发商Angie整合资源与专业技术，共同推进产品开发](https://cn.angie.software//news/gruppa-rubytech-i-angie-objedinaiut-resursi.md)

*22.08.2024*

俄罗斯高负载系统软件开发商Angie（Web Server有限责任公司）已加入Rubytech集团。

![Alternative text](../../_images/news/gruppa-rubytech-i-angie-objedinaiut-resursi.webp)

## [Angie 和 Angie PRO 发布 1.6.1 更新](https://cn.angie.software//news/releases/angie-i-angie-pro-poluchili-obnovlenie-1.6.1.md)

*08.08.2024*

Web Server公司发布了开源网络服务器 Angie 1.6.1 和其商业版本 Angie PRO 1.6.1。

## [SolidWall Web应用程序防护解决方案兼容Angie PRO](https://cn.angie.software//news/integrations/reshenie-po-zaschite-web-prilojenii-solidwall-sovmestimo-s-angie-pro.md)

*15.07.2024*

与Angie PRO的集成增强了SolidWall WAF的功能，例如，实现了对HTTP/3协议的支持。

## [Angie和Angie PRO Web服务器发布更新](https://cn.angie.software//news/releases/vishli-obnovlenia-web-servera-angie-i-angie-pro.md)

*28.06.2024*

新版本显著扩展了负载均衡功能，并继续开发ACME模块。

## [Web服务器Angie新增ACME支持](https://cn.angie.software//news/releases/veb-server-angie-poluchil-podderzhku-acme.md)

*27.03.2024*

新增了http_acme模块，实现了对ACME(自动化证书管理环境)协议的支持，简化了网站数字证书的工作流程，
无需使用像EFF Certbot这样的第三方解决方案。

## [国产云环境Kubernetes解决方案Angie Ingress Controller (ANIC)发布更新](https://cn.angie.software//news/releases/vishli-obnovleniya-otechestvennogo-reshenia-ANIC.md)

*02.03.2024*

Web Server公司发布了用于Kubernetes容器化应用流量管理的俄罗斯解决方案Angie Ingress Controller (ANIC) 0.3.0版本。

## [Angie Web服务器及其专有版本Angie PRO发布更新](https://cn.angie.software//news/releases/vishli-obnovleniya-veb-servera-angie-i-ego-proprietarnoi-versii-angie-pro.md)

*15.02.2024*

Web Server公司发布了俄罗斯开源Web服务器Angie 1.4.1及其商业版本Angie PRO 1.4.1。

## [X-Config负责监控Angie PRO配置的安全性](https://cn.angie.software//news/integrations/bezopastnost-configuracii-angie-pro-kontroliruet-x-config.md)

*08.02.2024*

Angie PRO的安全配置标准将使客户能够自动监控Web服务器设置，接收按优先级排序的漏洞识别报告，并提供修复建议。

## [Angie Ingress Controller (ANIC) 已加入国产软件名录](https://cn.angie.software//news/integrations/ingress-controller-anic-voshel-v-reestr-otechestvennogo-po.md)

*12.01.2024*

大家好！我们用于 Kubernetes 云环境的解决方案 Angie Ingress Controller (ANIC) 已被添加到 [国产软件名录](https://reestr.digital.gov.ru/reestr/2057228/)。

## [俄罗斯网络服务器Angie PRO更新发布](https://cn.angie.software//news/releases/vishli-obnovleniya-rossiiskogo-veb-servera-Angie-Pro.md)

*21.12.2023*

Web Server公司宣布发布新版本的俄罗斯网络服务器Angie PRO 1.4.0。

## [俄罗斯开源Web服务器Angie发布更新](https://cn.angie.software//news/releases/vishli-obnovleniya-rossiiskogo-veb-servera-s-otkrytym-iskhodnym-kodom-Angie.md)

*12.12.2023*

"Web Server"公司发布了俄罗斯开源Web服务器Angie 1.4.0新版本。

## [Angie PRO 获得 ROSA Chrome 12 Server 操作系统认证](https://cn.angie.software//news/integrations/angie-pro-sertifitsirovan-dlya-os-rosa-chrome-12-server.md)

*01.12.2023*

俄罗斯网络服务器开发商Web Server与 ROSA IT 研究中心已确认 Angie PRO 网络服务器与 ROSA Chrome 12 Server 操作系统的兼容性，这一点已通过双方签发的证书得到证实，凸显了产品的高度兼容性和可靠性。

## [Angie和Angie PRO发布1.3.2更新](https://cn.angie.software//news/releases/angie-i-angie-pro-poluchili-obnovlenie-1.3.2.md)

*24.11.2023*

Web Server公司发布了Web服务器Angie及其商业版本Angie PRO的更新。

## [Angie新增功能助力更好的Web服务器监控](https://cn.angie.software//news/articles/novoe-v-angie-dlya-luchshego-monitoringa.md)

*17.11.2023*

2023年9月，我们通过添加Angie Console Light为Angie web服务器引入了新的监控组织方式。

## [Angie和Angie PRO针对DoS攻击的防护得到增强](https://cn.angie.software//news/releases/angie-i-angie-pro-obnovleni-dlya-uluchsheniya-zashchity-ot-dos-ataki.md)

*18.10.2023*

Web Server公司宣布发布Angie和Angie PRO的1.3.1版本。

## [多方位监控 Angie —— nginx Web 服务器的分支](https://cn.angie.software//news/articles/multifaceted-monitoring.md)

*27.09.2023*

Angie 监控能力的详细概述：用于统计的内置 API、
用于实时可视化的 Console Light，以及无需第三方模块的 Prometheus 集成。

## [Web服务器Angie PRO发布1.3.0更新](https://cn.angie.software//news/releases/veb-server-angie-pro-poluchil-obnovlenie-1.3.0.md)

*03.10.2023*

"Web Server"公司宣布发布俄罗斯Web服务器Angie PRO 1.3.0新版本。

## [开源代码的Web服务器Angie更新至版本1.3.0](https://cn.angie.software//news/releases/veb-server-angie-s-otkritim-ishodnim-kodom-1.3.0.md)

*19.09.2023*

公司“Web服务器”宣布发布俄罗斯开源Web服务器Angie 1.3.0的新版本。

## [WebmonitorEx平台与俄罗斯网络服务器Angie PRO实现兼容](https://cn.angie.software//news/integrations/platforma-vebmonitoreks-sovmestima-s-rossijskim-veb-serverom-Angie-Pro.md)

*06.09.2023*

WebmonitorEx已确保其平台与俄罗斯网络服务器Angie PRO的兼容性。这为企业提供了更高的可靠性和安全性，以防御网络威胁。

## [Web服务器Angie PRO发布1.2.0更新](https://cn.angie.software//news/releases/veb-server-angie-pro-poluchil-obnovlenie-1.2.0.md)

*19.08.2023*

"Web Server"公司宣布发布其俄罗斯Web服务器Angie PRO 1.2.0新版本。

## [Web Server公司推出Angie入口控制器](https://cn.angie.software//news/releases/kompaniya-veb-server-predstavila-angie-ingress-controller.md)

*29.06.2023*

Web Server公司推出了新产品Angie入口控制器（ANIC），可实现Kubernetes网络中的高效流量管理。

## [我们在发展并诚邀专业人才加入我们的团队](https://cn.angie.software//news/mi-rastem-i-priglashaem-na-rabotu-spetsialistov.md)

*16.06.2023*

我们在发展并诚邀专业人才加入我们的团队 - 招聘Angie网络服务器的C语言开发工程师和QA专家（Perl）

## [公司Web Server更新开源Web服务器Angie](https://cn.angie.software//news/releases/kompaniya-veb-server-obnovila-veb-server.md)

*08.06.2023*

俄罗斯开源Web服务器Angie 1.2.0新版本发布。

## [Angie Web服务器成为"俄罗斯版GitHub"的参与者](https://cn.angie.software//news/integrations/veb-server-angie-stal-uchastnikom-rossijskogo-GitHub.md)

*06.06.2023*

由前nginx团队开发的俄罗斯Web服务器Angie已成为创建俄罗斯代码仓库实验的参与者。俄罗斯数字发展部于2023年5月31日发布了相关命令。

## [Web服务器Angie PRO被列入国产软件名录](https://cn.angie.software//news/integrations/veb-server-angie-pro-voshel-v-reestr-otechestvennogo-PO.md)

*24.05.2023*

由前nginx团队开发的Web服务器Angie PRO已被列入国产软件名录。

## ["网络服务器"团队推出企业级产品 — Angie PRO](https://cn.angie.software//news/integrations/komanda-veb-servera-predstavlyaet-produkt-dlya-korporativnyh-zakazchikov-Angie-Pro.md)

*27.03.2023*

Angie已通过RED OS和Astra Linux特别版的兼容性认证。

## [俄罗斯将推出自主研发的Web服务器Angie](https://cn.angie.software//news/rossiya-poluchit-nezavisimii-veb-server.md)

*27.10.2022*

俄罗斯已开发出名为Angie的Web服务器，这将使俄罗斯企业能够替代国外解决方案并确保其基础设施的安全。

## [Angie正在招聘](https://cn.angie.software//news/angie-priglashaet-na-rabotu.md)

*28.05.2024*

大家好！我们想让全世界知道，我们也需要专业人士。

![替代文本](../../_images/news/angie-priglashaet-na-rabotu.jpeg)

## [备受尊敬的Ivan Panchenko的精彩访谈](https://cn.angie.software//news/interviews/prekrasnoe-intervyu-gluboko-uvazhaemogo-ivana-panchenko.md)

*07.02.2024*

从第25分钟开始，Ivan [谈论](https://www.youtube.com/watch?app=desktop&v=d9joPLRULeA) 我们的事情，
虽然他没有直接提到我们的名字。不过，这个一小时长的访谈中其他内容对所有从事开源项目的人来说都同样重要。

![Alternative text](../../_images/news/prekrasnoe-intervyu-gluboko-uvazhaemogo-ivana-panchenko.jpeg)

## [Angie Console - 我们正在开发新产品！](https://cn.angie.software//news/angie-console-mi-razrabativaem-novii-produkt.md)

*09.02.2024*

这是一个用于管理Web服务器集群的集中式系统，具有监控和动态配置功能。

![Alternative text](../../_images/news/angie-console-mi-razrabativaem-novii-produkt.jpg)

## [扩充第三方模块库：新增ModSecurity](https://cn.angie.software//news/integrations/popolnyaem-kollektsiyu-storonnih-modulei.md)

*04.12.2023*

大家好！在我们为即将发布的Angie和Angie PRO网络服务器更新版本进行工作的同时，我们也在持续扩充我们的第三方模块库。

![Alternative text](../../_images/news/popolnyaem-kollektsiyu-storonnih-modulei.webp)

## [Angie Web服务器一年后：新机遇与未来规划](https://cn.angie.software//news/events/veb-server-angie-god-spustya-novie-vozmozhnosti.md)

*27.11.2023*

Angie开发负责人Valentin Bartenyev将在HighLoad 2023大会上回顾项目第一年的发展历程。

![替代文本](../../_images/news/veb-server-angie-god-spustya-novie-vozmozhnosti.jpeg)

## [研发部负责人访谈](https://cn.angie.software//news/interviews/intervyu-s-rukovoditelem-otdela-razrabotki.md)

*16.11.2023*

大家好！今天我们在Habr上发布了一篇对研发部负责人Valentin Bartenyev的访谈。

![Alternative text](../../_images/news/intervyu-s-rukovoditelem-otdela-razrabotki.jpg)

## [获得Alt SP Server操作系统兼容性证书](https://cn.angie.software//news/integrations/poluchili-sertifikat-sovmestimosti-s-os-Alt-SP-Server.md)

*10.11.2023*

该证书不仅证实了测试的成功完成，也是我们产品对部分客户实施的必需文件。

![Alternative text](../../_images/news/poluchili-sertifikat-sovmestimosti-s-os-Alt-SP-Server.jpeg)

## [认识 Console Light](https://cn.angie.software//news/articles/vstrechaite-console-light.md)

*27.09.2023*

我们推出了一款用于实时活动监控的轻量级可视化控制台。

![Alternative text](../../_images/news/vstrechaite-console-light.jpg)

## [三周更新计划](https://cn.angie.software//news/tri-nedeli-obnovleniy.md)

*19.09.2023*

在接下来的三周(没错!)中，我们将以更新来庆祝并让用户感到欣喜。

![Alternative text](../../_images/news/tri-nedeli-obnovleniy.jpeg)

## [在俄罗斯推广开源](https://cn.angie.software//news/articles/populyarizuem-opensource-v-rossii.md)

*14.09.2023*

我们与科学出版物N+1的朋友们一起启动了一个在俄罗斯推广开源的特别项目。

![Alternative text](../../_images/news/populyarizuem-opensource-v-rossii.jpeg)

## [Angie与中国的经验](https://cn.angie.software//news/articles/opyt-raboti-angie-s-kitaem.md)

*04.09.2023*

当俄罗斯正在积极制定"本土"开源项目发展计划时，中国也在积极发展其自己的开源项目。

![Alternative text](../../_images/news/opyt-raboti-angie-s-kitaem.jpeg)

## [在贝加尔测试Angie PRO](https://cn.angie.software//news/integrations/testiruem-angie-pro-na-baikale.md)

*31.08.2023*

我们成功地在ARM处理器架构上编译、构建软件包并测试了我们的产品Angie/Angie PRO。

![Alternative text](../../_images/news/testiruem-angie-pro-na-baikale.jpeg)

## [Angie 与 nginx 的异同点](https://cn.angie.software//news/articles/shodstva-i-razlichiya-angie-i-nginx.md)

*25.08.2023*

Angie 项目和 Angie PRO 产品与其前身 nginx 及其商业版本 NGINX Plus 的关系。

![Angie vs. nginx](../../_images/news/shodstva-i-razlichiya-angie-i-nginx.webp)

## [ANIC - Angie Ingress Controller](https://cn.angie.software//news/articles/anic-angie-ingress-controller.md)

*11.08.2023*

今天我们将讨论Angie Ingress Controller（ANIC）- Web Server公司为简化Kubernetes中的流量管理而推出的解决方案。

![Alternative text](../../_images/news/anic-angie-ingress-controller.jpg)

## [Angie 和 N+1 探索俄罗斯开源世界](https://cn.angie.software//news/articles/angie-i-Nplus1-issleduyut-opensors-v-rossii.md)

*04.08.2023*

我们将与 N+1 编辑团队一起，用一年时间探索使用开源原则的软件开发世界。

![Alternative text](../../_images/news/angie-i-Nplus1-issleduyut-opensors-v-rossii.jpg)

## [Angie 一周年！](https://cn.angie.software//news/angie-1-god.md)

*21.07.2023*

今天，7月21日，Angie迎来了它的第一个生日。我们正在各大平台上开设博客，向您介绍我们的发展情况。

![Alternative text](../../_images/news/angie-1-god.jpeg)


# https://cn.angie.software/angie/docs/configuration/njs-reference.md

<!-- review: finished -->

<a id="njs-reference"></a>

# NJS API 参考

[NJS](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs) 模块提供了用于扩展 Angie 功能的对象、方法和属性。

本参考仅包含 NJS 特定的、不符合 ECMAScript 标准的属性、方法和模块。符合 ECMAScript 标准的 NJS 属性和方法的定义可以在 [ECMAScript 规范](http://www.ecma-international.org/ecma-262/) 中找到。

<a id="njs-nginx-objects"></a>

## Angie 对象

<a id="njs-http-request"></a>

### HTTP 请求

- `r.args{}`
- `r.done()`
- `r.error()`
- `r.finish()`
- `r.headersIn{}`
- `r.headersOut{}`
- `r.httpVersion`
- `r.internal`
- `r.internalRedirect()`
- `r.log()`
- `r.method`
- `r.parent`
- `r.remoteAddress`
- `r.requestBody`
- `r.requestBuffer`
- `r.requestText`
- `r.rawHeadersIn[]`
- `r.rawHeadersOut[]`
- `r.responseBody`
- `r.responseBuffer`
- `r.responseText`
- `r.return()`
- `r.send()`
- `r.sendBuffer()`
- `r.sendHeader()`
- `r.setReturnValue()`
- `r.status`
- `r.subrequest()`
- `r.uri`
- `r.rawVariables{}`
- `r.variables{}`
- `r.warn()`

HTTP 请求对象仅在 [HTTP JS](https://cn.angie.software//angie/docs/installation/external-modules/http_js.md#http-js) 模块中可用。在 0.8.5 之前，该对象的所有字符串属性都是字节字符串。

<a id="r-args"></a>

`r.args{}`

> 请求参数对象，只读。

> 查询字符串以对象形式返回。从 0.7.6 开始，重复的键以数组形式返回，键区分大小写，键和值都会进行百分号解码。

> 例如，查询字符串

> ```text
> a=1&b=%32&A=3&b=4&B=two%20words
> ```

> 会被转换为 `r.args`：

> ```javascript
> {a: "1", b: ["2", "4"], A: "3", B: "two words"}
> ```

> 更高级的解析场景可以使用 [Query String](#njs-querystring) 模块和 `$args` 变量来实现，例如：

> ```javascript
> import qs from 'querystring';

> function args(r) {
>     return qs.parse(r.variables.args);
> }
> ```

> 参数对象在首次访问 `r.args` 时进行求值。如果只需要单个参数，例如 `foo`，可以使用 Angie 变量：

> ```javascript
> r.variables.arg_foo
> ```

> 这里，Angie 变量对象返回给定键的第一个值，不区分大小写，不进行百分号解码。

> 要将 `r.args` 转换回字符串，可以使用 Query String 的 `stringify` 方法。

<a id="r-done"></a>

`r.done()`
: 调用此函数后，后续的数据块将直接传递给客户端，而不调用 `js_body_filter` （0.5.2）。只能从 `js_body_filter` 函数中调用。

<a id="r-error"></a>

`r.error(string)`
: 将 `string` 以 `error` 日志级别写入错误日志。
  <br/>
  #### NOTE
  由于 Angie 有硬编码的最大行长度限制，只有字符串的前 2048 字节可以被记录。

<a id="r-finish"></a>

`r.finish()`
: 完成向客户端发送响应。

<a id="r-headers-in"></a>

`r.headersIn{}`
: 传入的请求头对象，只读。
  <br/>
  可以使用以下语法访问 `Foo` 请求头：`headersIn.foo` 或 `headersIn['Foo']`。
  <br/>
  `Authorization`、`Content-Length`、`Content-Range`、`Content-Type`、`ETag`、`Expect`、`From`、`Host`、`If-Match`、`If-Modified-Since`、`If-None-Match`、`If-Range`、`If-Unmodified-Since`、`Max-Forwards`、`Proxy-Authorization`、`Referer`、`Transfer-Encoding` 和 `User-Agent` 请求头只能有一个字段值（0.4.1）。`Cookie` 头中的重复字段值用分号（`;`）分隔。所有其他请求头中的重复字段值用逗号分隔。

<a id="r-headers-out"></a>

`r.headersOut{}`
: 主请求的传出响应头对象，可写。
  <br/>
  如果 `r.headersOut{}` 是子请求的响应对象，它表示响应头。在这种情况下，`Accept-Ranges`、`Connection`、`Content-Disposition`、`Content-Encoding`、`Content-Length`、`Content-Range`、`Date`、`Keep-Alive`、`Server`、`Transfer-Encoding`、`X-Accel-*` 响应头中的字段值可能会被省略。
  <br/>
  可以使用以下语法访问 `Foo` 响应头：`headersOut.foo` 或 `headersOut['Foo']`。
  <br/>
  传出的响应头应该在响应头发送给客户端之前设置；否则，头的更新将被忽略。这意味着 `r.headersOut{}` 在以下情况下有效可写：
  <br/>
  - 在 `js_content` 处理程序中，在调用 `r.sendHeader()` 或 `r.return()` 之前
  - 在 `js_header_filter` 处理程序中
  <br/>
  多值响应头（0.4.0）的字段值可以使用以下语法设置：
  <br/>
  ```javascript
  r.headersOut['Foo'] = ['a', 'b']
  ```
  <br/>
  输出将是：
  <br/>
  ```text
  Foo: a
  Foo: b
  ```
  <br/>
  `Foo` 响应头的所有先前字段值将被删除。
  <br/>
  对于只接受单个字段值的标准响应头（如 `Content-Type`），只有数组的最后一个元素会生效。`Set-Cookie` 响应头的字段值始终以数组形式返回。`Age`、`Content-Encoding`、`Content-Length`、`Content-Type`、`ETag`、`Expires`、`Last-Modified`、`Location`、`Retry-After` 响应头中的重复字段值会被忽略。所有其他响应头中的重复字段值用逗号分隔。

<a id="r-http-version"></a>

`r.httpVersion`
: HTTP 版本，只读。

<a id="r-internal"></a>

`r.internal`
: 布尔值，对于内部 location 为 `true`。

<a id="r-internal-redirect"></a>

`r.internalRedirect(uri)`
: 执行到指定 `uri` 的内部重定向。如果 URI 以 `@` 前缀开头，则被视为命名 location。在新 location 中，所有请求处理从普通 location 的 `NGX_HTTP_SERVER_REWRITE_PHASE` 开始重复，从命名 location 的 `NGX_HTTP_REWRITE_PHASE` 开始重复。因此，重定向到命名 location 不会检查 `client_max_body_size` 限制。重定向的请求变为内部请求，可以访问内部 location。实际的重定向发生在处理程序执行完成后。
  <br/>
  #### NOTE
  重定向后，在目标 location 中启动一个新的 NJS VM，原始 location 中的 VM 停止。Angie 变量的值会保留，可用于向目标 location 传递信息。从 0.5.3 开始，可以使用通过 `js_var` 指令为 HTTP 或 Stream 声明的变量。
  <br/>
  #### NOTE
  从 0.7.4 开始，该方法接受转义的 URI。

<a id="r-log"></a>

`r.log(string)`
: 将 `string` 以 `info` 日志级别写入错误日志。
  <br/>
  #### NOTE
  由于 Angie 有硬编码的最大行长度限制，只有字符串的前 2048 字节可以被记录。

<a id="r-method"></a>

`r.method`
: HTTP 方法，只读。

<a id="r-parent"></a>

`r.parent`
: 引用父请求对象。

<a id="r-remote-address"></a>

`r.remoteAddress`
: 客户端地址，只读。

<a id="r-request-body"></a>

`r.requestBody`
: 该属性在 0.5.0 中已过时，在 0.8.0 中被移除。应该使用 `r.requestBuffer` 或 `r.requestText` 属性代替。

<a id="r-request-buffer"></a>

`r.requestBuffer`
: 客户端请求体（如果尚未写入临时文件）（从 0.5.0 开始）。要确保客户端请求体在内存中，其大小应受 `client_max_body_size` 限制，并且应使用 `client_body_buffer_size` 设置足够的缓冲区大小。该属性仅在 `js_content` 指令中可用。

<a id="r-request-text"></a>

`r.requestText`
: 与 `r.requestBuffer` 相同，但返回一个字符串。注意，它可能会将 UTF-8 编码中无效的字节转换为替换字符。

<a id="r-raw-headers-in"></a>

`r.rawHeadersIn[]`
: 返回键值对数组，完全按照从客户端接收的原样（0.4.1）。
  <br/>
  例如，对于以下请求头：
  <br/>
  ```text
  Host: localhost
  Foo:  bar
  foo:  bar2
  ```
  <br/>
  `r.rawHeadersIn` 的输出将是：
  <br/>
  ```javascript
  [
      ['Host', 'localhost'],
      ['Foo', 'bar'],
      ['foo', 'bar2']
  ]
  ```
  <br/>
  可以使用以下语法收集所有 `foo` 头：
  <br/>
  ```javascript
  r.rawHeadersIn.filter(v=>v[0].toLowerCase() == 'foo').map(v=>v[1])
  ```
  <br/>
  输出将是：
  <br/>
  ```javascript
  ['bar', 'bar2']
  ```
  <br/>
  头字段名称不会转换为小写，重复的字段值不会合并。

<a id="r-raw-headers-out"></a>

`r.rawHeadersOut[]`
: 返回响应头的键值对数组（0.4.1）。头字段名称不会转换为小写，重复的字段值不会合并。

<a id="r-response-body"></a>

`r.responseBody`
: 该属性在 0.5.0 中已弃用，在 0.8.0 中被移除。应该使用 `r.responseBuffer` 或 `r.responseText` 属性代替。

<a id="r-response-buffer"></a>

`r.responseBuffer`
: 包含子请求响应体，只读（从 0.5.0 开始）。`r.responseBuffer` 的大小受 `subrequest_output_buffer_size` 指令限制。

<a id="r-response-text"></a>

`r.responseText`
: 与 `r.responseBuffer` 相同，但返回字符串（从 0.5.0 开始）。注意，它可能会将 UTF-8 编码中无效的字节转换为替换字符。

<a id="r-return"></a>

`r.return(status[, string | Buffer])`
: 向客户端发送带有指定 `status` 的完整响应。响应可以是字符串或 Buffer（0.5.0）。
  <br/>
  可以将重定向 URL（用于代码 301、302、303、307 和 308）或响应正文文本（用于其他代码）指定为第二个参数。

<a id="r-send"></a>

`r.send(string | Buffer)`
: 向客户端发送响应正文的一部分。发送的数据可以是字符串或 Buffer（0.5.0）。

<a id="r-sendbuffer"></a>

`r.sendBuffer(data[, options])`
: 将数据添加到要转发到下一个正文过滤器的数据块链中（0.5.2）。实际转发会在稍后发生，即当前链的所有数据块都处理完毕时。
  <br/>
  数据可以是字符串或 Buffer。`options` 是一个对象，用于覆盖从传入数据块缓冲区派生的 Angie 缓冲区标志。可以使用以下标志覆盖这些标志：
  <br/>
  `last`
  : 布尔值，`true` 表示该缓冲区是最后一个缓冲区。
  <br/>
  `flush`
  : 布尔值，`true` 表示该缓冲区应具有 `flush` 标志。
  <br/>
  该方法只能从 `js_body_filter` 函数中调用。

<a id="r-send-header"></a>

`r.sendHeader()`
: 向客户端发送 HTTP 头。

<a id="r-set-return-value"></a>

`r.setReturnValue(value)`
: 设置 `js_set` 处理程序的返回值（0.7.0）。与普通的 return 语句不同，当处理程序是 JS 异步函数时应使用此方法。例如：
  <br/>
  ```javascript
  async function js_set(r) {
      const digest = await crypto.subtle.digest('SHA-256', r.headersIn.host);
      r.setReturnValue(digest);
  }
  ```

<a id="r-status"></a>

`r.status`
: 状态，可写。

<a id="r-subrequest"></a>

`r.subrequest(uri[, options[, callback]])`
: 使用给定的 `uri` 和 `options` 创建子请求,并安装可选的完成 `callback`。
  <br/>
  子请求与客户端请求共享其输入标头。要向代理服务器发送与原始标头不同的标头,可以使用 `proxy_set_header` 指令。要向代理服务器发送全新的标头集,可以使用 `proxy_pass_request_headers` 指令。
  <br/>
  如果 `options` 是字符串,则它保存子请求参数字符串。否则,:samp:options 应为具有以下键的对象:
  <br/>
  `args`
  : 参数字符串,默认使用空字符串。
  <br/>
  `body`
  : 请求主体,默认使用父请求对象的请求主体。
  <br/>
  `method`
  : HTTP 方法,默认使用 `GET` 方法。
  <br/>
  `detached`
  : 布尔标志(0.3.9);如果为 `true`,则创建的子请求是分离的子请求。对分离子请求的响应将被忽略。与普通子请求不同,分离的子请求可以在变量处理程序内创建。`detached` 标志和 callback 参数是互斥的。
  <br/>
  完成 `callback` 接收一个子请求响应对象,其方法和属性与父请求对象相同。
  <br/>
  从 0.3.8 开始,如果未提供 `callback`,则返回解析为子请求响应对象的 `Promise` 对象。
  <br/>
  例如,要查看子请求中的所有响应标头:
  <br/>
  ```javascript
  async function handler(r) {
      const reply = await r.subrequest('/path');
  <br/>
      for (const h in reply.headersOut) {
          r.log(`${h}: ${reply.headersOut[h]}`);
      }
  <br/>
      r.return(200);
  }
  ```

<a id="r-uri"></a>

`r.uri`
: 请求中的当前 URI,已规范化,只读。

<a id="r-raw-variables"></a>

`r.rawVariables{}`
: Angie 变量作为 Buffers,可写(自 0.5.0 起)。

<a id="r-variables"></a>

`r.variables{}`
: Angie 变量对象,可写(自 0.2.8 起)。
  <br/>
  例如,要获取 `$foo` 变量,可以使用以下语法之一:
  <br/>
  ```javascript
  r.variables['foo']
  r.variables.foo
  ```
  <br/>
  从 0.8.6 开始,可以使用以下语法访问正则表达式捕获:
  <br/>
  ```javascript
  r.variables['1']
  r.variables[1]
  ```
  <br/>
  Angie 对在 `angie.conf` 中引用的变量和未引用的变量的处理方式不同。当变量被引用时,它可能是可缓存的,但当它未被引用时,它始终是不可缓存的。例如,当 `$request_id` 变量仅从 NJS 访问时,每次求值时它都有一个新值。但是,当 `$request_id` 被引用时,例如:
  <br/>
  ```nginx
  proxy_set_header X-Request-Id $request_id;
  ```
  <br/>
  `r.variables.request_id` 每次都返回相同的值。
  <br/>
  变量可写的条件是:
  <br/>
  - 它是使用 HTTP 或 Stream 的 `js_var` 指令创建的(自 0.5.3 起)
  - 它在 Angie 配置文件中被引用
  <br/>
  即便如此,某些内置变量仍然无法被赋值(例如 `$http_`)。

<a id="r-warn"></a>

`r.warn(string)`
: 在 `warning` 日志级别将 `string` 写入错误日志。
  <br/>
  #### NOTE
  由于 Angie 具有硬编码的最大行长度限制,因此只能记录字符串的前 2048 个字节。

<a id="njs-stream-session"></a>

### Stream 会话

- `s.allow()`
- `s.decline()`
- `s.deny()`
- `s.done()`
- `s.error()`
- `s.log()`
- `s.off()`
- `s.on()`
- `s.remoteAddress`
- `s.rawVariables{}`
- `s.send()`
- `s.sendDownstream()`
- `s.sendUpstream()`
- `s.status`
- `s.setReturnValue()`
- `s.variables{}`
- `s.warn()`

流会话对象仅在 [Stream JS](https://cn.angie.software//angie/docs/installation/external-modules/stream_js.md#stream-js) 模块中可用。在 0.8.5 之前,该对象的所有字符串属性都是字节字符串。

<a id="njs-s-allow"></a>

`s.allow()`
: `s.done(0)` 的别名(0.2.4)。

<a id="njs-s-decline"></a>

`s.decline()`
: `s.done(-5)` 的别名(0.2.4)。

<a id="njs-s-deny"></a>

`s.deny()`
: `s.done(403)` 的别名(0.2.4)。

<a id="njs-s-done"></a>

`s.done([code])`
: 将当前阶段处理程序的退出 `code` 设置为代码值,默认为 `0`。实际的终结发生在 js 处理程序完成并且所有待处理事件(例如来自 `ngx.fetch()` 或 `setTimeout()` 的事件)都被处理之后(0.2.4)。
  <br/>
  可能的代码值:
  <br/>
  - `0` — 成功终结,将控制权传递给下一个阶段
  - `-5` — 未决定,将控制权传递给当前阶段的下一个处理程序(如果有)
  - `403` — 访问被禁止
  <br/>
  只能从阶段处理程序函数调用:`js_access` 或 `js_preread`。

<a id="njs-s-error"></a>

`s.error(string)`
: 在 `error` 日志级别将发送的 `string` 写入错误日志。
  <br/>
  #### NOTE
  由于 Angie 具有硬编码的最大行长度限制,因此只能记录字符串的前 2048 个字节。

<a id="s-log"></a>

`s.log(string)`
: 在 `info` 日志级别将发送的 `string` 写入错误日志。
  <br/>
  #### NOTE
  由于 Angie 具有硬编码的最大行长度限制,因此只能记录字符串的前 2048 个字节。

<a id="s-off"></a>

`s.off(eventName)`
: 注销由 `s.on()` 方法设置的回调(0.2.4)。

<a id="s-on"></a>

`s.on(event, callback)`
: 为指定的 `event` 注册 `callback` (0.2.4)。
  <br/>
  `event` 可以是以下字符串之一:
  <br/>
  `upload`
  : 来自客户端的新数据(字符串)。
  <br/>
  `download`
  : 发送到客户端的新数据(字符串)。
  <br/>
  `upstream`
  : 来自客户端的新数据(Buffer)(自 0.5.0 起)。
  <br/>
  `downstream`
  : 发送到客户端的新数据(Buffer)(自 0.5.0 起)。
  <br/>
  完成回调具有以下原型:`callback(data, flags)`,其中 `data` 是字符串或 Buffer(取决于事件类型);:samp:flags 是具有以下属性的对象:
  <br/>
  `last`
  : 布尔值,:samp:true 表示数据是最后一个缓冲区。

<a id="s-remote-address"></a>

`s.remoteAddress`
: 客户端地址,只读。

<a id="s-raw-variables"></a>

`s.rawVariables`
: Angie 变量作为 Buffers,可写(自 0.5.0 起)。

<a id="s-send"></a>

`s.send(data[, options])`
: 将数据添加到将在正向方向转发的数据块链中:在下载回调中发送到客户端;在上传中发送到上游服务器(0.2.4)。实际转发会在稍后发生,即当前链的所有数据块都处理完毕时。
  <br/>
  数据可以是字符串或 Buffer(0.5.0)。`options` 是一个对象,用于覆盖从传入数据块缓冲区派生的 Angie 缓冲区标志。可以使用以下标志覆盖这些标志:
  <br/>
  `last`
  : 布尔值,:samp:true 表示该缓冲区是最后一个缓冲区。
  <br/>
  `flush`
  : 布尔值,:samp:true 表示该缓冲区应具有 `flush` 标志。
  <br/>
  该方法可以在每次回调调用中多次调用。

<a id="s-send-downstream"></a>

`s.sendDownstream()`
: 与 `s.send()` 相同,但它始终将数据发送到客户端(自 0.7.8 起)。

<a id="s-send-upstream"></a>

`s.sendUpstream()`
: 与 `s.send()` 相同,但它始终从客户端发送数据(自 0.7.8 起)。

<a id="s-status"></a>

`s.status`
: 会话状态代码,:samp:$status 变量的别名,只读(自 0.5.2 起)。

<a id="s-set-return-value"></a>

`s.setReturnValue(value)`
: 设置 `js_set` 处理程序的返回值(0.7.0)。与普通的 return 语句不同,当处理程序是 JS 异步函数时应使用此方法。例如:
  <br/>
  ```javascript
  async function js_set(r) {
      const digest = await crypto.subtle.digest('SHA-256', r.headersIn.host);
      r.setReturnValue(digest);
  }
  ```

<a id="s-variables"></a>

`s.variables{}`
: Angie 变量对象,可写(自 0.2.8 起)。变量只有在 Angie 配置文件中被引用时才可写。即便如此,某些内置变量仍然无法被赋值。

<a id="s-warn"></a>

`s.warn(string)`
: 在 `warning` 日志级别将发送的 `string` 写入错误日志。
  <br/>
  #### NOTE
  由于 Angie 具有硬编码的最大行长度限制,因此只能记录字符串的前 2048 个字节。

<a id="njs-periodic-session"></a>

### 周期会话

- `PeriodicSession.rawVariables{}`
- `PeriodicSession.variables{}`

`Periodic Session` 对象作为 HTTP 和 Stream 的 `js_periodic` 处理程序的第一个参数提供(自 0.8.1 起)。

`PeriodicSession.rawVariables{}`
: Angie 变量作为 Buffers,可写。

`PeriodicSession.variables{}`
: Angie 变量对象,可写。

<a id="njs-headers"></a>

### Headers

- `Headers()`
- `Headers.append()`
- `Headers.delete()`
- `Headers.get()`
- `Headers.getAll()`
- `Headers.forEach()`
- `Headers.has()`
- `Headers.set()`

Fetch API 的 `Headers` 接口自 0.5.1 起可用。

可以使用 `Headers()` 构造函数创建新的 `Headers` 对象(自 0.7.10 起):

`Headers([init])`
: `init`
  : 包含用于预填充 `Headers` 对象的 HTTP 标头的对象,可以是 `string`、名称-值对的 `array`,或现有的 `Headers` 对象。

可以使用以下属性和方法创建新的 `Headers` 对象:

`append()`
: 向 `Headers` 对象中的现有标头追加新值,如果标头不存在则添加该标头(自 0.7.10 起)。

`delete()`
: 从 `Headers` 对象中删除标头(自 0.7.10 起)。

`get()`
: 返回包含指定名称的所有标头值的字符串,值之间用逗号和空格分隔。

`getAll(name)`
: 返回包含指定名称的所有标头值的数组。

`forEach()`
: 对 `Headers` 对象中的每个键/值对执行一次提供的函数(自 0.7.10 起)。

`has()`
: 返回布尔值,指示是否存在具有指定名称的标头。

`set()`
: 为 `Headers` 对象内的现有标头设置新值,如果标头不存在则添加该标头(自 0.7.10 起)。

<a id="njs-request"></a>

### Request

- `Request()`
- `Request.arrayBuffer()`
- `Request.bodyUsed`
- `Request.cache`
- `Request.credentials`
- `Request.headers`
- `Request.json()`
- `Request.method`
- `Request.mode`
- `Request.text()`
- `Request.url`

Fetch API 的 `Request` 接口自 0.7.10 起可用。

可以使用 `Request()` 构造函数创建新的 `Request` 对象:

`Request[resource[, options]])`
: 创建一个可以稍后传递给 `ngx.fetch()` 的 `Request` 对象来获取。`resource` 可以是 URL 或现有的 `Request` 对象。`options` 是可选参数,应为具有以下键的对象:
  <br/>
  `body`
  : 请求主体,默认为空。
  <br/>
  `headers`
  : 响应标头对象——包含用于预填充 `Headers` 对象的 HTTP 标头的对象,可以是 `string`、名称-值对的 `array`,或现有的 `Headers` 对象。
  <br/>
  `method`
  : HTTP 方法,默认使用 GET 方法。

可以使用以下属性和方法创建新的 `Request` 对象:

`arrayBuffer()`
: 返回一个 `Promise`,该 Promise 解析为 `ArrayBuffer`。

`bodyUsed`
: 布尔值,如果主体已在请求中使用则为 `true`。

`cache`
: 包含请求的缓存模式。

`credentials`
: 包含请求的凭据,默认为 `same-origin`。

`headers`
: 与 `Request` 关联的只读 `Headers` 对象。

`json()`
: 返回一个 `Promise`,该 Promise 解析为将请求主体解析为 JSON 的结果。

`method`
: 包含请求方法。

`mode`
: 包含请求的模式。

`text()`
: 返回一个 `Promise`,该 Promise 解析为请求主体的字符串表示形式。

`url`
: 包含请求的 URL。

<a id="njs-response"></a>

### Response

- `Response()`
- `Response.arrayBuffer()`
- `Response.bodyUsed`
- `Response.headers`
- `Response.json()`
- `Response.ok`
- `Response.redirected`
- `Response.status`
- `Response.statusText`
- `Response.text()`
- `Response.type`
- `Response.url`

`Response` 接口自 0.5.1 起可用。

可以使用 `Response()` 构造函数创建新的 `Response` 对象(自 0.7.10 起):

`Response[body[, options]])`
: 创建 `Response` 对象。`body` 是可选参数,可以是 `string` 或 `buffer`,默认为 `null`。`options` 是可选参数,应为具有以下键的对象:
  <br/>
  `headers`
  : 响应标头对象——包含用于预填充 `Headers` 对象的 HTTP 标头的对象,可以是 `string`、名称-值对的 `array`,或现有的 `Headers` 对象。
  <br/>
  `status`
  : 响应的状态码。
  <br/>
  `statusText`
  : 与状态码对应的状态消息。

可以使用以下属性和方法创建新的 `Response()` 对象:

`arrayBuffer()`
: 获取 `Response` 流并读取至完成。返回一个 `Promise`,该 Promise 解析为 `ArrayBuffer`。

`bodyUsed`
: 布尔值,如果主体已被读取则为 `true`。

`headers`
: 与 `Response` 关联的只读 `Headers` 对象。

`json()`
: 获取 `Response` 流并读取至完成。返回一个 `Promise`,该 Promise 解析为将主体文本解析为 JSON 的结果。

`ok`
: 布尔值,如果响应成功(状态码在 200–299 之间)则为 `true`。

`redirected`
: 布尔值,如果响应是重定向的结果则为 `true`。

`status`
: 响应的状态码。

`statusText`
: 与状态码对应的状态消息。

`text()`
: 获取 `Response` 流并读取至完成。返回一个 `Promise`,该 Promise 解析为字符串。

`type`
: 响应的类型。

`url`
: 响应的 URL。

<a id="njs-ngx"></a>

### ngx

- `ngx.build`
- `ngx.conf_file_path`
- `ngx.conf_prefix`
- `ngx.error_log_path`
- `ngx.fetch()`
- `ngx.log()`
- `ngx.prefix`
- `ngx.version`
- `ngx.version_number`
- `ngx.worker_id`

`ngx` 全局对象自 0.5.0 起可用。

`ngx.build`
: 包含可选 Angie 构建名称的字符串,对应于 configure 脚本的 `--build=name` 参数,默认为 `""` (0.8.0)。

`ngx.conf_file_path`
: 包含当前 Angie 配置文件的文件路径的字符串(0.8.0)。

`ngx.conf_prefix`
: 包含 Angie 配置前缀的文件路径的字符串——Angie 当前查找配置的目录(0.7.8)。

`ngx.error_log_path`
: 包含当前错误日志文件的文件路径的字符串(0.8.0)。

<a id="ngx-fetch"></a>

`ngx.fetch(resource, [options])`
: 发起请求以获取 `resource` (0.5.1),可以是 URL 或 `Request` 对象(0.7.10)。返回一个 `Promise`,该 Promise 解析为 `Response` 对象。从 0.7.0 开始,支持 `https://` 协议;不处理重定向。
  <br/>
  如果 `resource` 中的 URL 指定为域名,则使用解析器进行解析。如果指定了 `https://` 协议,则应配置 `js_fetch_trusted_certificate` 指令以对 `resource` 的 HTTPS 服务器进行身份验证。
  <br/>
  `options` 参数应为包含以下键的对象:
  <br/>
  `body`
  : 请求主体,默认为空。
  <br/>
  `buffer_size`
  : 读取响应的缓冲区大小,默认为 `4096`。
  <br/>
  `headers`
  : 请求头对象。
  <br/>
  `max_response_body_size`
  : 响应主体的最大大小(以字节为单位),默认为 `32768`。
  <br/>
  `method`
  : HTTP 方法,默认使用 `GET` 方法。
  <br/>
  `verify`
  : 启用或禁用 HTTPS 服务器证书验证,默认为 `true` (0.7.0)。
  <br/>
  示例:
  <br/>
  ```javascript
  let reply = await ngx.fetch('http://example.com/');
  let body = await reply.text();
  <br/>
  r.return(200, body);
  ```

`ngx.log(level, message)`
: 使用指定的日志级别将消息写入错误日志。`level` 参数指定日志级别之一;:samp:message 参数可以是字符串或 Buffer。可以指定以下日志级别:`ngx.INFO`、`ngx.WARN` 和 `ngx.ERR`。
  <br/>
  #### NOTE
  由于 Angie 具有硬编码的最大行长度限制,因此只能记录字符串的前 2048 个字节。

`ngx.prefix`
: 包含 Angie 前缀文件路径的字符串 — 保存服务器文件的目录(0.8.0)。

`ngx.version`
: 包含 Angie 版本的字符串,例如:`1.25.0` (0.8.0)。

`ngx.version_number`
: 包含 Angie 版本的数字,例如:`1025000` (0.8.0)。

`ngx.worker_id`
: 对应于 Angie 内部工作进程 ID 的数字,该值介于 `0` 和 `worker_processes` 指令中指定的值之间(0.8.0)。

<a id="njs-ngx-shared"></a>

### ngx.shared

`ngx.shared` 全局对象从 0.8.0 开始可用。

<a id="njs-shareddict"></a>

#### SharedDict

- `ngx.shared.SharedDict.add()`
- `ngx.shared.SharedDict.capacity`
- `ngx.shared.SharedDict.clear()`
- `ngx.shared.SharedDict.delete()`
- `ngx.shared.SharedDict.freeSpace()`
- `ngx.shared.SharedDict.get()`
- `ngx.shared.SharedDict.has()`
- `ngx.shared.SharedDict.incr()`
- `ngx.shared.SharedDict.items()`
- `ngx.shared.SharedDict.keys()`
- `ngx.shared.SharedDict.name`
- `ngx.shared.SharedDict.pop()`
- `ngx.shared.SharedDict.replace()`
- `ngx.shared.SharedDict.set()`
- `ngx.shared.SharedDict.size()`
- `ngx.shared.SharedDict.type`

共享字典对象从 0.8.0 开始可用。共享字典的名称、类型和大小通过 HTTP 或 Stream 中的 `js_shared_dict_zone` 指令设置。

`SharedDict()` 对象具有以下属性和方法:

`ngx.shared.SharedDict.add(key, value [,timeout])`
: 仅当键尚不存在时,才为字典中的指定 `key` 设置 `value`。`key` 参数是表示要添加项的键的字符串;:samp:value 参数是要添加项的值。
  <br/>
  可选的 `timeout` 参数以毫秒为单位指定,并覆盖 HTTP 或 Stream 中 `js_shared_dict_zone` 指令的 `timeout` 参数(从 0.8.5 开始)。当某些键预期具有唯一的超时时间时,这可能很有用。
  <br/>
  如果值已成功添加到 `SharedDict` 字典,则返回 `true`;如果键已存在于字典中,则返回 `false`。如果 `SharedDict` 字典中没有足够的可用空间,则抛出 `SharedMemoryError`。如果 `value` 的类型与此字典预期的类型不同,则抛出 `TypeError`。

`ngx.shared.SharedDict.capacity`
: 返回 `SharedDict` 字典的容量,对应于 HTTP 或 Stream 中 `js_shared_dict_zone` 指令的 `size` 参数。

`ngx.shared.SharedDict.clear()`
: 从 `SharedDict` 字典中删除所有项。

`ngx.shared.SharedDict.delete(key)`
: 从 `SharedDict` 字典中删除与指定键关联的项;如果字典中的项存在并已删除,则返回 `true`,否则返回 `false`。

`ngx.shared.SharedDict.freeSpace()`
: 返回可用页面大小(以字节为单位)。如果大小为零,则 `SharedDict` 字典仍将接受新值(如果已占用页面中有空间)。

`ngx.shared.SharedDict.get(key)`
: 通过其 `key` 检索项;返回与 `key` 关联的值,如果没有则返回 `undefined`。

`ngx.shared.SharedDict.has(key)`
: 通过其 `key` 搜索项;如果存在此类项,则返回 `true`,否则返回 `false`。

`ngx.shared.SharedDict.incr(key,delta[[,init], timeout])`
: 将与 `key` 关联的整数值增加 `delta`。`key` 参数是字符串;:samp:delta 参数是要增加或减少值的数字。如果键不存在,则该项将初始化为可选的 `init` 参数,默认为 `0`。
  <br/>
  可选的 `timeout` 参数以毫秒为单位指定,并覆盖 HTTP 或 Stream 中 `js_shared_dict_zone` 指令的 `timeout` 参数(从 0.8.5 开始)。当某些键预期具有唯一的超时时间时,这可能很有用。
  <br/>
  返回新值。如果 `SharedDict` 字典中没有足够的可用空间,则抛出 `SharedMemoryError`。如果此字典不期望数字,则抛出 `TypeError`。
  <br/>
  #### NOTE
  仅当使用 HTTP 或 Stream 中 `js_shared_dict_zone` 指令的 `type=number` 参数声明字典类型时,才能使用此方法。

`ngx.shared.SharedDict.items([maxCount])`
: 返回 `SharedDict` 字典键值项的数组(从 0.8.1 开始)。`maxCount` 参数设置要检索的最大项数,默认为 `1024`。

`ngx.shared.SharedDict.keys([maxCount])`
: 返回 `SharedDict` 字典键的数组。`maxCount` 参数设置要检索的最大键数,默认为 `1024`。

`ngx.shared.SharedDict.name`
: 返回 `SharedDict` 字典的名称,对应于 HTTP 或 Stream 中 `js_shared_dict_zone` 指令的 `zone=` 参数。

`ngx.shared.SharedDict.pop(key)`
: 从 `SharedDict` 字典中删除与指定 `key` 关联的项;返回与 `key` 关联的值,如果没有则返回 `undefined`。

`ngx.shared.SharedDict.replace(key, value)`
: 仅当键已存在时,才替换指定 `key` 的 `value`;如果值已成功替换,则返回 `true`,如果键在 `SharedDict` 字典中不存在,则返回 `false`。如果 `SharedDict` 字典中没有足够的可用空间,则抛出 `SharedMemoryError`。如果 `value` 的类型与此字典预期的类型不同,则抛出 `TypeError`。

`ngx.shared.SharedDict.set(key, value [,timeout])`
: 为指定的 `key` 设置 `value`;返回此 `SharedDict` 字典(用于方法链)。
  <br/>
  可选的 `timeout` 参数以毫秒为单位指定,并覆盖 HTTP 或 Stream 中 `js_shared_dict_zone` 指令的 `timeout` 参数(从 0.8.5 开始)。当某些键预期具有唯一的超时时间时,这可能很有用。

`ngx.shared.SharedDict.size()`
: 返回 `SharedDict` 字典的项数。

`ngx.shared.SharedDict.type`
: 返回 `string` 或 `number`,对应于 HTTP 或 Stream 中 `js_shared_dict_zone` 指令的 `type=` 参数设置的 `SharedDict` 字典类型。

<a id="njs-builtin-objects"></a>

## 内置对象

<a id="njs-console"></a>

### console

- `console.error()`
- `console.info()`
- `console.log()`
- `console.time()`
- `console.timeEnd()`
- `console.warn()`

`console` 对象从 Angie 0.8.2 开始可用,从 CLI 0.2.6 开始可用。

`console.error(msg[, msg2 ...])`
: 输出一条或多条错误消息。消息可以是字符串或对象。

`console.info(msg[, msg2 ...])`
: 输出一条或多条信息消息。消息可以是字符串或对象。

`console.log(msg[, msg2 ...])`
: 输出一条或多条日志消息。消息可以是字符串或对象。

`console.time(label)`
: 启动一个计时器,可以跟踪操作所需的时间。`label` 参数允许命名不同的计时器。如果使用相同的名称调用 `console.timeEnd()`,则将输出自计时器启动以来经过的时间(以毫秒为单位)。

`console.timeEnd(label)`
: 停止先前由 `console.time()` 启动的计时器。`label` 参数允许命名不同的计时器。

`console.warn(msg[, msg2 ...])`
: 输出一条或多条警告消息。消息可以是字符串或对象。

<a id="njs-builtin-crypto"></a>

### crypto

- `crypto.getRandomValues()`
- `crypto.subtle.encrypt()`
- `crypto.subtle.decrypt()`
- `crypto.subtle.deriveBits()`
- `crypto.subtle.deriveKey()`
- `crypto.subtle.digest()`
- `crypto.subtle.exportKey()`
- `crypto.subtle.generateKey()`
- `crypto.subtle.importKey()`
- `crypto.subtle.sign()`
- `crypto.subtle.verify()`

`crypto` 对象是一个全局对象,允许使用加密功能(自 0.7.0 起)。

`crypto.getRandomValues(typedArray)`
: 获取加密强度的随机值。返回作为 `typedArray` 传递的同一数组,但其内容被替换为新生成的随机数。可能的值:
  <br/>
  `typedArray`
  : 可以是 `Int8Array`、`Int16Array`、`Uint16Array`、`Int32Array` 或 `Uint32Array`。

`crypto.subtle.encrypt(algorithm, key, data)`
: 使用提供的 `algorithm` 和 `key` 加密 `data`。返回一个 `Promise`,该 Promise 将使用包含密文的 `ArrayBuffer` 来兑现。可能的值:
  <br/>
  `algorithm`
  : 一个对象,指定要使用的算法以及所需的任何额外参数:
    <br/>
    - 对于 `RSA-OAEP`,传递一个具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `RSA-OAEP`:
        ```javascript
        crypto.subtle.encrypt({name: "RSA-OAEP"}, key, data)
        ```
    - 对于 `AES-CTR`,传递一个具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `AES-CTR`。
    <br/>
      `counter`
      : 一个 `ArrayBuffer`、`TypedArray` 或 `DataView` — 计数器块的初始值,必须为 16 字节长(AES 块大小)。此块最右边的 length 位用于计数器,其余部分用于随机数。例如,如果 length 设置为 64,则 counter 的前半部分是随机数,后半部分用于计数器。
    <br/>
      `length`
      : 计数器块中用于实际计数器的位数。计数器必须足够大,以免回绕。
    - 对于 `AES-CBC`,传递一个具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `AES-CBC`。
    <br/>
      `iv`
      : 初始化向量,是一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,必须为 16 字节,不可预测,最好是加密随机的。但是,它不需要保密,例如,它可以与密文一起未加密传输。
    - 对于 `AES-GCM`,传递一个具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `AES-GCM`。
    <br/>
      `iv`
      : 初始化向量,是一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,必须为 16 字节,并且对于使用给定密钥执行的每个加密操作必须是唯一的。
    <br/>
      `additionalData`
      : (可选)是一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,包含不会被加密但将与加密数据一起进行身份验证的附加数据。如果指定了 `additionalData`,则必须在相应的 `decrypt()` 调用中指定相同的数据:如果提供给 `decrypt()` 调用的数据与原始数据不匹配,解密将抛出异常。`additionalData` 的位长度必须小于 `2^64 - 1`。
    <br/>
      `tagLength`
      : (可选,默认为 `128`) - 一个 `number`,确定在加密操作中生成的身份验证标签的位大小,并在相应的解密中用于身份验证。可能的值: `32`、`64`、`96`、`104`、`112`、`120` 或 `128`。AES-GCM 规范建议应为 `96`、`104`、`112`、`120` 或 `128`,尽管在某些应用程序中 `32` 或 `64` 位可能是可接受的。
  <br/>
  `key`
  : 一个 `CryptoKey`,包含用于加密的密钥。
  <br/>
  `data`
  : 一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,包含要加密的数据(也称为明文)。

`crypto.subtle.decrypt(algorithm, key, data)`
: 解密加密的数据。返回一个包含解密数据的 `Promise`。可能的值:
  <br/>
  `algorithm`
  : 一个对象,指定要使用的算法以及所需的任何额外参数。为额外参数提供的值必须与传递到相应 `encrypt()` 调用中的值匹配。
    <br/>
    - 对于 `RSA-OAEP`,传递一个具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `RSA-OAEP`:
        ```javascript
        crypto.subtle.encrypt({name: "RSA-OAEP"}, key, data)
        ```
    - 对于 `AES-CTR`,传递一个具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `AES-CTR`。
    <br/>
      `counter`
      : 一个 `ArrayBuffer`、`TypedArray` 或 `DataView` — 计数器块的初始值,必须为 16 字节长(AES 块大小)。此块最右边的 length 位用于计数器,其余部分用于随机数。例如,如果 length 设置为 64,则 counter 的前半部分是随机数,后半部分用于计数器。
    <br/>
      `length`
      : 计数器块中用于实际计数器的位数。计数器必须足够大,以免回绕。
    - 对于 `AES-CBC`,传递一个具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `AES-CBC`。
    <br/>
      `iv`
      : 初始化向量,是一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,必须为 16 字节,不可预测,最好是加密随机的。但是,它不需要保密(例如,它可以与密文一起未加密传输)。
    - 对于 `AES-GCM`,传递一个具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `AES-GCM`。
    <br/>
      `iv`
      : 初始化向量,是一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,必须为 16 字节,并且对于使用给定密钥执行的每个加密操作必须是唯一的。
    <br/>
      `additionalData`
      : (可选)是一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,包含不会被加密但将与加密数据一起进行身份验证的附加数据。如果指定了 `additionalData`,则必须在相应的 `decrypt()` 调用中指定相同的数据:如果提供给 `decrypt()` 调用的数据与原始数据不匹配,解密将抛出异常。`additionalData` 的位长度必须小于 `2^64 - 1`。
    <br/>
      `tagLength`
      : (可选,默认为 `128`) - 一个 `number`,确定在加密操作中生成的身份验证标签的位大小,并在相应的解密中用于身份验证。可能的值: `32`、`64`、`96`、`104`、`112`、`120` 或 `128`。AES-GCM 规范建议应为 `96`、`104`、`112`、`120` 或 `128`,尽管在某些应用程序中 `32` 或 `64` 位可能是可接受的。
  <br/>
  `key`
  : 一个 `CryptoKey`,包含用于解密的密钥。如果使用 `RSA-OAEP`,这是 `CryptoKeyPair` 对象的 `privateKey` 属性。
  <br/>
  `data`
  : 一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,包含要解密的数据(也称为密文)。

`crypto.subtle.deriveBits(algorithm, baseKey, length)`
: 从基础密钥派生位数组。返回一个 `Promise`,该 Promise 将使用包含派生位的 `ArrayBuffer` 来兑现。可能的值:
  <br/>
  `algorithm`
  : 一个对象,定义要使用的派生算法:
    <br/>
    - 对于 `HKDF`,传递一个具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `HKDF`。
    <br/>
      `hash`
      : 一个字符串,包含要使用的摘要算法: `SHA-1`、`SHA-256`、`SHA-384` 或 `SHA-512`。
    <br/>
      `salt`
      : 一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,表示与 `digest` 函数的输出长度相同的随机或伪随机值。与传递到 `deriveKey()` 中的输入密钥材料不同,salt 不需要保密。
    <br/>
      `info`
      : 一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,表示特定于应用程序的上下文信息,用于将派生密钥绑定到应用程序或上下文,并允许在使用相同输入密钥材料的同时为不同上下文派生不同的密钥。此属性是必需的,但可以是空缓冲区。
    - 对于 `PBKDF2`,传递一个具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `PBKDF2`。
    <br/>
      `hash`
      : 一个字符串,包含要使用的摘要算法: `SHA-1`、`SHA-256`、`SHA-384` 或 `SHA-512`。
    <br/>
      `salt`
      : 一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,表示至少 `16` 字节的随机或伪随机值。与传递到 `deriveKey()` 中的输入密钥材料不同,salt 不需要保密。
    <br/>
      `iterations`
      : 一个 `number`,表示在 `deriveKey()` 中哈希函数将被执行的次数。
    - 对于 `ECDH`,传递具有以下键的对象(自 0.9.1 起):
    <br/>
      `name`
      : 一个字符串,应设置为 `ECDH`。
    <br/>
      `public`
      : 一个 `CryptoKey`,表示另一方的公钥。该密钥必须使用与基础密钥相同的曲线生成。
  <br/>
  `baseKey`
  : 一个 `CryptoKey`,表示派生算法的输入 - 派生函数的初始密钥材料:例如,对于 `PBKDF2`,它可能是一个密码,使用 `crypto.subtle.importKey()` 作为 `CryptoKey` 导入。
  <br/>
  `length`
  : 一个数字,表示要派生的比特数。为了浏览器兼容性,该数字应该是 `8` 的倍数。

`crypto.subtle.deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages)`
: 从主密钥派生一个秘密密钥。可能的值:
  <br/>
  `algorithm`
  : 一个对象,定义要使用的派生算法:
    <br/>
    - 对于 `HKDF`,传递具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `HKDF`。
    <br/>
      `hash`
      : 一个字符串,包含要使用的摘要算法: `SHA-1`、`SHA-256`、`SHA-384` 或 `SHA-512`。
    <br/>
      `salt`
      : 一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,表示与 `digest` 函数输出长度相同的随机或伪随机值。与传递给 `deriveKey()` 的输入密钥材料不同,盐不需要保密。
    <br/>
      `info`
      : 一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,表示特定于应用程序的上下文信息,用于将派生密钥绑定到应用程序或上下文,并允许在使用相同输入密钥材料的同时为不同上下文派生不同的密钥。此属性是必需的,但可以是空缓冲区。
    - 对于 `PBKDF2`,传递具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `PBKDF2`。
    <br/>
      `hash`
      : 一个字符串,包含要使用的摘要算法: `SHA-1`、`SHA-256`、`SHA-384` 或 `SHA-512`。
    <br/>
      `salt`
      : 一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,表示至少 `16` 字节的随机或伪随机值。与传递给 `deriveKey()` 的输入密钥材料不同,盐不需要保密。
    <br/>
      `iterations`
      : 一个 `number`,表示在 `deriveKey()` 中哈希函数将被执行的次数。
    - 对于 `ECDH`,传递具有以下键的对象(自 0.9.1 起):
    <br/>
      `name`
      : 一个字符串,应设置为 `ECDH`。
    <br/>
      `publicKey`
      : 一个 `CryptoKey`,表示另一方的公钥。该密钥必须使用与基础密钥相同的曲线生成。
  <br/>
  `baseKey`
  : 一个 `CryptoKey`,表示派生算法的输入 - 派生函数的初始密钥材料:例如,对于 `PBKDF2`,它可能是一个密码,使用 `crypto.subtle.importKey()` 作为 `CryptoKey` 导入。
  <br/>
  `derivedKeyAlgorithm`
  : 一个对象,定义派生密钥将用于的算法:
    <br/>
    - 对于 `HMAC`,传递具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应设置为 `HMAC`。
    <br/>
      `hash`
      : 一个字符串,包含要使用的摘要函数的名称: `SHA-1`、`SHA-256`、`SHA-384` 或 `SHA-512`。
    <br/>
      `length`
      : (可选)是一个 `number`,表示密钥的比特长度。如果未指定,密钥的长度等于所选哈希函数的块大小。
    - 对于 `AES-CTR`、`AES-CBC` 或 `AES-GCM`,传递具有以下键的对象:
    <br/>
      `name`
      : 一个字符串,应根据所使用的算法设置为 `AES-CTR`、`AES-CBC` 或 `AES-GCM`。
    <br/>
      `length`
      : 一个 `number`,表示要生成的密钥的比特长度: `128`、`192` 或 `256`。
  <br/>
  `extractable`
  : 一个布尔值,指示是否可以导出密钥。
  <br/>
  `keyUsages`
  : 一个 `Array`,指示可以对派生密钥执行的操作。密钥用途必须被 `derivedKeyAlgorithm` 中设置的算法所允许。可能的值:
    <br/>
    `encrypt`
    : 用于加密消息的密钥。
    <br/>
    `decrypt`
    : 用于解密消息的密钥。
    <br/>
    `sign`
    : 用于签名消息的密钥。
    <br/>
    `verify`
    : 用于验证签名的密钥。
    <br/>
    `deriveKey`
    : 用于派生新密钥的密钥。
    <br/>
    `deriveBits`
    : 用于派生比特的密钥。
    <br/>
    `wrapKey`
    : 用于包装密钥的密钥。
    <br/>
    `unwrapKey`
    : 用于解包密钥的密钥。

`crypto.subtle.digest(algorithm, data)`
: 生成给定数据的摘要。接受要使用的摘要算法的标识符和要摘要的数据作为参数。返回一个 `Promise`,该 Promise 将使用摘要来完成。可能的值:
  <br/>
  `algorithm`
  : 一个字符串,定义要使用的哈希函数: `SHA-1` (不用于加密应用程序)、`SHA-256`、`SHA-384` 或 `SHA-512`。
  <br/>
  `data`
  : 一个 `ArrayBuffer`、`TypedArray` 或 `DataView`,包含要摘要的数据。

`crypto.subtle.exportKey(format, key)`
: 导出密钥:将密钥作为 `CryptoKey` 对象,并以外部可移植格式返回密钥(自 0.7.10 起)。如果 `format` 是 `jwk`,则 `Promise` 使用包含密钥的 JSON 对象来完成。否则,promise 使用包含密钥的 `ArrayBuffer` 来完成。可能的值:
  <br/>
  `format`
  : 一个字符串,描述应导出密钥的数据格式,可以是以下值:
    <br/>
    `raw`
    : 原始数据格式。

- 对于 `HMAC`,传递具有以下键的对象:
  > > > `name`
  > > > : 字符串,应设置为 `HMAC`。

  > > > `hash`
  > > > : 字符串,包含要使用的摘要函数的名称:可以是 `SHA-1`、`SHA-256`、`SHA-384` 或 `SHA-512`。

  > > > `length`
  > > > : (可选)是一个 `number`,表示密钥的比特长度。如果未指定,密钥的长度等于所选哈希函数的块大小。
  > > - 对于 `AES-CTR`、`AES-CBC` 或 `AES-GCM`,传递具有以下键的对象:

  > >   `name`
  > >   : 字符串,应根据所使用的算法设置为 `AES-CTR`、`AES-CBC` 或 `AES-GCM`。

  > >   `length`
  > >   : 一个 `number`,表示要生成的密钥的比特长度:可以是 `128`、`192` 或 `256`。

  > `extractable`
  > : 布尔值,指示是否可以导出密钥。

  > `keyUsages`
  > : 一个 `Array`,指示派生密钥可以执行的操作。密钥用途必须被 `derivedKeyAlgorithm` 中设置的算法所允许。可能的值:
  >   <br/>
  >   `encrypt`
  >   : 用于加密消息的密钥。
  >   <br/>
  >   `decrypt`
  >   : 用于解密消息的密钥。
  >   <br/>
  >   `sign`
  >   : 用于签名消息的密钥。
  >   <br/>
  >   `verify`
  >   : 用于验证签名的密钥。
  >   <br/>
  >   `deriveKey`
  >   : 用于派生新密钥的密钥。
  >   <br/>
  >   `deriveBits`
  >   : 用于派生比特的密钥。
  >   <br/>
  >   `wrapKey`
  >   : 用于包装密钥的密钥。
  >   <br/>
  >   `unwrapKey`
  >   : 用于解包密钥的密钥。

`crypto.subtle.digest(algorithm, data)`
: 生成给定数据的摘要。接受要使用的摘要算法的标识符和要摘要的数据作为参数。返回一个 `Promise`,该 Promise 以摘要来兑现。可能的值:
  <br/>
  `algorithm`
  : 定义要使用的哈希函数的字符串:可以是 `SHA-1` (不用于加密应用)、`SHA-256`、`SHA-384` 或 `SHA-512`。
  <br/>
  `data`
  : 包含要摘要的数据的 `ArrayBuffer`、`TypedArray` 或 `DataView`。

`crypto.subtle.exportKey(format, key)`
: 导出密钥:接受一个密钥作为 `CryptoKey` 对象,并以外部可移植格式返回密钥(自 0.7.10 起)。如果 `format` 是 `jwk`,则 `Promise` 以包含密钥的 JSON 对象来兑现。否则,Promise 以包含密钥的 `ArrayBuffer` 来兑现。可能的值:
  <br/>
  `format`
  : 描述密钥应以何种数据格式导出的字符串,可以是以下值:
    <br/>
    `raw`
    : 原始数据格式。
    <br/>
    `pkcs8`
    : [PKCS #8](https://datatracker.ietf.org/doc/html/rfc5208) 格式。
    <br/>
    `spki`
    : [SubjectPublicKeyInfo](https://datatracker.ietf.org/doc/html/rfc5280#section-4.1) 格式。
    <br/>
    `jwk`
    : [JSON Web Key](https://datatracker.ietf.org/doc/html/rfc7517) (JWK) 格式(自 0.7.10 起)。
  <br/>
  `key`
  : 包含要导出的密钥的 `CryptoKey`。

`crypto.subtle.generateKey(algorithm, extractable, usage)`
: 为对称算法生成新密钥或为公钥算法生成密钥对(自 0.7.10 起)。返回一个 `Promise`,该 Promise 以生成的密钥作为 `CryptoKey` 或 `CryptoKeyPair` 对象来兑现。可能的值:
  <br/>
  `algorithm`
  : 一个字典对象,定义要生成的密钥类型并提供额外的特定于算法的参数:
    <br/>
    - 对于 `RSASSA-PKCS1-v1_5`、`RSA-PSS` 或 `RSA-OAEP`,传递具有以下键的对象:
    <br/>
      `name`
      : 字符串,应根据所使用的算法设置为 `RSASSA-PKCS1-v1_5`、`RSA-PSS` 或 `RSA-OAEP`。
    <br/>
      `hash`
      : 字符串,表示要使用的 `digest` 函数的名称,可以是 `SHA-256`、`SHA-384` 或 `SHA-512`。
    - 对于 `ECDSA`,传递具有以下键的对象:
    <br/>
      `name`
      : 字符串,应设置为 `ECDSA`。
    <br/>
      `namedCurve`
      : 字符串,表示要使用的椭圆曲线的名称,可以是 `P-256`、`P-384` 或 `P-521`。
    - 对于 `HMAC`,传递具有以下键的对象:
    <br/>
      `name`
      : 字符串,应设置为 `HMAC`。
    <br/>
      `hash`
      : 字符串,表示要使用的 `digest` 函数的名称,可以是 `SHA-256`、`SHA-384` 或 `SHA-512`。
    <br/>
      `length`
      : (可选)是一个数字,表示密钥的比特长度。如果省略,密钥的长度等于所选摘要函数生成的摘要的长度。
    - 对于 `AES-CTR`、`AES-CBC` 或 `AES-GCM`,传递标识算法的字符串或形式为 ` *"name": "ALGORITHM"* ` 的对象,其中 `ALGORITHM` 是算法的名称。
    - 对于 `ECDH`,传递具有以下键的对象(自 0.9.1 起):
    <br/>
      `name`
      : 字符串,应设置为 `ECDH`。
    <br/>
      `namedCurve`
      : 字符串,表示要使用的椭圆曲线的名称,可以是 `P-256`、`P-384` 或 `P-521`。
  <br/>
  `extractable`
  : 布尔值,指示是否可以导出密钥。
  <br/>
  `usage`
  : 一个 `array`,指示密钥的可能操作:
    <br/>
    `encrypt`
    : 用于加密消息的密钥。
    <br/>
    `decrypt`
    : 用于解密消息的密钥。
    <br/>
    `sign`
    : 用于签名消息的密钥。
    <br/>
    `verify`
    : 用于验证签名的密钥。
    <br/>
    `deriveKey`
    : 用于派生新密钥的密钥。
    <br/>
    `deriveBits`
    : 用于派生比特的密钥。
    <br/>
    `wrapKey`
    : 用于包装密钥的密钥。
    <br/>
    `unwrapKey`
    : 用于解包密钥的密钥。

`crypto.subtle.importKey(format, keyData, algorithm, extractable, keyUsages)`
: 导入密钥:接受外部可移植格式的密钥作为输入,并返回一个 `CryptoKey` 对象。返回一个 `Promise`,该 Promise 以导入的密钥作为 `CryptoKey` 对象来兑现。可能的值:
  <br/>
  `format`
  : 描述要导入的密钥的数据格式的字符串,可以是以下值:
    <br/>
    `raw`
    : 原始数据格式。
    <br/>
    `pkcs8`
    : [PKCS #8](https://datatracker.ietf.org/doc/html/rfc5208) 格式。
    <br/>
    `spki`
    : [SubjectPublicKeyInfo](https://datatracker.ietf.org/doc/html/rfc5280#section-4.1) 格式。
    <br/>
    `jwk`
    : [JSON Web Key](https://datatracker.ietf.org/doc/html/rfc7517) (JWK) 格式(自 0.7.10 起)。
  <br/>
  `keyData`
  : 包含给定格式密钥的 `ArrayBuffer`、`TypedArray` 或 `DataView` 对象。
  <br/>
  `algorithm`
  : 定义要导入的密钥类型并提供额外的算法特定参数的字典对象:
    <br/>
    - 对于 `RSASSA-PKCS1-v1_5`、`RSA-PSS` 或 `RSA-OAEP`,传递具有以下键的对象:
    <br/>
      `name`
      : 字符串,应根据所使用的算法设置为 `RSASSA-PKCS1-v1_5`、`RSA-PSS` 或 `RSA-OAEP`。
    <br/>
      `hash`
      : 字符串,表示要使用的 `digest` 函数的名称,可以是 `SHA-1`、`SHA-256`、`SHA-384` 或 `SHA-512`。
    - 对于 `ECDSA`,传递具有以下键的对象:
    <br/>
      `name`
      : 字符串,应设置为 `ECDSA`。
    <br/>
      `namedCurve`
      : 字符串,表示要使用的椭圆曲线的名称,可以是 `P-256`、`P-384` 或 `P-521`。
    - 对于 `HMAC`,传递具有以下键的对象:
    <br/>
      `name`
      : 字符串,应设置为 `HMAC`。
    <br/>
      `hash`
      : 字符串,表示要使用的 `digest` 函数的名称,可以是 `SHA-256`、`SHA-384` 或 `SHA-512`。
    <br/>
      `length`
      : (可选)是一个数字,表示密钥的比特长度。如果省略,密钥的长度等于所选摘要函数生成的摘要的长度。
    - 对于 `AES-CTR`、`AES-CBC` 或 `AES-GCM`,传递标识算法的字符串或形式为 ` *"name": "ALGORITHM"* ` 的对象,其中 `ALGORITHM` 是算法的名称。
    - 对于 `PBKDF2`,传递 `PBKDF2` 字符串。
    - 对于 `HKDF`,传递 `HKDF` 字符串。
    - 对于 `ECDH`,传递具有以下键的对象(自 0.9.1 起):
    <br/>
      `name`
      : 字符串,应设置为 `ECDH`。
    <br/>
      `namedCurve`
      : 字符串,表示要使用的椭圆曲线的名称,可以是 `P-256`、`P-384` 或 `P-521`。
  <br/>
  `extractable`
  : 布尔值,指示是否可以导出密钥。
  <br/>
  `keyUsages`
  : 一个 `array`,指示密钥的可能操作:
    <br/>
    `encrypt`
    : 用于加密消息的密钥。
    <br/>
    `decrypt`
    : 用于解密消息的密钥。
    <br/>
    `sign`
    : 用于签名消息的密钥。
    <br/>
    `verify`
    : 用于验证签名的密钥。
    <br/>
    `deriveKey`
    : 用于派生新密钥的密钥。
    <br/>
    `deriveBits`
    : 用于派生比特的密钥。
    <br/>
    `wrapKey`
    : 用于包装密钥的密钥。
    <br/>
    `unwrapKey`
    : 用于解包密钥的密钥。

`crypto.subtle.sign(algorithm, key, data)`
: 返回 `signature` 作为 `Promise`,该 Promise 以包含签名的 `ArrayBuffer` 来兑现。可能的值:
  <br/>
  `algorithm`
  : 指定要使用的签名算法及其参数的字符串或对象:
    <br/>
    - 对于 `RSASSA-PKCS1-v1_5`,传递标识算法的字符串或形式为 ` *"name": "ALGORITHM"* ` 的对象。
    - 对于 `RSA-PSS`,传递具有以下键的对象:
    <br/>
      `name`
      : 字符串,应设置为 `RSA-PSS`。
    <br/>
      `saltLength`
      : 长整型 `integer`,表示要使用的随机盐的长度(以字节为单位)。
    - 对于 `ECDSA`,传递具有以下键的对象:
    <br/>
      `name`
      : 字符串,应设置为 `ECDSA`。
    <br/>
      `hash`
      : 要使用的摘要算法的标识符,可以是 `SHA-256`、`SHA-384` 或 `SHA-512`。
    - 对于 `HMAC`,传递标识算法的字符串或形式为 ` *"name": "ALGORITHM"* ` 的对象。
  <br/>
  `key`
  : 包含用于签名的密钥的 `CryptoKey` 对象。如果算法标识公钥密码系统,则这是私钥。
  <br/>
  `data`
  : 包含要签名的数据的 `ArrayBuffer`、`TypedArray` 或 `DataView` 对象。

`crypto.subtle.verify(algorithm, key, signature, data)`
: 验证数字签名;返回一个 `Promise`,该 Promise 以布尔值兑现:如果签名有效则为 `true`,否则为 `false`。可能的值:
  <br/>
  `algorithm`
  : 指定要使用的算法及其参数的字符串或对象:
    <br/>
    - 对于 `RSASSA-PKCS1-v1_5`,传递标识算法的字符串或形式为 ` *"name": "ALGORITHM"* ` 的对象。
    - 对于 `RSA-PSS`,传递具有以下键的对象:
    <br/>
      `name`
      : 字符串,应设置为 `RSA-PSS`。
    <br/>
      `saltLength`
      : 长整型 `integer`,表示要使用的随机盐的长度(以字节为单位)。
    - 对于 `ECDSA`,传递具有以下键的对象:
    <br/>
      `name`
      : 字符串,应设置为 `ECDSA`。
    <br/>
      `hash`
      : 要使用的摘要算法的标识符,可以是 `SHA-256`、`SHA-384` 或 `SHA-512`。
    - 对于 `HMAC`,传递标识算法的字符串或形式为 ` *"name": "ALGORITHM"* ` 的对象。
  <br/>
  `key`
  : 包含用于验证的密钥的 `CryptoKey` 对象。对于对称算法,它是密钥;对于公钥系统,它是公钥。
  <br/>
  `signature`
  : 包含要验证的签名的 `ArrayBuffer`、`TypedArray` 或 `DataView`。
  <br/>
  `data`
  : 包含要验证其签名的数据的 `ArrayBuffer`、`TypedArray` 或 `DataView` 对象。

<a id="njs-cryptokey"></a>

#### CryptoKey

- `CryptoKey.algorithm`
- `CryptoKey.extractable`
- `CryptoKey.type`
- `CryptoKey.usages`

`CryptoKey` 对象表示从 `SubtleCrypto` 方法之一获得的加密 `key`：`crypto.subtle.generateKey()`、`crypto.subtle.deriveKey()`、`crypto.subtle.importKey()`。

`CryptoKey.algorithm`
: 返回一个对象,描述此密钥可用于的算法以及任何相关的额外参数(自 0.8.0 起),只读。

`CryptoKey.extractable`
: 布尔值,如果密钥可以导出则为 `true` (自 0.8.0 起),只读。

`CryptoKey.type`
: 字符串值,指示对象表示的密钥类型,只读。可能的值:
  <br/>
  `secret`
  : 此密钥是用于对称算法的秘密密钥。
  <br/>
  `private`
  : 此密钥是非对称算法 `CryptoKeyPair` 的私钥部分。
  <br/>
  `public`
  : 此密钥是非对称算法 `CryptoKeyPair` 的公钥部分。

`CryptoKey.usages`
: 字符串数组,指示此密钥可用于什么用途(自 0.8.0 起),只读。可能的数组值:
  <br/>
  `encrypt`
  : 用于加密消息的密钥。
  <br/>
  `decrypt`
  : 用于解密消息的密钥。
  <br/>
  `sign`
  : 用于签名消息的密钥。
  <br/>
  `verify`
  : 用于验证签名的密钥。
  <br/>
  `deriveKey`
  : 用于派生新密钥的密钥。
  <br/>
  `deriveBits`
  : 用于派生比特的密钥。

<a id="njs-cryptokeypair"></a>

#### CryptoKeyPair

- `CryptoKeyPair.privateKey`
- `CryptoKeyPair.publicKey`

`CryptoKeyPair` 是 WebCrypto API 的字典对象,表示非对称密钥对。

`CryptoKeyPair.privateKey`
: 表示私钥的 `CryptoKey` 对象。

`CryptoKeyPair.publicKey`
: 表示公钥的 `CryptoKey` 对象。

<a id="njs-njs"></a>

### njs

- `njs.version`
- `njs.version_number`
- `njs.dump()`
- `njs.memoryStats`
- `njs.on()`

`njs` 对象是表示当前 VM 实例的全局对象(自 0.2.0 起)。

`njs.version`
: 返回包含当前 NJS 版本的字符串(例如,"0.7.4")。

`njs.version_number`
: 返回包含当前 NJS 版本的数字。例如,"0.7.4" 返回为 `0x000704` (自 0.7.4 起)。

`njs.dump(value)`
: 返回值的美化打印字符串表示。

`njs.memoryStats`
: 包含当前 VM 实例内存统计信息的对象(自 0.7.8 起)。
  <br/>
  `size`
  : NJS 内存池从操作系统申请的内存量(以字节为单位)。

`njs.on(event, callback)`
: 为指定的 VM 事件注册回调(自 0.5.2 起)。事件可以是以下字符串之一:
  <br/>
  `exit`
  : 在 VM 销毁之前调用。回调不带参数调用。

<a id="njs-process"></a>

### process

- `process.argv`
- `process.env`
- `process.kill()`
- `process.pid`
- `process.ppid`

`process` 对象是提供有关当前进程信息的全局对象(0.3.3)。

`process.argv`
: 返回包含启动当前进程时传递的命令行参数的数组。

`process.env`
: 返回包含用户环境的对象。
  <br/>
  #### NOTE
  默认情况下,Angie 会删除从其父进程继承的所有环境变量,但 TZ 变量除外。使用 `env` 指令来保留一些继承的变量。

`process.kill(pid, number | string)`
: 向由 `pid` 标识的进程发送信号。信号名称是数字或字符串,例如 `SIGINT` 或 `SIGHUP`。有关更多信息,请参阅 [kill(2)](https://man7.org/linux/man-pages/man2/kill.2.html)。

`process.pid`
: 返回当前进程的 PID。

`process.ppid`
: 返回当前父进程的 PID。

<a id="njs-string"></a>

### String

默认情况下,NJS 中的所有字符串都是 Unicode 字符串。它们对应于包含 Unicode 字符的 ECMAScript 字符串。在 0.8.0 之前,还支持字节字符串。

<a id="byte-strings-removed"></a>

#### 字节字符串(已移除)

#### NOTE
自 0.8.0 起,已移除对字节字符串和字节字符串方法的支持。在处理字节序列时,应使用 [Buffer](#njs-buffer) 对象和 Buffer 属性,例如 `r.requestBuffer`、`r.rawVariables`。

字节字符串包含字节序列,用于将 Unicode 字符串序列化为外部数据以及从外部源反序列化。例如,:samp:toUTF8() 方法使用 UTF-8 编码将 Unicode 字符串序列化为字节字符串。`toBytes()` 方法将代码点最多为 255 的 Unicode 字符串序列化为字节字符串;否则返回 `null`。

以下方法已过时并在 0.8.0 中移除:

- `String.bytesFrom()` (在 0.8.0 中移除,使用 `Buffer.from()`)
- `String.prototype.fromBytes()` (在 0.8.0 中移除)
- `String.prototype.fromUTF8()` (在 0.8.0 中移除,使用 `TextDecoder`)
- `String.prototype.toBytes()` (在 0.8.0 中移除)
- `String.prototype.toString()` 带编码(在 0.8.0 中移除)
- `String.prototype.toUTF8()` (在 0.8.0 中移除,使用 `TextEncoder`)

<a id="njs-webapi"></a>

## Web API

<a id="njs-textdecoder"></a>

### TextDecoder

- `TextDecoder()`
- `TextDecoder.prototype.encoding`
- `TextDecoder.prototype.fatal`
- `TextDecoder.prototype.ignoreBOM`
- `TextDecoder.prototype.decode()`

`TextDecoder` 从字节流生成代码点流(0.4.3)。

`TextDecoder([[encoding], options])`
: 为指定的 `encoding` 创建新的 `TextDecoder` 对象;目前仅支持 UTF-8。`options` 是具有以下属性的 `TextDecoderOptions` 字典:
  <br/>
  `fatal`
  : 布尔标志,指示当发现编码错误时 `TextDecoder.decode()` 是否必须抛出 `TypeError` 异常,默认为 `false`。

`TextDecoder.prototype.encoding`
: 返回包含 `TextDecoder()` 使用的编码名称的字符串,只读。

`TextDecoder.prototype.fatal`
: 布尔标志,如果错误模式是致命的则为 `true`,只读。

`TextDecoder.prototype.ignoreBOM`
: 布尔标志,如果忽略字节顺序标记则为 `true`,只读。

`TextDecoder.prototype.decode(buffer, [options])`
: 返回包含由 `TextDecoder()` 从 `buffer` 解码的文本的字符串。缓冲区可以是 `ArrayBuffer`。`options` 是具有以下属性的 `TextDecodeOptions` 字典:
  <br/>
  `stream`
  : 布尔标志,指示后续调用 `decode()` 时是否会有额外数据:如果分块处理数据则为 `true`,如果是最后一块或数据未分块则为 `false`。默认为 `false`。
  <br/>
  示例:
  <br/>
  ```javascript
  >> (new TextDecoder()).decode(new Uint8Array([206,177,206,178]))
  αβ
  ```

<a id="njs-textencoder"></a>

### TextEncoder

- `TextEncoder()`
- `TextEncoder.prototype.encode()`
- `TextEncoder.prototype.encodeInto()`

`TextEncoder` 对象从代码点流生成 UTF-8 编码的字节流(0.4.3)。

`TextEncoder()`
: 返回新构造的 `TextEncoder`,它将生成 UTF-8 编码的字节流。

`TextEncoder.prototype.encode(string)`
: 将 `string` 编码为包含 UTF-8 编码文本的 `Uint8Array`。

`TextEncoder.prototype.encodeInto(string, uint8Array)`
: 将 `string` 编码为 UTF-8,将结果放入目标 `Uint8Array`,并返回显示编码进度的字典对象。字典对象包含两个成员:
  <br/>
  `read`
  : 从源 `string` 转换为 UTF-8 的 UTF-16 代码单元数。
  <br/>
  `written`
  : 目标 `Uint8Array` 中修改的字节数。

<a id="njs-timers"></a>

## 定时器

- `clearTimeout()`
- `setTimeout()`

`clearTimeout(timeout)`
: 取消由 `setTimeout()` 创建的 `timeout` 对象。

`setTimeout(function, milliseconds[, argument1, argumentN])`
: 在指定的 `milliseconds` 毫秒数后调用 `function`。可以向指定的函数传递一个或多个可选 `arguments`。返回 `timeout` 对象。
  <br/>
  示例:
  <br/>
  ```javascript
  function handler(v)
  {
      // ...
  }
  <br/>
  t = setTimeout(handler, 12);
  <br/>
  // ...
  <br/>
  clearTimeout(t);
  ```

<a id="njs-global-functions"></a>

### 全局函数

- `atob()`
- `btoa()`

`atob(encodedData)`
: 解码使用 `Base64` 编码的数据字符串。`encodedData` 参数是包含 Base64 编码数据的二进制字符串。返回包含从 `encodedData` 解码的数据的字符串。
  <br/>
  类似的 `btoa()` 方法可用于编码和传输可能导致通信问题的数据,然后传输它并使用 `atob()` 方法再次解码数据。例如,您可以编码、传输和解码控制字符,如 ASCII 值 `0` 到 `31`。
  <br/>
  示例:
  <br/>
  ```javascript
  const encodedData = btoa("text to encode"); // 编码字符串
  const decodedData = atob(encodedData); // 解码字符串
  ```

`btoa(stringToEncode)`
: 从二进制字符串创建 Base64 编码的 ASCII 字符串。`stringToEncode` 参数是要编码的二进制字符串。返回包含 `stringToEncode` 的 Base64 表示的 ASCII 字符串。
  <br/>
  该方法可用于编码可能导致通信问题的数据,传输它,然后使用 `atob()` 方法再次解码数据。例如,您可以编码控制字符,如 ASCII 值 `0` 到 `31`。
  <br/>
  示例:
  <br/>
  ```javascript
  const encodedData = btoa("text to encode"); // 编码字符串
  const decodedData = atob(encodedData); // 解码字符串
  ```

<a id="njs-builtin-modules"></a>

## 内置模块

<a id="njs-buffer"></a>

### Buffer

`Buffer` 对象是处理二进制数据的 Node.js 兼容方式。由于文件内容过于庞大,本节仅限于 Buffer 方法的完整列表。

- `Buffer.alloc()`
- `Buffer.allocUnsafe()`
- `Buffer.byteLength()`
- `Buffer.compare()`
- `Buffer.concat()`
- `Buffer.from(array)`
- `Buffer.from(arrayBuffer)`
- `Buffer.from(buffer)`
- `Buffer.from(object)`
- `Buffer.from(string)`
- `Buffer.isBuffer()`
- `Buffer.isEncoding()`
- `buffer[]`
- `buf.buffer`
- `buf.byteOffset`
- `buf.compare()`
- `buf.copy()`
- `buf.equals()`
- `buf.fill()`
- `buf.includes()`
- `buf.indexOf()`
- `buf.lastIndexOf()`
- `buf.length`
- `buf.readIntBE()`
- `buf.readIntLE()`
- `buf.readUIntBE()`
- `buf.readUIntLE()`
- `buf.readDoubleBE()`
- `buf.readDoubleLE()`
- `buf.readFloatBE()`
- `buf.readFloatLE()`
- `buf.subarray()`
- `buf.slice()`
- `buf.swap16()`
- `buf.swap32()`
- `buf.swap64()`
- `buf.toJSON()`
- `buf.toString()`
- `buf.write()`
- `buf.writeIntBE()`
- `buf.writeIntLE()`
- `buf.writeUIntBE()`
- `buf.writeUIntLE()`
- `buf.writeDoubleBE()`
- `buf.writeDoubleLE()`
- `buf.writeFloatBE()`
- `buf.writeFloatLE()`

有关 Buffer 方法的详细文档,请参阅 [Node.js Buffer 文档](https://nodejs.org/api/buffer.html)。

<a id="njs-crypto"></a>

### Crypto

Crypto 模块提供加密功能支持。Crypto 模块对象使用 `import crypto from 'crypto'` 导入。

#### NOTE
自 0.7.0 起,扩展的 crypto API 可作为全局 [crypto](#njs-builtin-crypto) 对象使用。

- `crypto.createHash()`
- `crypto.createHmac()`

`crypto.createHash(algorithm)`
: 创建并返回一个 Hash 对象,可使用给定的 `algorithm` 生成哈希摘要。算法可以是 `md5`、`sha1` 和 `sha256`。

`crypto.createHmac(algorithm, secret key)`
: 创建并返回一个 HMAC 对象,使用给定的 `algorithm` 和 `secret key`。算法可以是 `md5`、`sha1` 和 `sha256`。

<a id="hash"></a>

#### Hash

- `hash.update()`
- `hash.digest()`

`hash.update(data)`
: 使用给定的 `data` 更新哈希内容。

`hash.digest([encoding])`
: 计算使用 `hash.update()` 传递的所有数据的摘要。编码可以是 `hex`、`base64` 和 `base64url`。如果未提供编码,则返回 Buffer 对象(0.4.4)。
  <br/>
  #### NOTE
  在 0.4.4 版本之前,返回的是字节字符串而不是 Buffer 对象。

`hash.copy()`
: 复制哈希的当前状态(自 0.7.12 起)。

示例:

```javascript
import crypto from 'crypto';

crypto.createHash('sha1').update('A').update('B').digest('base64url');
/* BtlFlCqiamG-GMPiK_GbvKjdK10 */
```

<a id="hmac"></a>

#### HMAC

- `hmac.update()`
- `hmac.digest()`

`hmac.update(data)`
: 使用给定的 `data` 更新 HMAC 内容。

`hmac.digest([encoding])`
: 计算使用 `hmac.update()` 传递的所有数据的 HMAC 摘要。编码可以是 `hex`、`base64` 和 `base64url`。如果未提供编码,则返回 Buffer 对象(0.4.4)。
  <br/>
  #### NOTE
  在 0.4.4 版本之前,返回的是字节字符串而不是 Buffer 对象。

<a id="njs-fs"></a>

### fs

`fs` 模块提供文件系统操作。模块对象使用 `import fs from 'fs'` 导入。

- `fs.accessSync()`
- `fs.appendFileSync()`
- `fs.mkdirSync()`
- `fs.readdirSync()`
- `fs.readFileSync()`
- `fs.realpathSync()`
- `fs.renameSync()`
- `fs.rmdirSync()`
- `fs.symlinkSync()`
- `fs.unlinkSync()`
- `fs.writeFileSync()`
- `fs.promises.readFile()`
- `fs.promises.appendFile()`
- `fs.promises.writeFile()`
- `fs.promises.readdir()`
- `fs.promises.mkdir()`
- `fs.promises.rmdir()`
- `fs.promises.rename()`
- `fs.promises.unlink()`
- `fs.promises.symlink()`
- `fs.promises.access()`
- `fs.promises.realpath()`

有关 fs 方法的详细文档,请参阅 [Node.js fs 文档](https://nodejs.org/api/fs.html)。

<a id="njs-querystring"></a>

### Query String

Query String 模块提供解析和格式化 URL 查询字符串的方法。模块对象使用 `import qs from 'querystring'` 导入。

- `querystring.decode()`
- `querystring.encode()`
- `querystring.escape()`
- `querystring.parse()`
- `querystring.stringify()`
- `querystring.unescape()`

`querystring.decode()`
: `querystring.parse()` 的别名。

`querystring.encode()`
: `querystring.stringify()` 的别名。

`querystring.escape(string)`
: 以针对 URL 查询字符串要求优化的方式对 `string` 执行 URL 百分号编码。该方法由 `querystring.stringify()` 使用,不应直接使用。

`querystring.parse(string[, separator[, equal[, options]]])`
: 将 `string` 解析为 URL 查询字符串并返回一个对象。可选的 `separator` 参数(默认值: `&`)指定用于分隔键值对的子字符串。可选的 `equal` 参数(默认值: `=`)指定用于分隔键和值的子字符串。可选的 `options` 参数是一个对象,可能包含以下属性:
  <br/>
  `decodeURIComponent`
  : 解码查询字符串中百分号编码字符时使用的函数,默认值: `querystring.unescape()`。
  <br/>
  `maxKeys`
  : 要解析的最大键数,默认值: `1000`。值 `0` 会移除对键计数的限制。
  <br/>
  示例:
  <br/>
  ```javascript
  >> qs.parse('foo=bar&abc=xyz&abc=123')
  {
      foo: 'bar',
      abc: ['xyz', '123']
  }
  ```

`querystring.stringify(object[, separator[, equal[, options]]])`
: 通过迭代 `object` 的自有属性从中生成 URL 查询字符串。可选的 `separator` 参数(默认值: `&`)指定用于分隔键值对的子字符串。可选的 `equal` 参数(默认值: `=`)指定用于分隔键和值的子字符串。可选的 `options` 参数是一个对象,可能包含以下属性:
  <br/>
  `encodeURIComponent`
  : 将查询字符串中的 URL 不安全字符转换为百分号编码时使用的函数,默认值: `querystring.escape()`。
  <br/>
  示例:
  <br/>
  ```javascript
  >> qs.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' })
  'foo=bar&baz=qux&baz=quux&corge='
  ```

`querystring.unescape(string)`
: 对 `string` 中的 URL 百分号编码字符执行解码。该方法由 `querystring.parse()` 使用,不应直接使用。

<a id="njs-xml"></a>

### XML

- `xml.parse()`
- `xml.c14n()`
- `xml.exclusiveC14n()`
- `xml.serialize()`
- `xml.serializeToString()`
- `XMLDoc`
- `XMLNode`
- `XMLAttr`

XML 模块允许处理 XML 文档(自 0.7.10 起)。XML 模块对象使用 `import xml from 'xml'` 导入。

示例:

```javascript
import xml from 'xml';

let data = `<note><to b="bar" a= "foo" >Tove</to><from>Jani</from></note>`;
let doc = xml.parse(data);

console.log(doc.note.to.$text) /* 'Tove' */
console.log(doc.note.to.$attr$b) /* 'bar' */
console.log(doc.note.$tags[1].$text) /* 'Jani' */

let dec = new TextDecoder();
let c14n = dec.decode(xml.exclusiveC14n(doc.note));
console.log(c14n) /* '<note><to a="foo" b="bar">Tove</to><from>Jani</from></note>' */

c14n = dec.decode(xml.exclusiveC14n(doc.note.to));
console.log(c14n) /* '<to a="foo" b="bar">Tove</to>' */

c14n = dec.decode(xml.exclusiveC14n(doc.note, doc.note.to /* excluding 'to' */));
console.log(c14n) /* '<note><from>Jani</from></note>' */
```

`parse(string | Buffer)`
: 解析字符串或 Buffer 中的 XML 文档;返回一个表示已解析 XML 文档的 `XMLDoc` 包装对象。

`c14n(root_node[, excluding_node])`
: 根据 [规范 XML 版本 1.1](https://www.w3.org/TR/xml-c14n) 规范化 `root_node` 及其子节点。`root_node` 可以是围绕 XML 结构的 `XMLNode` 或 `XMLDoc` 包装对象。返回包含规范化输出的 Buffer 对象。
  <br/>
  `excluding_node`
  : 允许从输出中省略文档的一部分。

`exclusiveC14n(root_node[, excluding_node[, withComments[,prefix_list]]])`
: 根据 [独占 XML 规范化版本 1.0](https://www.w3.org/TR/xml-exc-c14n/) 规范化 `root_node` 及其子节点。
  <br/>
  `root_node`
  : 围绕 XML 结构的 `XMLNode` 或 `XMLDoc` 包装对象。
  <br/>
  `excluding_node`
  : 允许从输出中省略与该节点及其子节点对应的文档部分。
  <br/>
  `withComments`
  : 布尔值,默认为 `false`。如果为 `true`,规范化对应于 [带注释的独占 XML 规范化版本 1.0](http://www.w3.org/2001/10/xml-exc-c14n#WithComments)。返回包含规范化输出的 Buffer 对象。
  <br/>
  `prefix_list`
  : 可选字符串,包含以空格分隔的命名空间前缀,这些命名空间也应包含在输出中。

`serialize()`
: 与 `xml.c14n()` 相同(自 0.7.11 起)。

`serializeToString()`
: 与 `xml.c14n()` 相同,但以 `string` 形式返回结果(自 0.7.11 起)。

`XMLDoc`
: 围绕 XML 结构的 XMLDoc 包装对象,文档的根节点。
  <br/>
  > `doc.$root`
  > : 按名称获取文档的根节点,如果不存在则为 undefined。
  <br/>
  > `doc.abc`
  > : 名为 `abc` 的第一个根标签,作为 `XMLNode` 包装对象。

`XMLNode`
: 围绕 XML 标签节点的 XMLNode 包装对象。
  <br/>
  > `node.abc`
  > : 与 `node.$tag$abc` 相同。
  <br/>
  > `node.$attr$abc`
  > : 节点的 `abc` 属性值,自 0.7.11 起可写。
  <br/>
  > `node.$attr$abc=xyz`
  > : 与 `node.setAttribute('abc', xyz)` 相同(自 0.7.11 起)。
  <br/>
  > `node.$attrs`
  > : 节点所有属性的 `XMLAttr` 包装对象。
  <br/>
  > `node.$name`
  > : 节点的名称。
  <br/>
  > `node.$ns`
  > : 节点的命名空间。
  <br/>
  > `node.$parent`
  > : 当前节点的父节点。
  <br/>
  > `node.$tag$abc`
  > : 节点名为 `abc` 的第一个子标签,自 0.7.11 起可写。
  <br/>
  > `node.$tags`
  > : 所有子标签的数组。
  <br/>
  > `node.$tags = [node1, node2, ...]`
  > : 与 `node.removeChildren()`; `node.addChild(node1)`; `node.addChild(node2)` 相同(自 0.7.11 起)。
  <br/>
  > `node.$tags$abc`
  > : 节点所有名为 `abc` 的子标签,自 0.7.11 起可写。
  <br/>
  > `node.$text`
  > : 节点的内容,自 0.7.11 起可写。
  <br/>
  > `node.$text = 'abc'`
  > : 与 `node.setText('abc')` 相同(自 0.7.11 起)。
  <br/>
  > `node.addChild(nd)`
  > : 将 XMLNode 作为子节点添加到该节点(自 0.7.11 起)。`nd` 在添加到节点之前会被递归复制。
  <br/>
  > `node.removeAllAttributes()`
  > : 删除节点的所有属性(自 0.7.11 起)。
  <br/>
  > `node.removeAttribute(attr_name)`
  > : 删除名为 `attr_name` 的属性(自 0.7.11 起)。
  <br/>
  > `node.removeChildren(tag_name)`
  > : 删除所有名为 `tag_name` 的子标签(自 0.7.11 起)。如果 `tag_name` 不存在,则删除所有子标签。
  <br/>
  > `node.removeText()`
  > : 删除节点的文本值(0.7.11)。
  <br/>
  > `node.setAttribute(attr_name, value)`
  > : 为 `attr_name` 设置值(自 0.7.11 起)。当值为 `null` 时,删除名为 `attr_name` 的属性。
  <br/>
  > `node.setText(value)`
  > : 为节点设置文本值(自 0.7.11 起)。当值为 `null` 时,删除节点的文本。

`XMLAttr`
: 围绕 XML 节点属性的 XMLAttrs 包装对象。
  <br/>
  > `attr.abc`
  > : `abc` 的属性值。

<a id="njs-zlib"></a>

### zlib

`zlib` 模块(0.5.2)使用 zlib 提供压缩和解压缩功能。模块对象使用 `import zlib from 'zlib'` 导入。

- `zlib.constants`
- `zlib.deflateRawSync()`
- `zlib.deflateSync()`
- `zlib.inflateRawSync()`
- `zlib.inflateSync()`

`zlib.constants`
: 返回 zlib 常量字典。

`zlib.deflateRawSync(data[, options])`
: 使用 Deflate 算法压缩 `data`,不包含 zlib 头。

`zlib.deflateSync(data[, options])`
: 使用 Deflate 算法压缩 `data`。

`zlib.inflateRawSync(data[, options])`
: 使用 Deflate 算法解压缩 `data`,不包含 zlib 头。

`zlib.inflateSync(data[, options])`
: 使用 Deflate 算法解压缩 `data`。

`options` 参数是一个对象,可能包含以下属性:

`level`
: 压缩级别(默认值: `zlib.constants.Z_DEFAULT_COMPRESSION`)。

`memLevel`
: 指定应为压缩状态分配多少内存(默认值: `zlib.constants.Z_DEFAULT_MEMLEVEL`)。

`strategy`
: 调整压缩算法(默认值: `zlib.constants.Z_DEFAULT_STRATEGY`)。

`windowBits`
: 设置窗口大小(默认值: `zlib.constants.Z_DEFAULT_WINDOWBITS`)。

`dictionary`
: 包含预定义压缩字典的 Buffer。

`info`
: 布尔值,如果为 `true`,返回包含 buffer 和 engine 的对象。

`chunkSize`
: 压缩的块大小(默认值: `zlib.constants.Z_DEFAULT_CHUNK`)。

示例:

```javascript
import zlib from 'zlib';

const deflated = zlib.deflateSync('Hello World!');
const inflated = zlib.inflateSync(deflated);

console.log(inflated.toString()); // 'Hello World!'
```


# https://cn.angie.software/angie/docs/installation/external-modules/njs.md

<!-- review: finished -->

<a id="external-njs"></a>

# NJS

该模块将 JavaScript 编程语言集成到 Angie 的事件处理模型中,允许使用 JavaScript 脚本扩展服务器功能。它由两个模块组成：

- [HTTP JS](https://cn.angie.software//angie/docs/installation/external-modules/http_js.md#http-js) — 用于处理 HTTP 流量；
- [Stream JS](https://cn.angie.software//angie/docs/installation/external-modules/stream_js.md#stream-js) — 用于处理 TCP/UDP 流量。

<a id="installation-19"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-njs` 或 `angie-module-njs-light`；
- Angie PRO：`angie-pro-module-njs` 或 `angie-pro-module-njs-light`。

<a id="features-1"></a>

## 功能特性

该模块使用 njs（JavaScript 的一个子集）编写的脚本扩展服务器功能，支持实现自定义服务器端逻辑等更多功能：

- 在请求到达代理服务器之前进行复杂的访问控制和安全检查。
- 响应头操作。
- 编写灵活的异步处理程序和内容过滤器。

还提供了一个独立的命令行工具，可以独立于服务器使用，用于开发和调试 njs 脚本。

<a id="loading-the-module-19"></a>

## 加载模块

在 `main{}` 上下文中加载模块：

```nginx
load_module modules/ngx_http_js_module.so;    # 用于 HTTP
load_module modules/ngx_stream_js_module.so;  # 用于 Stream
```

<a id="usage"></a>

## 使用方法

详细文档可在各个模块的章节中找到：

- [HTTP JS](https://cn.angie.software//angie/docs/installation/external-modules/http_js.md#http-js)
- [Stream JS](https://cn.angie.software//angie/docs/installation/external-modules/stream_js.md#stream-js)

<a id="security"></a>

## 安全性

该模块不执行动态代码，特别是从网络接收的代码。使用 njs 执行此类代码的唯一方法是在服务器配置中配置 `js_import` 指令。JavaScript 代码在服务器启动时加载一次。

在该模块的威胁模型中，JavaScript 代码被视为可信来源，就像配置文件和站点证书一样。实际上，这意味着以下几点：

- 由于修改 JavaScript 代码导致的内存内容泄露和其他安全问题不被视为安全问题，而是作为常规错误处理；
- 必须采取措施保护模块使用的 JavaScript 代码；
- 如果配置文件中没有 `js_import` 指令，服务器将受到保护，免受与 JavaScript 相关的漏洞影响。

<a id="command-line-utility"></a>

## 命令行工具

**njs** 命令行工具有助于开发和调试 njs 脚本，与模块一起安装。与模块作为 Angie 的一部分运行时不同，使用该工具时 Angie 对象（`HTTP` 和 `Stream`）不可用。

使用该工具的示例：

```console
$ echo "2**3" | njs -q
8

$ njs

>> globalThis
global {
 njs: njs {
  version: '0.3.9'
 },
 global: [Circular],
 process: process {
  argv: [
   '/usr/bin/njs'
  ],
...
```

<a id="preloaded-objects"></a>

## 预加载对象

对于每个传入请求，该模块会创建一个单独的虚拟机。这提供了许多好处，例如可预测的内存消耗和请求隔离。但是，由于所有请求都是隔离的，如果请求处理程序需要访问任何数据，它必须自己读取。这是低效的，特别是当数据量很大时。

为了解决这个问题，引入了预加载共享对象机制。这些对象被创建为不可变的，并且没有原型链：它们的值不能被更改，属性不能被添加或删除。

以下是在 njs 中使用预加载对象的几个示例：

- 按名称访问属性：
  ```javascript
  preloaded_object.prop_name
  preloaded_object[prop_name]
  ```
- 枚举属性：
  ```javascript
  for (i in preloaded_object_name) {
        // ...
  }
  ```
- 使用 `call()` 应用非修改性内置方法：
  ```javascript
  Array.prototype.filter.call(preloaded_object_name, ...)
  ```

<a id="api-reference"></a>

## API 参考

有关所有 njs 对象、方法和属性的完整参考，请参阅：

- [NJS API 参考](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-reference)

<a id="additional-information-20"></a>

## 其他信息

- 官方网站：[https://nginx.org/en/docs/njs/](https://nginx.org/en/docs/njs/)
- 使用示例：[https://github.com/nginx/njs-examples/](https://github.com/nginx/njs-examples/)


# https://cn.angie.software/news/articles/novoe-v-angie-dlya-luchshego-monitoringa.md

# Angie新增功能助力更好的Web服务器监控

*17.11.2023*

2023年9月，我们通过添加Angie Console Light为Angie web服务器引入了新的监控组织方式。

2023年9月，我们 [推出](https://cn.angie.software/news/articles/vstrechaite-console-light/) 了Angie web服务器的新监控组织方式。具体而言，我们添加了Angie Console Light —— 一个用于实时活动监控的轻量级可视化控制台。它可以显示服务器的关键负载和性能指标。

我们现在已在Angie Console Light的可视化界面中添加了服务器上已加载配置文件列表的链接。每个文件的内容都可以在带有语法高亮的紧凑格式中查看（About — Configs小部件）。

该控制台的一个显著特点是能够实时显示特定web服务器实例的指标。页面更新频率可由用户自行设置。

Angie Console Light的演示版本可在此处访问：[https://console.angie.software/](https://console.angie.software/)。有关标签页和所收集指标的详细说明，请参阅文档中的 [这部分内容](https://cn.angie.software/angie/docs/configuration/monitoring/)。


# https://cn.angie.software/angie/docs/configuration/oidc.md

<!-- review: finished -->

<a id="oidc-config"></a>

# OIDC 身份验证设置

本指南说明如何使用 Google 作为身份提供商
和 Angie Web 服务器通过 Lua 脚本设置 OpenID Connect (OIDC) 身份验证。

该实现使用 OAuth2/OIDC 身份验证保护内部端点,
并演示了一种基于电子邮件域限制访问的方法。
这只是一种示例方法;您可以按照自己喜欢的方式实现访问控制,
例如维护特定用户的允许列表、检查提供商响应中的域成员资格
或组属性,或使用来自您私有 IAM 系统的自定义声明。

<a id="architecture"></a>

## 架构

此处建议的 OIDC 设置包括:

- Angie - 支持 Lua 模块以进行 OIDC 处理
- [lua-resty-openidc](https://github.com/zmartzone/lua-resty-openidc) - 用于 OIDC 身份验证的 OpenResty Lua 库
- Google OAuth2 - 用于用户身份验证的身份提供商
- Docker Compose - 在本示例中仅用于快速启动;
  在生产环境中使用您喜欢的任何部署方法

<a id="prerequisites"></a>

## 前提条件

在配置 OIDC 身份验证之前,请确保您具备:

1. 支持 [Lua 模块](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua) 的 Angie Web 服务器
2. Docker 和 Docker Compose(用于部署)
3. Google Cloud Console 项目
4. 来自 Google 的 OAuth2 凭据

<a id="google-oauth2-setup"></a>

## Google OAuth2 设置

要将 Google 配置为您的 OIDC 提供商:

1. 导航到 [Google Cloud Console](https://console.cloud.google.com/apis/credentials)
2. 创建新项目或选择现有项目
3. 为您的项目配置 OAuth 同意屏幕(外部或内部)并发布它,以便用户可以进行身份验证
4. 创建 OAuth2 凭据:
   - 应用类型: Web 应用程序
   - 已授权的重定向 URI: `http://localhost/auth/callback`
5. 保存您的 `client_id` 和 `client_secret` 以供配置使用

#### NOTE
标准 Google Identity Services 已经支持 OIDC;不需要旧版 Google+ API。
仅当您的应用程序需要其数据时才启用其他 Google API。

<a id="configuration-setup"></a>

## 配置设置

让我们从 OIDC 设置所需的配置文件开始。

<a id="docker-compose-configuration"></a>

### Docker Compose 配置

Docker 部署使用以下配置文件:

```yaml
services:
  angie:
    image: docker.angie.software/angie:templated
    environment:
      ANGIE_LOAD_MODULES: "lua"
    ports:
      - 80:80
    volumes:
      - ./files/etc/angie/http.d:/etc/angie/http.d
```

此配置执行以下操作:

- 使用支持 Lua 模块的 [模板化 Angie 镜像](https://cn.angie.software//angie/docs/installation/docker.md#docker-templated)
- 加载 [Lua 模块](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua) 以实现 OIDC 功能
- 映射端口 80 以进行 HTTP 访问
- 从本地目录挂载配置文件

对于即插即用的演示,
下载 [`OIDC 快速启动包`](https://cn.angie.software//angie/docs/configuration/oidc-sample-config.zip),
在 `files/etc/angie/http.d/oidc.lua` 中设置您的 `client_id` 和 `client_secret`,
一切都将开箱即用。

<a id="oidc-authentication-script"></a>

### OIDC 身份验证脚本

创建一个 OIDC 身份验证脚本,
使用 `lua-resty-openidc` 库处理身份验证逻辑:

```lua
access_by_lua_block {
    local res, err = require("resty.openidc").authenticate({
        redirect_uri = "http://localhost/auth/callback",
        discovery = "https://accounts.google.com/.well-known/openid-configuration",
        logout_path = "/auth/logout",
        redirect_after_logout_uri = "/auth/logged-out",
        revoke_tokens_on_logout = true,
        client_id = "YOUR_CLIENT_ID",
        client_secret = "YOUR_CLIENT_SECRET"
    })
}
```

配置参数:

- `redirect_uri`: 成功身份验证后的回调 URL
- `discovery`: Google 的 OIDC 发现端点
- `logout_path`: 用户注销路径
- `redirect_after_logout_uri`: 注销后的重定向目标
- `revoke_tokens_on_logout`: 注销时撤销令牌以确保安全
- `client_id` 和 `client_secret`: 您的 Google OAuth2 凭据

<a id="angie-configuration"></a>

### Angie 配置

使用必要的 [location](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#location) 块配置 Angie
以进行 OIDC 身份验证。

<a id="protected-resources"></a>

#### 受保护的资源

要使用 OIDC 身份验证保护资源:

```nginx
location /internal/ {
    include /etc/angie/http.d/oidc.lua;
    proxy_pass http://127.0.0.1/status/;
}
```

此配置执行以下操作:

- 使用 OIDC 身份验证保护 `/internal/` 路径
- 将经过身份验证的请求代理到 `/status/` 的 [内部 API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#http-api)

<a id="authentication-endpoints"></a>

#### 身份验证端点

配置 OAuth2 流程端点:

```nginx
location /auth/callback {
    include /etc/angie/http.d/oidc.lua;
}

location /auth/logout {
    include /etc/angie/http.d/oidc.lua;
}

location /auth/logged-out {
    default_type text/plain;
    return 200 "You have been logged out. Bye!";
}
```

端点功能:

- `/auth/callback`: 处理来自 Google 的 OAuth2 回调
- `/auth/logout`: 启动用户注销
- `/auth/logged-out`: 成功注销后的着陆页

<a id="internal-api-access"></a>

#### 内部 API 访问

配置对内部 API 的受限访问:

```nginx
location /status/ {
    api     /status/;
    allow   127.0.0.1;
    deny    all;
}
```

这提供了:

- 访问 Angie 的 [状态 API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#http-api)
- 仅限本地主机访问 (127.0.0.1)
- 通过 `/internal/` 访问时的 OIDC 保护

<a id="deployment-steps"></a>

## 部署步骤

按照以下步骤部署 OIDC 身份验证:

<a id="configuration-update"></a>

### 配置更新

1. 在您的 OIDC Lua 脚本中更新 OAuth2 凭据:

   替换 `oidc.lua` 中的占位符值:
   - 将 `client_id` 替换为您的 Google OAuth2 客户端 ID
   - 将 `client_secret` 替换为您的 Google OAuth2 客户端密钥

<a id="service-startup"></a>

### 服务启动

1. 启动 Docker 服务:
   ```console
   $ docker-compose up -d
   ```
2. 验证部署:
   - 导航到 `http://localhost/internal/`
   - 您应该被重定向到 Google 进行身份验证
   - 成功登录后,您将访问受保护的内容

<a id="security-configuration"></a>

## 安全配置

<a id="email-domain-restriction"></a>

### 电子邮件域限制

实现域验证以按电子邮件域限制访问:

```lua
if not string.match(res.user.email, "gmail.com$") then
    ngx.exit(ngx.HTTP_FORBIDDEN)
end
```

对于生产环境,请考虑以下事项:

- 将 `gmail.com` 替换为您组织的域
- 实现允许的电子邮件地址白名单
- 添加基于角色的访问控制

<a id="token-management"></a>

### 令牌管理

OIDC 实现包括安全功能:

- 注销时自动撤销令牌 (`revoke_tokens_on_logout = true`)
- lua-resty-openidc 库安全地管理会话
- 所有身份验证流程都遵循 OAuth2/OIDC 安全最佳实践

#### WARNING
对于生产部署:

- 始终对 OAuth2 回调使用 HTTPS
- 安全地存储客户端密钥,切勿存储在版本控制中
- 实施适当的会话超时和续订策略
- 监控身份验证日志以发现安全事件

<a id="authentication-flow"></a>

## 身份验证流程

OIDC 身份验证流程遵循标准 OAuth2/OIDC 程序:

1. 用户访问受保护的 URL(例如 `http://localhost/internal/`)
2. 如果未经身份验证,用户将被重定向到 Google OAuth2
3. 用户使用 Google 凭据进行身份验证
4. Google 使用授权码重定向回 `/auth/callback`
5. 服务器将代码交换为访问令牌和 ID 令牌
6. 验证用户信息(包括电子邮件域检查)
7. 授予用户访问受保护资源的权限

注销过程确保安全的会话终止:

1. 用户导航到 `http://localhost/auth/logout`
2. 在 Google 的 OAuth2 端点撤销令牌
3. 清除本地会话数据
4. 用户被重定向到 `/auth/logged-out`

<a id="advanced-configuration"></a>

## 高级配置

要限制对特定组织域的访问:

```lua
if not string.match(res.user.email, "yourcompany.com$") then
    ngx.exit(ngx.HTTP_FORBIDDEN)
end
```

对于具有多个允许域的组织:

```lua
local allowed_domains = {"company1.com", "company2.com", "gmail.com"}
local email_valid = false

for _, domain in ipairs(allowed_domains) do
    if string.match(res.user.email, domain .. "$") then
        email_valid = true
        break
    end
end

if not email_valid then
    ngx.exit(ngx.HTTP_FORBIDDEN)
end
```

<a id="user-information-access"></a>

### 用户信息访问

从 OIDC 提供商访问其他用户声明:

```lua
-- 从 ID 令牌访问用户信息
local user_name = res.user.name
local user_picture = res.user.picture
local user_locale = res.user.locale
local user_email = res.user.email
```

这些值可用于日志记录、个性化或其他访问控制决策。


# https://cn.angie.software/angie/docs/installation/external-modules/opentracing.md

<!-- review: finished -->

<a id="external-opentracing"></a>

# Opentracing

Opentracing 模块为 Angie 添加了分布式 OpenTracing 请求追踪功能;它包含用于将数据导出到 Zipkin 和 DataDog 的插件。

<a id="installation-20"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-opentracing`
- Angie PRO:`angie-pro-module-opentracing`

<a id="loading-the-module-20"></a>

## 加载模块

要使用该模块,必须在 `main{}` 上下文中加载它:

```nginx
load_module modules/ngx_http_opentracing_module.so;
```

<a id="configuration-example-94"></a>

## 配置示例

```nginx
http {
    opentracing on;

    opentracing_load_tracer /usr/local/lib/libdd_opentracing_plugin.so /etc/datadog-config.json;

    upstream backend {
        server app-service:9001;
    }

    server {
        error_log /var/log/angie/debug.log debug;
        listen 8080;
        server_name localhost;

        location = / {
            opentracing_trace_locations off;
            proxy_pass http://backend;
            opentracing_propagate_context;
            opentracing_tag "resource.name" "/";
        }
    }
}
```

<a id="additional-information-21"></a>

## 附加信息

各种配置选项可在以下位置找到:
[https://github.com/opentracing-contrib/nginx-opentracing/tree/master/example](https://github.com/opentracing-contrib/nginx-opentracing/tree/master/example)

详细文档和源代码可在以下位置获取:
[https://github.com/opentracing-contrib/nginx-opentracing](https://github.com/opentracing-contrib/nginx-opentracing)


# https://cn.angie.software/news/articles/opyt-raboti-angie-s-kitaem.md

# Angie与中国的经验

*04.09.2023*

当俄罗斯正在积极制定"本土"开源项目发展计划时，中国也在积极发展其自己的开源项目。

![Alternative text](../../_images/news/opyt-raboti-angie-s-kitaem.jpeg)![Alternative text](../../_images/news/opyt-raboti-angie-s-kitaem.jpeg)

我们的CEO在《福布斯》杂志上分享了Angie与中国的合作经验。请阅读这篇文章，因为这个话题在开源领域意外地再次引起关注。当俄罗斯正在积极制定"本土"开源项目发展计划时，中国也在积极发展其自己的开源项目。

[https://www.forbes.ru/tekhnologii/495635-zakrytye-zony-otkrytogo-koda-kak-kitaj-i-rossia-razvivaut-open-source](https://www.forbes.ru/tekhnologii/495635-zakrytye-zony-otkrytogo-koda-kak-kitaj-i-rossia-razvivaut-open-source)


# https://cn.angie.software/angie/docs/oss_changes.md

<!-- review: finished -->

<a id="oss-changes"></a>

# Angie 版本历史

## 2026

<a id="angie-1-11-6"></a>

### Angie 1.11.6

发布日期： 25.05.2026.

<a id="security-1-11-6"></a>

#### 安全性

- 当使用 [rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 指令时，若其正则表达式包含嵌套的 PCRE 捕获，
  且替换字符串引用了多个此类捕获，攻击者在超出攻击者控制的条件下，
  可能导致工作进程崩溃，并且在没有地址空间布局随机化的系统上，
  可能执行任意代码
  ([CVE-2026-9256](https://nvd.nist.gov/vuln/detail/CVE-2026-9256))；
  此修复从 nginx 1.31.1 移植而来。

<a id="packages-1-11-6"></a>

#### 软件包

- 已更新:
  - [angie-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，至版本 0.13.1
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.9
  - [angie-module-testcookie](https://cn.angie.software//angie/docs/installation/external-modules/testcookie.md#external-testcookie)，至版本 7d263d4
  - [angie-module-vod](https://cn.angie.software//angie/docs/installation/external-modules/vod.md#external-vod)，至版本 v1.7.2

<a id="angie-1-11-5"></a>

### Angie 1.11.5

发布日期：15.05.2026.

<a id="security-1-11-5"></a>

#### 安全性

- 当 [rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 指令使用未命名的捕获组（例如 `$1`、`$2`）
  且替换字符串包含 `?` 时，如果其后跟随 [rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5)、[if](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#if) 或 [set](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#set)
  指令，攻击者在超出攻击者控制的条件下，可能导致工作进程崩溃，
  并且在没有地址空间布局随机化的系统上，可能执行任意代码
  ([CVE-2026-42945](https://nvd.nist.gov/vuln/detail/CVE-2026-42945))；
  此修复从 nginx 1.31.0 移植而来。
- 使用 [ssl_ocsp](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-ocsp) 指令时，在处理 DNS
  服务器响应过程中可能发生对先前已释放内存的访问，
  允许攻击者破坏工作进程内存或导致其崩溃
  ([CVE-2026-40701](https://nvd.nist.gov/vuln/detail/CVE-2026-40701))；
  此修复从 nginx 1.31.0 移植而来。
- 使用 HTTP/3 时，攻击者可能伪造 IP
  地址，从而在某些配置中绕过限制或授权
  ([CVE-2026-40460](https://nvd.nist.gov/vuln/detail/CVE-2026-40460))；
  此修复从 nginx 1.31.0 移植而来。
- 当配置了 [scgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-pass) 或 [uwsgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-pass) 时，
  处于中间人（MITM）位置并控制代理服务器响应的攻击者，
  可能导致过度的内存分配或数据越界读取，
  从而向客户端泄露工作进程的内存内容或导致进程崩溃
  ([CVE-2026-42946](https://nvd.nist.gov/vuln/detail/CVE-2026-42946))；
  此修复从 nginx 1.31.0 移植而来。
- 当通过 [charset_map](https://cn.angie.software//angie/docs/configuration/modules/http/http_charset.md#charset-map) 指令使用 UTF-8 解码处理特制响应时，
  工作进程中可能发生越界读取，允许攻击者在超出攻击者控制的条件下，
  向客户端发送有限的工作进程内存内容或导致进程崩溃
  ([CVE-2026-42934](https://nvd.nist.gov/vuln/detail/CVE-2026-42934))；
  此修复从 nginx 1.31.0 移植而来。

<a id="packages-1-11-5"></a>

#### 软件包

- 已更新：
  - [angie-module-auth-totp](https://cn.angie.software//angie/docs/installation/external-modules/auth-totp.md#external-auth-totp)，至版本 1.2.0
  - [angie-module-cache-purge](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge)，至版本 3.0.2
  - [angie-module-keyval](https://cn.angie.software//angie/docs/installation/external-modules/keyval.md#external-keyval)，至版本 0.4.0
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.8
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 v0.46.0
- 已将 [angie-module-dav-ext](https://cn.angie.software//angie/docs/installation/external-modules/dav-ext.md#external-dav-ext) 的源更换为
  [mid1221213/nginx-dav-ext-module](https://github.com/mid1221213/nginx-dav-ext-module) v4.0.1。
- 已将 [angie-module-vod](https://cn.angie.software//angie/docs/installation/external-modules/vod.md#external-vod) 的源更换为
  [dio-az/nginx-vod-module](https://github.com/dio-az/nginx-vod-module) v1.7.1。

<a id="angie-1-11-4"></a>

### Angie 1.11.4

发布日期：25.03.2026.

<a id="security-1-11-4"></a>

#### 安全性

- [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中与客户端的 TLS
  握手可能在 OCSP 拒绝客户端证书的情况下仍然成功
  ([CVE-2026-28755](https://nvd.nist.gov/vuln/detail/CVE-2026-28755))；
  此修复从 nginx 1.29.7 移植而来。
- 在 DAV 模块中，在带有 [alias](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#alias) 指令的 `location` 中处理 COPY 或 MOVE
  请求时可能发生缓冲区溢出，允许攻击者将源路径或目标路径修改到文档根目录之外
  ([CVE-2026-27654](https://nvd.nist.gov/vuln/detail/CVE-2026-27654))；
  此修复从 nginx 1.29.7 移植而来。
- 在 32 位平台上，MP4 模块处理特制文件可能导致工作进程崩溃，
  或可能产生其他潜在影响
  ([CVE-2026-27784](https://nvd.nist.gov/vuln/detail/CVE-2026-27784))；
  此修复从 nginx 1.29.7 移植而来。
- MP4 模块处理特制文件可能导致工作进程崩溃，
  或可能产生其他潜在影响
  ([CVE-2026-32647](https://nvd.nist.gov/vuln/detail/CVE-2026-32647))；
  此修复从 nginx 1.29.7 移植而来。
- 如果在 [Mail](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-mail) 代理模块中使用了 CRAM-MD5 或 APOP 认证方法，
  并且启用了认证重试，则工作进程可能崩溃
  ([CVE-2026-27651](https://nvd.nist.gov/vuln/detail/CVE-2026-27651))；
  此修复从 nginx 1.29.7 移植而来。
- 使用 [Mail](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-mail) 代理模块时，攻击者可以利用 PTR DNS
  记录向认证 HTTP 请求以及向代理服务器的 SMTP 连接中的 XCLIENT 命令注入数据
  ([CVE-2026-28753](https://nvd.nist.gov/vuln/detail/CVE-2026-28753))；
  此修复从 nginx 1.29.7 移植而来。

<a id="bugfixes-1-11-4"></a>

#### 错误修复

- 连接到代理服务器之前的罕见系统错误可能影响 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-http) 和
  [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中对端状态的正确性；在
  [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中还可能导致工作进程崩溃；
  该问题出现在 1.9.1 中。
- 在 [proxy_http_version](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http-version) `3` 和 [proxy_set_header](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-set-header)
  `Host ..` 指令从 `http` 块继承的配置中，发出的 HTTP/3
  请求可能不包含 `Host` 头。

<a id="packages-1-11-4"></a>

#### 软件包

- 已更新：
  - [angie-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，至版本 0.11.0
  - [angie-module-cache-purge](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge)，至版本 2.5.6
  - [angie-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)，至版本 v0.15
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.6
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 v0.43.0

<a id="angie-1-11-3"></a>

### Angie 1.11.3

发布日期：06.02.2026.

<a id="security-1-11-3"></a>

#### 安全性

- 中间人（MITM）攻击者在使用 TLS 的代理服务器之前，在超出攻击者控制的条件下，
  可以在 TLS 握手开始之前向响应中注入明文数据
  ([CVE-2026-1642](https://nvd.nist.gov/vuln/detail/CVE-2026-1642))；
  此修复从 nginx 1.29.5 移植而来。

<a id="packages-1-11-3"></a>

#### 软件包

- 已更新：
  - [angie-module-jwt](https://cn.angie.software//angie/docs/installation/external-modules/jwt.md#external-jwt)，至版本 3.4.4

<a id="angie-1-11-2"></a>

### Angie 1.11.2

发布日期:2026 年 1 月 15 日。

<a id="bugfixes-1-11-2"></a>

#### 错误修复

- 如果禁用了 BPF,HTTP/3 请求可能失败并显示错误
  `[alert] sendmsg() failed (90: Message too large) while sending frames`;
  该错误出现在 1.11.0 版本中。
- 当在启用 BPF 的情况下监听 IPv6 通配符地址时,HTTP/3 请求不被接受;
  该错误出现在 1.11.0 版本中。
- 当在 [docker_endpoint](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#docker-endpoint) 指令中指定域名时,
  与 Docker API 的连接和上游服务器组的更新不会发生。

<a id="packages-1-11-2"></a>

#### 软件包

- 更新:
  - [angie-module-cache-purge](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge),至版本 2.5.5

2026 年 2 月 2 日

- 更新:
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs),至版本 0.9.5

## 2025

<a id="angie-1-11-1"></a>

### Angie 1.11.1

发布日期:2025 年 12 月 30 日。

<a id="changes-1-11-1"></a>

#### 变更

- 现在,如果在 [acme_http_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-http-port) 指令中仅指定端口而不指定 IP(默认值),
  并且存在监听该端口的 `server` 块,则 ACME 中该端口的 HTTP 质询处理
  仅在这些块的 [listen](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#listen) 指令中配置的 IP 地址上工作;不会尝试监听所有 IP 地址,
  如之前那样;这使配置更加灵活,并防止了从以前版本更新时的问题,
  即配置中仅有监听端口 `80` 和特定 IP 地址的 `server` 块。

<a id="bugfixes-1-11-1"></a>

#### 错误修复

- HTTP/2 请求未计入服务器区域统计;
  该错误出现在 1.11.0 版本中。
- 当 ACME 客户端在配置中被禁用且没有先前获得的证书时,
  对该客户端的统计 API 请求可能导致工作进程崩溃。
- 如果在 `server` 块内的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令中使用 `$http_host`
  或 `$cookie_*` 变量作为键,HTTP/3 请求可能不会计入此状态区域。

<a id="packages-1-11-1"></a>

#### 软件包

- 更新:
  - [angie-module-vts](https://cn.angie.software//angie/docs/installation/external-modules/vts.md#external-vts),至版本 v0.2.5

<a id="angie-1-11-0"></a>

### Angie 1.11.0

发布日期:2025 年 12 月 24 日。

<a id="changes-1-11"></a>

#### 变更

- HTTP/3 请求中的 `$http_host` 变量现在从 `:authority`
  伪标头的值初始化(如果未传递 `Host` 标头),这对客户端来说是正常的;
  以前,与早期协议版本的差异可能导致使用 `$http_host` 的配置出现问题。
- 如果 `upstream` 组中的所有 HTTP 服务器都不可用或返回错误,
  现在在接收到根据 [proxy_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-next-upstream)
  指令(及类似指令)被视为错误的状态时,始终返回自己的错误页面,
  而不是最后一个服务器的响应;这确保了所有情况下的一致行为。
- `fastcgi.conf`、`fastcgi_params`、`uwsgi_params`
  和 `scgi_params` 配置文件中的 `REQUEST_METHOD` 参数现在通过
  `$upstream_request_method` 变量设置,该变量在配置缓存时对 `HEAD`
  请求取值 `GET`;这防止了以前 `HEAD` 请求可能导致存储空响应的问题,
  该响应随后会为 `GET` 请求提供服务,因为在常见配置中请求方法不是缓存键的一部分。
- ACME 服务器的最大响应大小现在由 [acme_max_response_size](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-max-response-size)
  指令限制,而不是 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的 `max_cert_size=` 参数;
  默认值对大多数情况足够,但如果证书更新以 `[error] too big subrequest response while sending
  to client` 错误消息结束,则应增加其值。
- HTTP 模块中 [variables_hash_max_size](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#variables-hash-max-size) 指令的默认值
  增加到 `2048`,以减少由于近年来添加的新变量导致的关于次优哈希构建的警告的可能性:
  `[warn] could not build optimal variables_hash, you should increase either
  variables_hash_max_size: 1024 or variables_hash_bucket_size: 64;
  ignoring variables_hash_bucket_size`。

<a id="features-1-11"></a>

#### 功能特性

- 新的 [Metric](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#http-metric) 模块,支持任意的实时 HTTP 指标收集,
  具有完全可配置的聚合方法(计数器、直方图、移动平均等);它允许在任何阶段跟踪任何请求处理数据,
  按自定义键分组,并通过 `/status/http/metric_zones/` API 部分公开指标
  (包括 Prometheus 支持),为整个 HTTP 流量提供强大的内置分析工具。
- 支持 ACME 的 ALPN 验证,通过在 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的
  `challenge` 参数中指定 `alpn` 启用;
  允许在仅保持 HTTPS 端口开放的情况下请求多域证书。
- 统计 API 的 `/status/http/acme_clients/` 部分中的 ACME 客户端
  和证书请求过程的信息(支持 Prometheus)。
- 在 HTTP 和 stream SSL 模块中添加了对加密客户端 Hello(ECH)的支持;
  新的 [ssl_encrypted_hello_key](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-encrypted-hello-key) 指令指定包含私钥的文件;
  `$ssl_encrypted_hello` 变量包含有关 ECH 使用的信息。
  感谢 Maxim Dounin (freenginx)。
- 使用 [image_filter](https://cn.angie.software//angie/docs/configuration/modules/http/http_image_filter.md#id3) 指令的 `convert` 参数转换图像格式。
- Image Filter 模块中支持 AVIF 和 HEIC 格式。
- stream 模块中支持与上游服务器连接的 PROXY protocol V2,
  以及使用 [proxy_protocol_tlv](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#s-proxy-protocol-tlv) 指令设置任意 TLV 值的能力,
  该指令允许包含变量的字符串。
- `$upstream_request_method` 变量,包含上游请求方法,
  当启用缓存或设置 [proxy_method](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-method) 时,该方法可能与客户端请求方法不同;
  这有助于避免常见的配置问题,即缓存的空 `HEAD` 响应为 `GET` 请求提供服务,
  以及避免分别缓存 `HEAD` 和 `GET` 响应。
- 消除了为 ACME HTTP 质询定义单独的带有 `listen 80` 指令的 `server` 块的需要;
  如有必要,可以使用 [acme_http_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-http-port) 指令自定义监听端口。
- 导出 Prometheus 指标时计算列表和对象中项目数量的能力;
  以尾部斜杠结尾的路径现在返回相应 API 集合中的项目计数。
- `$sent_body` 变量,包含子请求或客户端模块外部请求的响应正文。
- 邮件代理模块中支持 XOAUTH2 和 OAUTHBEARER 认证机制。
  感谢 Rob Mueller 和 Maxim Dounin (freenginx)。
- [sticky](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky) 指令的 `route` 参数现在可以包含任意数量变量的任意字符串。
- 在 ACME 模块中,现在自动计算续订证书的近似大小,
  消除了在为大量域颁发证书时增加 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的
  `max_cert_size` 参数的需要;
  该参数保留用于仍需要手动配置的情况。
- `$upstream_cache_key` 变量,包含正在使用的缓存键。
  感谢 Kirill A. Korinsky 和 Maxim Dounin (freenginx)。
- 支持使用 AWS-LC SSL 库构建。
  感谢 Piotr Sikora (piotr at aviatrix.com)。
- 新的 Makefile 目标 `test` 执行测试套件。
- nginx 1.29.3 的所有功能,但不包括 `add_header_inherit` 和
  `add_trailer_inherit` 指令,由于其设计不佳而被省略。

<a id="bugfixes-1-11"></a>

#### 错误修复

- 重新加载和二进制升级过程现在可以正确处理 HTTP/3 连接;
  使用 BPF 模块将连接正确路由到所有现有进程。
- 如果 `upstream` 组中的所有服务器都不可用或返回错误,
  则从最后一个服务器接收错误响应可能被视为成功,
  尽管有 [proxy_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-next-upstream) 指令设置。
- 如果 [try_files](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#try-files) 指令中的路径短于相关 `location` 块中的前缀,
  则使用带有 URI 的 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass) 可能导致工作进程崩溃;
  该修复从 nginx 1.29.4 移植。
- 如果 ACME 客户端未通过任何 `acme` 指令在 `stream` 块中引用,
  在该块中使用任何相应的 `$acme_cert_*` 变量会导致配置被拒绝,
  并显示 `unknown variable` 错误;该错误出现在 1.10.3 版本中。
- 如果配置了将缓存索引保存到文件,则在操作期间的配置测试可能以错误结束:
  `[alert] mmap() failed (17: File exists)` 和 `[alert] munmap()
  failed (22: Invalid argument)`。
- 如果触发了 `proxy_cache_convert_head on`,则忽略 [proxy_method](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-method) 指令。
- `upstream` 块内 `server` 指令的 `fail_timeout` 选项指定的超时持续时间
  实际上长一秒。
- Angie 无法在 `NetBSD 10.0` 上构建。
  感谢 Maxim Dounin (freenginx)。
- 加载为 Angie PRO 构建的模块可能由于 ABI 不兼容而导致问题和崩溃;
  现在此类不正确的配置被禁止,并显示相关错误消息。

<a id="packages-1-11"></a>

#### 软件包

- 更新:
  - [angie-module-echo](https://cn.angie.software//angie/docs/installation/external-modules/echo.md#external-echo),至版本 v0.64

<a id="angie-1-10-3"></a>

### Angie 1.10.3

发布日期:2025 年 11 月 13 日。

<a id="security-1-1-1-1-1-1"></a>

#### 安全性

- 在 SMTP 模块中使用 `none` 认证方法时,处理特制的登录名/密码可能导致
  工作进程内存泄露到认证服务器
  ([CVE-2025-53859](https://nvd.nist.gov/vuln/detail/CVE-2025-53859));该修复从 nginx 1.29.1 移植。

<a id="bugfixes-1-1-1-1-1-1-1"></a>

#### 错误修复

- 当使用 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的 `renew_on_load` 选项时,
  如果先前获得的证书存在,则不会加载该证书。这可能会限制功能,
  直到证书续订完成。如果证书不存在,尝试获取新证书将失败,
  并显示错误 `[alert] lseek() failed (9: Bad file descriptor)`。
- 如果 [ACME 客户端](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 在 `stream` 块中被引用但不在
  `http` 块中,它将被禁用并显示警告 `[warn] ACME
  client ... is defined but not used`,并且永远不会获取证书。
- 如果所有 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令都有 `enabled=off` 参数,
  并且在配置中使用了相关的 `$acme_cert_*` 变量,Angie 将无法启动,
  并报告错误 `[emerg] unknown acme_cert_* variable`。
- 如果 [ACME 客户端](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 在位于 `http` 块之前的
  `stream` 块中使用,Angie 将无法启动,并报告错误
  `[emerg] ACME client .. is not defined but referenced`。
- 某些 `client` 块配置在使用引用在此情况下缺失的传入连接的变量时,
  可能导致工作进程崩溃。

<a id="packages-1-1-1-1-1-1-1"></a>

#### 软件包

- 更新:
  - [angie-module-cache-purge](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge),至版本 2.5.4
  - [angie-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi),至版本 v0.14.1
  - [angie-module-lua](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua),至版本 0.10.29
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs),至版本 0.9.4

---

<a id="angie-1-10-2"></a>

### Angie 1.10.2

发布日期:2025 年 8 月 21 日。

<a id="bugfixes-1-1-1-1-1-1"></a>

#### 错误修复

- `http` 块中的代理模块设置可能会破坏使用 `client` 块
  进行出站请求的模块的功能;该错误出现在 1.10.0 版本中。
- 将 [proxy_ignore_client_abort](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ignore-client-abort) 与使用 `client` 块
  进行出站请求的模块一起启用可能导致工作进程崩溃;
  该错误出现在 1.10.0 版本中。
- 如果在上游组中预配置了单个服务器,通过 [Docker API](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker)
  添加的服务器可能不会包含在负载均衡中。
- 如果上游组中的唯一服务器是通过 [Docker API](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker) 添加的,
  当检测到不可用时,它可能会被排除在负载均衡之外。

<a id="packages-1-1-1-1-1-1"></a>

#### 软件包

- 添加的动态模块:
  - [angie-module-auth-totp](https://cn.angie.software//angie/docs/installation/external-modules/auth-totp.md#external-auth-totp)
  - [angie-module-combined-upstreams](https://cn.angie.software//angie/docs/installation/external-modules/combined-upstreams.md#external-combined-upstreams)
- 更新:
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing),至版本 0.41.0

<a id="angie-1-10-1"></a>

### Angie 1.10.1

发布日期：2025 年 7 月 17 日。

<a id="changes-1-1-1-1-1"></a>

#### 变更

- 在 `client` 块中指定的指令现在只能被该块内显式声明的 `location` 块继承，因此它们不会影响隐式使用 `client` 块进行出站请求的其他模块的配置。

<a id="features-2-1-1-1-1-1-1-1"></a>

#### 功能特性

- 支持多个 `client` 块，允许将不同 `location` 块的通用设置分组到每个块中，从而减少配置重复。

<a id="bugfixes-1-1-1-1-1"></a>

#### 错误修复

- 当在 `listen` 指令中使用 `reuseport` 参数时，所有到指定地址和端口的连接都由单个工作进程处理；该错误出现在 1.10.0 版本中。
- 如果 QUIC 协议的 `retry` 模式在服务器上处于活动状态，使用 OpenSSL 库 3.5.0 或更高版本时，与上游服务器的 HTTP/3 握手可能会失败。
- 使用 GCC 15 构建 `HTTP/2` 和 `HTTP/3` 模块会导致错误。
- 使用 GCC 时，使用 `-O3` 标志构建可能会导致错误。

---

<a id="angie-1-10-0"></a>

### Angie 1.10.0

发布日期：2025 年 7 月 3 日。

<a id="features-2-1-1-1-1-1-1"></a>

#### 功能特性

- 基于 Docker（或 Podman）容器标签自动检索和动态更新代理服务器组，使用 [docker_endpoint](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#docker-endpoint) 指令进行配置。这使得能够通过指定的 Docker API 端点实时监控容器的启动和停止事件，并允许根据其标签将其地址添加到 `upstream` 组或从中删除——所有这些都无需重新加载配置。
- 在 `stream` 模块中通过 ACME 协议支持自动证书获取，使用 [acme](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_acme.md#s-acme) 指令和 [$acme_cert_\*](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_acme.md#v-s-acme-cert-name) 及 [$acme_cert_key_\*](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_acme.md#v-s-acme-cert-key-name) 等变量进行配置。
- 使用 [listen](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#listen) 指令的 `multipath` 参数支持处理 MPTCP 连接。感谢 Maxim Dounin (freenginx)、Maxime Dourov 和 Anthony Doeraene。
- 新增 [client](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client) 块，允许为各种模块发出的内部 HTTP 请求指定额外配置。
- 包含 [nginx 1.27.5](https://nginx.org/en/CHANGES) 的所有功能，包括 QUIC 连接的 CUBIC 拥塞控制。

<a id="packages-1-1-1-1-1"></a>

#### 软件包

- 更新：
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-console-light-oss)，至版本 1.8.0
  - [angie-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)，至版本 0.13
  - [angie-module-otel](https://cn.angie.software//angie/docs/installation/external-modules/otel.md#external-otel)，至版本 0.1.2

2025 年 7 月 14 日

- 更新：
  - [angie-module-headers-more](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)，至版本 v0.39
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)、[angie-module-njs-light](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.1

---

<a id="angie-1-9-1"></a>

### Angie 1.9.1

发布日期：2025 年 5 月 29 日。

<a id="features-2-1-1-1-1-1"></a>

#### 功能特性

- 在 [acme_dns_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-dns-port) 指令中支持 IP 地址和端口号；IPv4 和 IPv6 均可使用。

<a id="bugfixes-1-1-1-1"></a>

#### 错误修复

- 在 [server_name](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name) 指令中同时使用通配符域名和匹配的三级域名可能导致 ACME 服务器在单个 ACME 客户端下为这些域名颁发证书时失败。
- 在 `stream` 模块中，在被动检查期间成功连接到代理服务器后，其在统计 API 中的状态会错误地显示为 `unavailable`，直到会话结束。
- HTTP/3 请求可能会停滞并超时；该修复已从 nginx 1.29.0 移植而来。
- 在建立到代理服务器的 HTTP/3 连接时发生早期错误可能导致工作进程崩溃。
- 通过 HTTP/3 协议代理时，统计中的活动连接数可能显示不正确。

<a id="packages-1-1-1-1"></a>

#### 软件包

- 新增动态模块：
  - [angie-module-njs-light](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)
- 更新：
  - [angie-module-auth-spnego](https://cn.angie.software//angie/docs/installation/external-modules/auth-spnego.md#external-auth-spnego)，至版本 1.1.3
  - [angie-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)，至版本 0.12.1
  - [angie-module-modsecurity](https://cn.angie.software//angie/docs/installation/external-modules/modsecurity.md#external-modsec)，至版本 1.0.4
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.0
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 0.40.0

---

<a id="angie-1-9-0"></a>

### Angie 1.9.0

发布日期：2025 年 4 月 11 日。

<a id="features-2-1-1-1-1"></a>

#### 功能特性

- 在 [proxy_cache_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-path) 指令中可以指定一个文件，用于在服务器启动之间保存包含缓存索引的共享内存区域的内容；这消除了重启后重新加载缓存的需要，并允许服务器几乎立即恢复在线。
- 在 `stream` 模块中使用 [ssl_early_data](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#s-ssl-early-data) 指令支持 TLS 1.3 早期数据 (0-RTT)。
- 统计 API 中上游对等点的新 `busy` 状态，表示对等点已达到 `max_conns` 选项配置的限制。
- [acme_hook](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-hook) 指令中的 `uri=` 参数允许重新定义钩子请求 URI 并支持变量。
- [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的 `renew_on_load` 参数允许在配置加载时强制证书续订。
- 现在通过 `/status/angie` 统计 API 对象的 `build_time` 字段和 `-V` 命令行选项的输出显示构建时间。
- [nginx 1.27.4](https://nginx.org/en/CHANGES) 的所有功能，除了 `keepalive_min_timeout` 指令（类似功能自 1.8.0 版本起已存在）。

<a id="changes-1-1-1-1"></a>

#### 变更

- [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令中的 `enabled=off` 参数现在仅禁用给定客户端的证书续订，同时保留所有其他功能；密钥和证书（如果可用）可以通过 `$acme_cert_*` 变量访问，而使用 `$acme_hook_*` 变量和 `acme` 指令不会导致错误。
- 仅当在使用 `acme` 指令引用 ACME 客户端的 `server` 块中未找到有效（即符合 ACME 标准的）域名时，才会发出 `no valid domain name defined for ACME client` 错误。

<a id="bugfixes-1-1-1"></a>

#### 错误修复

- 如果使用 NTLS 支持构建，带有变量的 `proxy_ssl_certificate` 和 `proxy_ssl_certificate_key` 指令的继承无法正常工作。

<a id="packages-1-1-1"></a>

#### 软件包

- 更新：
  - [angie-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)，至版本 0.11.1
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.8.10

---

<a id="angie-1-8-3"></a>

### Angie 1.8.3

发布日期：2025 年 4 月 2 日。

<a id="bugfixes-1-1"></a>

#### 错误修复

- 如果同一连接内的请求属于不同的统计区域，或者在早期请求处理期间发生错误，HTTP 模块的 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 块中的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 统计可能会计算错误；该错误出现在 1.8.2 版本中。

<a id="packages-1-1"></a>

#### 软件包

- 更新：
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-console-light-oss)，至版本 1.7.0
  - [angie-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)，至版本 57f660bb2c6ef6e4b75c65406080d0236860ca08
  - [angie-module-jwt](https://cn.angie.software//angie/docs/installation/external-modules/jwt.md#external-jwt)，至版本 v3.4.3
  - [angie-module-ndk](https://cn.angie.software//angie/docs/installation/external-modules/ndk.md#external-ndk)，至版本 v0.3.4
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 v0.39.0
  - [angie-module-vts](https://cn.angie.software//angie/docs/installation/external-modules/vts.md#external-vts)，至版本 v0.2.4

2025 年 4 月 4 日

- 更新：
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-console-light-oss)，至版本 1.7.1

2025 年 4 月 7 日

- 更新：
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-console-light-oss)，至版本 1.7.2

<a id="angie-1-8-2"></a>

### Angie 1.8.2

发布日期：2025 年 2 月 13 日。

<a id="security-1-1-1-1-1"></a>

#### 安全性

- 在使用 TLSv1.3 SNI 处理虚拟服务器时验证不足，允许在不同虚拟服务器中重用 SSL 会话，从而绕过客户端 SSL 证书验证（[CVE-2025-23419](https://www.cve.org/CVERecord?id=CVE-2025-23419)）；该修复已从 nginx 1.27.4 移植而来。

<a id="bugfixes-1"></a>

#### 错误修复

- 从通过变量设置的单个区域检索统计值的 API 请求可能导致工作进程进入无限循环。
- HTTP/3 请求未计入区域统计；该错误出现在 1.8.0 版本中。
- 使用 QUIC 协议的 TLS 握手未计入 SSL 统计。
- 通过 [ACME 协议](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 进行证书续订可能会失败，如果 [server_name](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name) 指令中的服务器名称以点为前缀。

<a id="packages-1"></a>

#### 软件包

- 新增动态模块：
  - [angie-module-auth-pam](https://github.com/sto/ngx_http_auth_pam_module)
  - [angie-module-cgi](https://github.com/pjincz/nginx-cgi)

---

## 2024

<a id="angie-1-8-1"></a>

### Angie 1.8.1

发布日期：2024 年 12 月 28 日。

<a id="bugfixes"></a>

#### 错误修复

- 在 HTTP 模块的 `server` 块中使用 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令会导致在 TLS 握手时在 [access_log](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#access-log) 中过度记录空请求；该错误出现在 1.8.0 版本中。
- HTTP/3 流中的解码错误在关闭 QUIC 连接时可能导致工作进程崩溃；该修复已从 nginx 1.27.4 移植而来。
- 发送 QUIC 协议版本协商数据包可能导致无限数据包交换循环；该修复已从 nginx 1.27.4 移植而来。
- 在某些配置中，在 [ACME 模块](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 中使用不带钩子的 DNS 质询可能导致工作进程崩溃。

<a id="packages"></a>

#### 软件包

- 更新：
  - [angie-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，至版本 0.9.0

2025 年 1 月 23 日

- 更新：
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-console-light-oss)，至版本 1.6.0

2025 年 1 月 27 日

- 新增动态模块：
  - [angie-module-unbrotli](https://github.com/clyfish/ngx_unbrotli)
- 更新：
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-console-light-oss)，至版本 1.6.1
  - [angie-module-auth-spnego](https://cn.angie.software//angie/docs/installation/external-modules/auth-spnego.md#external-auth-spnego)，至版本 v1.1.2
  - [angie-module-headers-more](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)，至版本 v0.38
  - [angie-module-lua](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua)，至版本 0.10.28
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.8.9
  - [angie-module-vts](https://cn.angie.software//angie/docs/installation/external-modules/vts.md#external-vts)，至版本 v0.2.3
  - [angie-module-wasm](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#wasm-core)，至版本 v0.2-beta2

---

<a id="angie-1-8-0"></a>

### Angie 1.8.0

发布日期：2024 年 12 月 19 日。

<a id="features-2-1-1-1"></a>

#### 功能特性

- 通过处理来自 ACME 服务器的 DNS 查询来支持 `DNS-01` 质询，这允许自动请求任何类型的证书，包括通配符证书。
- ACME 模块中的钩子系统，可使用 [acme_hook](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-hook) 指令进行配置，允许使用外部应用程序处理域名质询，以提供与各种服务和 DNS 托管提供商的集成。
- ACME 模块记录一些额外信息：证书更新的确切原因、完整域名列表、客户端的账户 ID、长时间不活动（例如轮询）以及正在质询的域名；这些信息简化了故障排除并允许指定 CAA DNS 记录。
- [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的 `account_key` 参数，允许为 ACME 服务器账户重用现有密钥，而不是自动生成新密钥。
- 在 stream 和 HTTP 模块的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令中支持变量，允许在单个 `location` 或 `server` 块中动态统计多个区域；特别是当单个 `server` 块处理多个虚拟主机时，这非常有用。
- GZip HTTP 压缩模块与 `zlib-ng` 2.2.0 及更高版本的兼容性，以前可能会在错误日志中导致 `[alert] gzip filter failed to use preallocated memory` 消息。
- [max_headers](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#max-headers) 指令限制 HTTP 请求头字段的数量，以更好地防御 DoS 攻击。感谢 Maxim Dounin (freenginx) 和 Maksim Yevmenkin。
- [http3_max_table_capacity](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#http3-max-table-capacity) 和 [proxy_http3_max_table_capacity](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http3-max-table-capacity) 指令用于配置 HTTP/3 动态头压缩表限制。
- 交叉编译支持 - 构建系统现在可以使用包装脚本来运行自动测试，这使得可以在不直接在目标平台上运行测试程序的情况下准备构建。
- [nginx 1.27.3](https://nginx.org/en/CHANGES) 的所有功能。

#### 错误修复

- 使用 `0-RTT` 时 HTTP/3 客户端可能超时；该错误在 1.7.0 版本中从 nginx 继承而来。
- 在 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass) 指令中使用变量且未指定 `upstream` 块的 HTTP/3 代理可能导致工作进程崩溃。
- 使用动态表的 HTTP/3 上游如果与缓存一起使用可能导致工作进程崩溃。
- 某些 SSL 握手可能未计入 Stream 模块的统计。
- 在 `http` 或 `server` 级别指定的 HTTP/3 代理设置可能被忽略。
- 在启用 NTLS 支持的情况下通过 HTTP/3 代理时，[proxy_ssl_certificate](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-certificate) 指令不起作用。

<a id="changes-1-1-1"></a>

#### 变更

- 在优雅关闭旧工作进程时，现在仅在 [lingering_timeout](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#lingering-timeout) 指令指定的超时过期后才关闭保持活动连接；此行为允许避免在此时接收回复时可能出现的客户端错误。感谢 Maxim Dounin (freenginx)。
- 禁用了 Stream 模块变量 [$ssl_server_name](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-server-name)、[$ssl_server_cert_type](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-server-cert-type)、[$ssl_preread_protocol](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#v-ssl-preread-protocol) 和 [$ssl_preread_server_name](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#v-ssl-preread-server-name) 的缓存，这允许在使用虚拟服务器时获取实际值。

#### 软件包

- 新增动态模块：
  - [angie-module-http-auth-radius](https://github.com/ten0s/ngx_http_auth_radius_module)
- 更新：
  - [angie-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，至版本 0.8.0
  - [angie-module-jwt](https://cn.angie.software//angie/docs/installation/external-modules/jwt.md#external-jwt)，至版本 3.4.2
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.8.8
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 0.38.0
  - [angie-module-wasm](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#wasm-core)，至版本 0.1-beta5

---

<a id="angie-1-7-0"></a>

### Angie 1.7.0

发布日期：2024 年 9 月 19 日。

<a id="features-2-1-1"></a>

#### 功能特性

- 当代理服务器从组中移除时，可以通过 [proxy_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-connection-drop)、[grpc_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_grpc.md#grpc-connection-drop)、[fastcgi_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-connection-drop)、[scgi_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-connection-drop) 和 [uwsgi_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-connection-drop) 指令配置强制关闭到该服务器的所有连接。
- 在解析器统计 API 中增加了已发送 DNS 查询类型的计数器，该统计信息通过 [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 指令的 `status_zone` 参数收集。
- 新增 [$ssl_server_cert_type](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-server-cert-type) 变量，包含为接收到的 TLS 连接选择的证书类型。
- 可以通过 [pid](https://cn.angie.software//angie/docs/configuration/modules/core.md#pid) 指令的 `off` 参数禁用 PID 文件的创建，这在使用不可变镜像和由服务管理器直接控制时可能很有用。感谢 Maxim Dounin (freenginx)。
- 通过中间临时文件使 PID 文件的创建具有原子性，这消除了文件已在目录中但仍为空的时刻，并允许外部程序更容易、更可靠地处理它。
- 现在，在重新配置期间，如果 [pid](https://cn.angie.software//angie/docs/configuration/modules/core.md#pid) 指令中的名称已更改但通过符号链接指向同一文件，则不会尝试重新创建 PID 文件；特别是，这允许避免在从 `/var/run/angie.pid` 迁移到 `/run/angie.pid` 的系统上出现问题。感谢 Maxim Dounin (freenginx)。
- [Syslog 日志记录](https://cn.angie.software//angie/docs/configuration/processing.md#syslog-logging) 错误现在每秒最多报告一次；这有助于避免在 syslog 服务器宕机或过载时用此类消息淹没日志。感谢 Maxim Dounin (freenginx)。
- 在邮件代理模块中，通过 [max_commands](https://cn.angie.software//angie/docs/configuration/modules/mail/index.md#max-commands) 指令配置的身份验证期间的最大命令数受到限制，以更好地防范 DoS 攻击。感谢 Maxim Dounin (freenginx)。
- **./configure** 脚本的 [--feature-cache](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 选项，用于缓存其结果以在构建多个模块或交叉编译时进行优化。
- [nginx 1.27.1](https://nginx.org/en/CHANGES) 的所有功能。

#### 错误修复

- 使用 **systemd** 启动时可能出现 `PID file ... not readable (yet?) after start` 和 `Failed to parse PID from file...` 错误。感谢 Maxim Dounin (freenginx)。

<a id="changes-1-1"></a>

#### 变更

- 更新了 HTTP 状态码的描述以符合 RFC 9110。感谢 Maxim Dounin (freenginx) 和 Michiel W. Beijen。
- 现在 HTTP 请求之前最多只允许一个空行，以更好地防范 DoS 攻击。感谢 Maxim Dounin (freenginx)。
- 现在禁止末尾没有冒号的 HTTP/1.x 头字段名称；来自客户端或代理服务器的此类无效头字段现在将导致错误响应。感谢 Maxim Dounin (freenginx) 和 Maksim Yevmenkin。
- 使用 HTTP/1.1 分块传输编码读取请求体时，忽略的块扩展和尾部头字段的总大小现在受 [client_max_body_size](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-max-body-size) 指令限制，以更好地防范 DoS 攻击。感谢 Maxim Dounin (freenginx) 和 Bartek Nowotarski。
- `mime.types` 配置文件中的 MIME 类型已更改：`bmp` 扩展名改为 `image/bmp`，`rar` 扩展名改为 `application/vnd.rar`；`deb` 和 `udeb` 扩展名设置为 `application/vnd.debian.binary-package`。感谢 Yuriy Izorkin。

#### 软件包

- 更新：
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 0.36.0
  - [angie-module-lua](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua)，至版本 0.10.27

2024 年 10 月 24 日

- 为 [SberLinux](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-yum-oss) 添加了软件包。

2024 年 11 月 29 日

- 添加了 WASM 支持，包含以下软件包：
  - [angie-module-wamr](https://cn.angie.software//angie/docs/configuration/modules/wasm/wasm_wamr.md#wasm-wamr)
  - [angie-module-wasm](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#wasm-core)
  - [angie-module-wasmtime](https://cn.angie.software//angie/docs/configuration/modules/wasm/wasm_wasmtime.md#wasm-wasmtime)

---

<a id="angie-1-6-2"></a>

### Angie 1.6.2

发布日期：2024 年 8 月 16 日。

<a id="security-1-1-1-1"></a>

#### 安全性

- 使用 [ngx_http_mp4_module](https://cn.angie.software//angie/docs/configuration/modules/http/http_mp4.md#http-mp4) 处理特制的 MP4 文件可能导致工作进程崩溃（[CVE-2024-7347](https://nvd.nist.gov/vuln/detail/CVE-2024-7347)）；该修复从 nginx 1.27.1 移植而来。

---

<a id="angie-1-6-1"></a>

### Angie 1.6.1

发布日期：2024 年 8 月 8 日。

<a id="features-2-1"></a>

#### 功能特性

- [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-status-zone) 指令的 [API 统计](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-stream-server-zones) 中新增了 `passed` 计数器，用于跟踪使用 [pass](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_pass.md#s-pass) 指令传递到其他套接字的连接。

#### 错误修复

- 在 [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中使用虚拟服务器或 [pass](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_pass.md#s-pass) 指令时，统计 API 中的连接可能被错误地计数。
- 在配置了 5 个或更多 ACME 客户端时，工作进程可能崩溃；该错误出现在 1.6.0 版本中。
- 处理带有 `X-Accel-Redirect` 头的缓存响应可能导致工作进程崩溃。感谢 Maxim Dounin (freenginx) 和 Jiří Setnička。

#### 软件包

- 更新：
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-console-light-oss)，至版本 1.4.0
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 0.35.3
  - [angie-module-zstd](https://cn.angie.software//angie/docs/installation/external-modules/zstd.md#external-zstd)，至修订版 `f4ba115`

---

<a id="angie-1-6-0"></a>

### Angie 1.6.0

发布日期：2024 年 6 月 28 日。

<a id="features-2"></a>

#### 功能特性

- [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-upstream) 块中的 [sticky](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-sticky) 指令及相关选项，允许配置粘性会话模式，使会话中的所有连接都路由到同一服务器。
- 在 [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中使用 [rdp_preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#s-rdp-preread) 指令从 RDP 连接中提取 Cookie 值到 [$rdp_cookie](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#v-rdp-cookie) 和 [$rdp_cookie_NAME](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#id5) 变量，这允许在负载均衡时记录 RDP 客户端会话并将其粘附到特定服务器。
- 在 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 块中支持多个 [acme](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 指令，允许为该虚拟服务器同时配置获取两种类型的证书。
- 命令行选项 `-m` 和 `-M` 用于列出内置和已加载的模块。
- [ACME](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 模块支持 [BoringSSL](https://www.chromium.org/Home/chromium-security/boringssl/)。
- [nginx 1.27.0](https://nginx.org/en/CHANGES) 的所有功能，包括 [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中的虚拟服务器支持和 `pass` 指令，该指令允许将接受的连接传递给其他监听套接字进行处理，包括 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-http) 和 [Mail](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-mail) 模块。

#### 错误修复

- 通过 ACME 协议请求证书在某些配置上可能导致错误，日志消息类似于 `[alert] getsockname() failed (9: Bad file descriptor)`。
- 通过 ACME 协议请求包含大量域名的证书可能导致错误，日志消息类似于 `[error] JSON parser error`。
- 在配置了多个 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 指令的情况下，ACME 客户端可能将消息记录到不相关的日志中。

#### 软件包

- 更新：
  - [angie-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，至版本 0.7.0
  - [angie-module-auth-ldap](https://cn.angie.software//angie/docs/installation/external-modules/auth-ldap.md#external-ldap)，至修订版 `241200e`
  - [angie-module-jwt](https://cn.angie.software//angie/docs/installation/external-modules/jwt.md#external-jwt)，至版本 3.4.1
  - [angie-module-keyval](https://cn.angie.software//angie/docs/installation/external-modules/keyval.md#external-keyval)，至版本 0.3.0
  - [angie-module-lua](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua)：`stream_lua_module`，至修订版 `bea8a0c`
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.8.5

---

<a id="angie-1-5-2"></a>

### Angie 1.5.2

发布日期：2024 年 6 月 3 日。

<a id="security-1-1-1"></a>

#### 安全性

- 使用 HTTP/3 时，处理特制的 QUIC 会话可能导致工作进程崩溃、在 MTU 大于 4096 字节的系统上泄露工作进程内存或产生其他影响（[CVE-2024-32760](https://nvd.nist.gov/vuln/detail/CVE-2024-32760)、[CVE-2024-31079](https://nvd.nist.gov/vuln/detail/CVE-2024-31079)、[CVE-2024-35200](https://nvd.nist.gov/vuln/detail/CVE-2024-35200)、[CVE-2024-34161](https://nvd.nist.gov/vuln/detail/CVE-2024-34161)）；该修复已从 nginx 1.26.1 移植而来。

#### 软件包

- 更新：
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 0.35.2

---

<a id="angie-1-5-1"></a>

### Angie 1.5.1

发布日期：2024 年 5 月 16 日。

#### 错误修复

- 当在 `upstream` 块中的 `server` 指令使用 [resolve](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-reresolve) 选项时，如果解析的 IP 地址数量与指定的服务器数量不同，`proxy_next_upstream` 机制无法正常工作。
- 通过 ACME 协议请求证书时，工作进程可能会发生段错误。
- 在 [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中代理 TCP 连接时，[slow_start](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-slow-start) 机制无法工作。
- 如果 HTTP/3 请求作为 TLS 1.3 早期数据接收，可能会导致错误；该问题出现在 1.4.0 版本中。
- 使用 QUIC 中的 0-RTT 时，HTTP/3 连接可能会过早关闭。
- 从快速连接读取请求体时，可能会长时间读取。感谢 Maxim Dounin (freenginx)。

<a id="changes-1"></a>

#### 变更

- 现在 ACME 客户端不会丢弃之前存储的已过期或为不同域名列表签发的证书，而是在续订时使用它们。

#### 软件包

- 更新:
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-console-light-oss)，至 1.4.0 版本
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至 0.35.3 版本
  - [angie-module-zstd](https://cn.angie.software//angie/docs/installation/external-modules/zstd.md#external-zstd)，至修订版 `f4ba115`

---

<a id="angie-1-5-0"></a>

### Angie 1.5.0

发布日期: 2024 年 3 月 27 日。

#### 功能特性

- 基本支持使用 [ACME 协议](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 自动获取和更新证书,可通过 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 和 [acme](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 指令以及形如 [$acme_cert_=](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-cert-name) 和 [$acme_cert_key_=](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-cert-key-name) 的变量进行配置。
- 通过 [auto_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#auto-redirect) 指令配置自动重定向,向请求 URI 添加尾部斜杠。
- 输出 [统计指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics) 时使用 Epoch 格式的日期而不是 ISO 8601,便于在 Prometheus 中使用,并可选在 JSON API 中使用 `?date-epoch` 请求参数。
- 在 [统计 API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics) 中为上游对等方引入新的 `recovering` 状态,表明对等方在故障后正在缓慢启动,如 `slow_start` 选项所示。
- 现在 `-V` 参数还显示相关的 nginx 版本,这对与第三方工具(特别是 **certbot**)的兼容性很有用。感谢 [AdvTechnoKing](https://github.com/webserver-llc/angie/commit/eb914d43aa6a2231d7321c808cb4180abb013ca0)。
- [nginx 1.25.4](https://nginx.org/en/CHANGES) 的所有功能。

#### 错误修复

- 如果使用了 SSL 会话重用机制 ([proxy_ssl_session_reuse](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-session-reuse)) 并且代理服务器列表动态更新,则可能在为相应的 `upstream` 块配置的共享内存区域 (`zone`) 中发生泄漏。

#### 软件包

- 新增 [FreeBSD 13](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-freebsd-oss) (arm64)、[RED OS 8](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-yum-oss) (x86-64) 软件包。
- 新增动态模块:
  - [angie-module-otel](https://github.com/nginxinc/nginx-otel)
- 更新:
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing),至 0.34.0 版本

2024 年 3 月 28 日

- 更新:
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages),至 1.3.0 版本

2024 年 4 月 16 日

- 新增动态模块:
  - [angie-module-zstd](https://github.com/tokers/zstd-nginx-module)
- 更新:
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs),至 0.8.4 版本

2024 年 4 月 25 日

- 新增动态模块:
  - angie-module-vts: 包括
    [module-vts](https://github.com/vozlt/nginx-module-vts)、
    [module-sts](https://github.com/vozlt/nginx-module-sts)、
    [module-stream-sts](https://github.com/vozlt/nginx-module-stream-sts)

---

<a id="angie-1-4-1"></a>

### Angie 1.4.1

发布日期: 2024 年 2 月 15 日。

<a id="security-1-1"></a>

#### 安全性

- 使用 HTTP/3 时,处理特制的 QUIC 会话可能导致工作进程段错误 ([CVE-2024-24989](https://nvd.nist.gov/vuln/detail/CVE-2024-24989));请注意,Angie 从 1.4.0 版本开始已不受 [CVE-2024-24990](https://nvd.nist.gov/vuln/detail/CVE-2024-24990) 影响。

#### 软件包

- 新增动态模块:
  - [angie-module-dynamic-limit-req](https://github.com/limithit/ngx_dynamic_limit_req_module)
- 更新：
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至 0.8.3 版本
  - [angie-module-vod](https://cn.angie.software//angie/docs/installation/external-modules/vod.md#external-vod)，至 1.33 版本

## 2023

<a id="angie-1-4-0"></a>

### Angie 1.4.0

发布日期：2023 年 12 月 12 日。

#### 功能特性

- 在 [HTTP 代理模块](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy) 中支持与上游服务器建立 HTTP/3 连接，
  同时允许客户端使用任意 HTTP 版本。通过 [proxy_http_version](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http-version) 指令
  以及一组 `proxy_quic_` 和 `proxy_http3_` 指令进行配置。
- 使用 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 块中 [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 指令的 `slow_start`
  选项，在故障后平滑地将代理服务器重新上线的机制。
- [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中的 [mqtt_preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#s-mqtt-preread)
  指令，允许从 MQTT 协议的 CONNECT 数据包中提取用户名和客户端 ID 到
  [$mqtt_preread_username](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#v-mqtt-preread-username) 和 [$mqtt_preread_clientid](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#v-mqtt-preread-clientid) 变量中。
- 使用 [mp4_limit_rate](https://cn.angie.software//angie/docs/configuration/modules/http/http_mp4.md#mp4-limit-rate) 和 [mp4_limit_rate_after](https://cn.angie.software//angie/docs/configuration/modules/http/http_mp4.md#mp4-limit-rate-after) 指令，
  按比特率限制 MP4 文件向客户端的传输速率，从而降低带宽负载。
- [nginx 1.25.3](https://nginx.org/en/CHANGES) 的所有功能。

#### 错误修复

- 如果代理服务器是组中唯一的服务器，即使恢复后，在 [metrics API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics)
  中也可能被错误地报告为 `unavailable`。

#### 软件包

- 新增 [Alpine](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-alpine-oss) 3.19 软件包。
- 新增动态模块：
  - [angie-module-auth-ldap](https://github.com/kvspb/nginx-auth-ldap)
- 更新：
  - [angie-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，至 0.4.0 版本
  - [angie-module-headers-more](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)，至 0.36 版本
  - [angie-module-ndk](https://cn.angie.software//angie/docs/installation/external-modules/ndk.md#external-ndk)，至 0.3.3 版本
  - [angie-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至 0.33.0 版本

2023年12月18日

- 更新：
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)，至 1.2.0 版本

2023年12月25日

- 更新：
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)，至 1.2.1 版本

2024年1月22日

- 新增动态模块：
  - [angie-module-zip](https://github.com/evanmiller/mod_zip)
- 更新：
  - [angie-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，至 0.6.0 版本
  - [angie-module-headers-more](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)，至 0.37 版本
  - [angie-module-lua](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua)：
    `http_lua_module`，至 0.10.26 版本；
    `stream_lua_module`，至 0.0.14 版本

---

<a id="angie-1-3-2"></a>

### Angie 1.3.2

发布日期：2023 年 11 月 23 日。

#### 错误修复

- [Prometheus](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#id3) 输出中使用 `$p8s_value` 以外的变量作为值的
  指标可能出现不正确的值；实际上该问题可能出现在标准 `prometheus_all.conf`
  模板中的 `angie_http_upstreams_peers_state` 和
  `angie_stream_upstreams_peers_state` 指标上。
- 如果某些到上游服务器的连接尝试立即失败，可能未在 [统计 API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api)
  中正确计数；该错误出现在 1.3.0 版本。

#### 软件包

2023年12月4日

- 新增动态模块：
  - [angie-module-modsecurity](https://github.com/owasp-modsecurity/ModSecurity-nginx)

2023年12月7日

- 更新：
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)，至 1.1.1 版本

---

<a id="angie-1-3-1"></a>

### Angie 1.3.1

发布日期：2023 年 10 月 18 日。

<a id="security-1"></a>

#### 安全性

- 为 HTTP/2 流处理添加了额外限制，以更好地防御被称为"HTTP/2 Rapid Reset"的
  DoS 攻击 ([CVE-2023-44487](https://nvd.nist.gov/vuln/detail/CVE-2023-44487))。

#### 软件包

2023年10月26日

- 新增动态模块：
  - [angie-module-opentracing](https://github.com/opentracing-contrib/nginx-opentracing/)

2023年11月13日

- 新增动态模块：
  - [angie-module-testcookie](https://github.com/kyprizel/testcookie-nginx-module/)
- 更新：
  - [angie-console-light](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)，至 1.1.0 版本
  - [angie-module-headers-more](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)，至 0.35 版本
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至 0.8.2 版本
  - [angie-module-vod](https://cn.angie.software//angie/docs/installation/external-modules/vod.md#external-vod)，至 1.32 版本

---

<a id="angie-1-3-0"></a>

### Angie 1.3.0

发布日期：2023 年 9 月 19 日。

#### 功能特性

- 在 `location` 指令中指定多个匹配模式的能力，允许
  [合并](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#combined-locations) 多个具有相似设置的 `location` 块，
  从而通过减少重复来简化配置。
- 使用新的 [prometheus](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#id3) 和 [prometheus_template](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#prometheus-template) 指令，
  以 Prometheus 格式导出各种统计指标，并通过灵活的模板配置。
- 在由 [api](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 指令提供的统计接口中，为流上游服务器组提供
  详细信息和 [指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-stream-upstreams)。
- [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 模块的 `upstream` 块中 `server`
  指令的 [resolve](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-reresolve) 选项，允许监控与域名对应的 IP 地址列表的变化，
  并自动更新它而无需重新加载配置。
- [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 模块的 `upstream` 块中 `server`
  指令的 [service](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-reresolve) 选项，允许从 DNS SRV 记录中检索地址列表，
  并提供基本的优先级支持。
- 通过启用 [api_config_files](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api-config-files) 指令，经由 [api](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 指令提供的接口，
  访问当前工作进程使用的配置文件内容。
- 在进程标题中显示 [配置代数](https://cn.angie.software//angie/docs/configuration/runtime.md#control-config-change) 编号，
  允许使用 `ps` 工具监控配置重载的成功情况以及之前工作进程代数的数量。
- [nginx 1.25.2](https://nginx.org/en/CHANGES) 的所有功能。

<a id="bugfix-1"></a>

#### 错误修复

- 当使用 `./configure` 选项 `--without-http_upstream_zone_module`
  或 `--without-stream_upstream_zone_module` 时编译失败；
  该错误出现在 1.2.0 版本。

<a id="changes"></a>

#### 变更

- 现在加载 OpenSSL 配置时使用应用名称 `angie`。

#### 软件包

- 更新：
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至 0.8.1 版本

---

<a id="angie-1-2-0"></a>

### Angie 1.2.0

发布日期：2023 年 5 月 30 日。

#### 功能特性

- [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 块中的 [sticky](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky)
  指令及相关选项，允许配置会话保持模式，使会话内的所有请求都路由到同一服务器。
- [$upstream_sticky_status](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-sticky-status) 变量，根据启用会话保持时将请求路由到相关上游服务器的
  成功情况，取值为 `NEW`、`HIT` 或 `MISS`。
- 在使用 [TongSuo](https://github.com/Tongsuo-Project/Tongsuo) TLS 库时，
  [HTTP](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#stream-ssl) 模块中对 NTLS 的支持；可以通过 `‑‑with‑ntls`
  构建选项启用该支持，并使用相应的 [ssl_ntls](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-ntls) 和 [proxy_ssl_ntls](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-ntls) 指令进行配置。
- 在 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#stream-proxy) 代理模块中，使用 [proxy_ssl_certificate](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-certificate)
  和 [proxy_ssl_certificate_key](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-certificate-key) 指令指定不同类型（RSA 和 ECDSA）的多个证书
  及相应密钥的能力。
- 在 `master` 进程标题中显示版本和构建名称，允许使用 `ps` 工具
  获取正在运行的服务器实例的此信息。
- [gzip](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#http-gzip) 模块压缩"207 Multi-Status"响应的能力。
  感谢 [DBotThePony](https://github.com/webserver-llc/angie/pull/26)。
- [nginx 1.25.0](https://nginx.org/en/CHANGES) 的所有功能，
  包括 [HTTP/3](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#http-v3) 支持。

#### 软件包

- 新增 [Ubuntu 23.04 "Lunar Lobster"](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-deb-oss) 软件包。
- 新增动态模块：
  - `angie-module-lua` 软件包包含
    [http_lua_module](https://github.com/openresty/lua-nginx-module)
    和
    [stream_lua_module](https://github.com/openresty/stream-lua-nginx-module)。
  - [angie-module-redis2](https://github.com/openresty/redis2-nginx-module)

2023年6月13日

- 新增 [Debian 12 "Bookworm"](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-deb-oss) 和
  [AlmaLinux](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-yum-oss) 软件包。

2023年7月12日

- 新增动态模块：
  - [angie-module-cache-purge](https://github.com/nginx-modules/ngx_cache_purge)
  - [angie-module-echo](https://github.com/openresty/echo-nginx-module)
  - [angie-module-keyval](https://github.com/kjdev/nginx-keyval)
  - [angie-module-postgres](https://github.com/FRiCKLE/ngx_postgres)
- 更新：
  - [angie-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至 0.8.0 版本。

2023年7月28日

- 新增动态模块：
  - [angie-module-auth-jwt](https://github.com/kjdev/nginx-auth-jwt)

2023年8月18日

- 新增动态模块：
  - [angie-module-enhanced-memcached](https://github.com/bpaquet/ngx_http_enhanced_memcached_module)
  - [angie-module-eval](https://github.com/openresty/nginx-eval-module)

---

<a id="angie-1-1-0"></a>

### Angie 1.1.0

发布日期：2023 年 1 月 24 日。

#### 功能特性

- [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 块中 [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server)
  指令的 [resolve](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve) 选项，允许监控与域名对应的 IP 地址列表的变化，
  并自动更新它而无需重新加载配置。
- [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 块中 [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server)
  指令的 [service](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve) 选项，允许从 DNS SRV 记录中检索地址列表，
  并提供基本的优先级支持。
- 在由 [api](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 指令提供的统计接口中，为 HTTP 上游服务器组提供
  [详细信息和指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-upstream)。
- [autoindex](https://cn.angie.software//angie/docs/configuration/modules/http/http_autoindex.md#id3) 对目录列表使用自然排序顺序。
- [nginx 1.23.3](https://nginx.org/en/CHANGES) 的所有功能。

<a id="bugfix"></a>

#### 错误修复

- 当使用 GCC 9 或更早版本并启用 -O2 或更高优化级别时，由于错误警告导致编译失败。

#### 软件包

2023年3月15日

- 新增 [Oracle](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-yum-oss) 和
  [Rocky](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-yum-oss) Linux 软件包。
- 新增动态模块：
  - [angie-module-auth-spnego](https://github.com/stnoonan/spnego-http-auth-nginx-module)
  - [angie-module-brotli](https://github.com/google/ngx_brotli)
  - [angie-module-dav-ext](https://github.com/arut/nginx-dav-ext-module)
  - [angie-module-headers-more](https://github.com/openresty/headers-more-nginx-module/)
  - [angie-module-ndk](https://github.com/vision5/ngx_devel_kit)
  - [angie-module-rtmp](https://github.com/arut/nginx-rtmp-module)
  - [angie-module-set-misc](https://github.com/openresty/set-misc-nginx-module)

2023年4月7日

- 新增 [ALT](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-alt-oss) Linux 软件包。

2023年5月11日

- 新增 [FreeBSD](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-freebsd-oss) 软件包。
- 新增动态模块：
  - [angie-module-jwt](https://github.com/max-lt/nginx-jwt-module)
  - [angie-module-subs](https://github.com/yaoweibin/ngx_http_substitutions_filter_module)
  - [angie-module-upload](https://github.com/fdintino/nginx-upload-module)
  - [angie-module-vod](https://github.com/kaltura/nginx-vod-module)

2023年5月26日

- 新增 [Astra](https://cn.angie.software//angie/docs/installation/oss_packages.md#install-astrase-oss) Linux 特别版软件包。

---

## 2022

<a id="angie-1-0-0"></a>

### Angie 1.0.0

发布日期：2022 年 10 月 27 日。

#### 功能特性

- [api](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 指令，提供 HTTP RESTful 接口，以 JSON 格式访问
  Web 服务器实例的基本信息，以及客户端连接、共享内存区域、DNS 查询、
  HTTP 请求、HTTP 响应缓存、[stream](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#stream-core) 模块的 TCP/UDP 会话，
  以及 [limit_conn](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_conn.md#http-limit-conn)/[limit_req](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_req.md#http-limit-req)
  模块的区域的 [指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics)。
- [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#http-core) 模块中的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令，
  用于在 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 和 [location](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#location) 上下文中指定收集请求指标的区域。
- [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#stream-core) 模块中的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-status-zone) 指令，
  用于指定收集 TCP/UDP 会话指标的区域。
- [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 指令的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver-status) 参数，
  用于指定收集 DNS 查询指标的区域。
- [$angie_version](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-angie-version) 变量，包含 Angie 的版本。
- [nginx 1.23.2](https://nginx.org/en/CHANGES) 的所有功能。


# https://cn.angie.software/angie/docs/installation/oss_packages.md

<!-- review: finished -->

<a id="oss-packages"></a>

# Angie 软件包安装

要使用您的发行版软件包管理器
安装和更新 Angie,
请添加并配置相应的仓库。

<a id="distributions"></a>

## 发行版

| 名称                                | 版本                             | 架构                            |
|-----------------------------------|--------------------------------|-------------------------------|
| [AlmaLinux](#install-yum-oss)     | 10,  9,  8                     | x86-64, arm64                 |
| [Alpine](#install-alpine-oss)     | 3.23,  3.22,  3.21,  3.20      | x86-64, arm64                 |
| [Alt](#install-alt-oss)           | 11,  10  8                     | x86-64, arm64  x86-64         |
| [Astra SE](#install-astrase-oss)  | 4.7  1.8, 1.7                  | arm64  x86-64                 |
| [CentOS](#install-yum-oss)        | 10,  9                         | x86-64, arm64                 |
| [Debian](#install-deb-oss)        | 13,  12,  11                   | x86-64, arm64                 |
| [Fedora](#install-yum-oss)        | 44,  43                        | x86-64, arm64                 |
| [FreeBSD](#install-freebsd-oss)   | 15,  14,  13                   | x86-64, arm64                 |
| [MSVSphere](#install-yum-oss)     | 10,  9  8                      | x86-64, arm64  x86-64         |
| [openSUSE](#install-opensuse-oss) | 16,  15                        | x86-64, arm64                 |
| [Oracle Linux](#install-yum-oss)  | 10,  9,  8                     | x86-64, arm64                 |
| [OSNova](#install-osnova-oss)     | 3.3.0,  2.13                   | x86-64                        |
| [RED OS](#install-yum-oss)        | 8,  7                          | x86-64, arm64                 |
| [Rocky Linux](#install-yum-oss)   | 10,  9,  8                     | x86-64, arm64                 |
| [ROSA](#install-yum-oss)          | Chrome 13  Chrome 12  Fresh 12 | x86-64  x86-64, arm64  x86-64 |
| [SberLinux](#install-yum-oss)     | 9                              | x86-64                        |
| [Ubuntu](#install-deb-oss)        | 26.04,  24.04,  22.04          | x86-64, arm64                 |

<a id="test-builds"></a>

### 测试构建

我们每天测试并构建来自我们仓库的代码,
这些
[每日构建](https://download.angie.software/angie-nightly/)
适合在正式发布之前探索新功能。

每日构建的版本始终对应于即将发布的版本。
命名和安装过程通常与下面显示的类似,
但不使用路径前缀 `https://download.angie.software/angie/*`,
而是使用 `https://download.angie.software/angie-nightly/*`。

<a id="install-yum-oss"></a>

### Alma、CentOS、Fedora、MSVSphere、Oracle、RED OS、Rocky、ROSA、SberLinux

1. 要添加仓库,请创建一个名为
   `/etc/yum.repos.d/angie.repo`
   的文件,内容如下:

   Alma
   ```ini
   [angie]
   name=Angie repo
   baseurl=https://download.angie.software/angie/almalinux/$releasever/
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   CentOS
   ```ini
   [angie]
   name=Angie repo
   baseurl=https://download.angie.software/angie/centos/$releasever/
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   Fedora
   ```ini
   [angie]
   name=Angie repo
   baseurl=https://download.angie.software/angie/fedora/$releasever/
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   MSVSphere
   ```ini
   [angie]
   name=Angie repo
   baseurl=https://download.angie.software/angie/msvsphere/$releasever/
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   Oracle
   ```ini
   [angie]
   name=Angie repo
   baseurl=https://download.angie.software/angie/oracle/$releasever/
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   RED OS
   ```ini
   [angie]
   name=Angie repo
   baseurl=https://download.angie.software/angie/redos/$releasever/
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   Rocky
   ```ini
   [angie]
   name=Angie repo
   baseurl=https://download.angie.software/angie/rocky/$releasever/
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   ROSA Chrome
   ```ini
   [angie]
   name=Angie repo
   baseurl=https://download.angie.software/angie/rosa-chrome/$releasever/
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   priority=9
   ```

   ROSA Fresh
   ```ini
   [angie]
   name=Angie repo
   baseurl=https://download.angie.software/angie/rosa/$releasever/
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   priority=9
   ```

   SberLinux
   ```ini
   [angie]
   name=Angie repo
   baseurl=https://download.angie.software/angie/sberlinux/$releasever/
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   priority=9
   ```
2. 安装 Angie 软件包:
   ```console
   $ sudo yum install -y angie
   $ # -- 或者 --
   $ sudo dnf install -y angie
   ```
3. ( *可选*) 安装您需要的任何 [额外](#install-extras-oss)
   软件包:
   ```console
   $ sudo yum install -y <PACKAGE NAME>
   $ # -- 或者 --
   $ sudo dnf install -y <PACKAGE NAME>
   ```
4. 启动服务:
   ```console
   $ sudo systemctl start angie
   ```
5. 要在服务器重启后自动启动 Angie:
   ```console
   $ sudo systemctl enable angie
   ```

<a id="install-alpine-oss"></a>

### Alpine

1. 安装添加 Angie 仓库的
   先决条件:
   ```console
   $ sudo apk update
   $ sudo apk add curl ca-certificates
   ```
2. 下载 Angie 仓库的公钥
   用于软件包验证:
   ```console
   $ sudo curl -o /etc/apk/keys/angie-signing.rsa \
               https://angie.software/keys/angie-signing.rsa
   ```
3. 添加 Angie 仓库:
   ```console
   $ echo "https://download.angie.software/angie/alpine/v$(egrep -o \
          '[0-9]+\.[0-9]+' /etc/alpine-release)/main" \
          | sudo tee -a /etc/apk/repositories > /dev/null
   ```
4. 更新仓库索引:
   ```console
   $ sudo apk update
   ```
5. 安装 Angie 软件包:
   ```console
   $ sudo apk add angie
   ```
6. ( *可选*) 安装您需要的任何 [额外](#install-extras-oss)
   软件包:
   ```console
   $ sudo apk add <PACKAGE NAME>
   ```
7. 启动服务:
   ```console
   $ sudo service angie start
   ```
8. 要在服务器重启后自动启动 Angie:
   ```console
   $ sudo rc-update add angie
   ```

<a id="install-alt-oss"></a>

### Alt

1. 创建 `/etc/ssl/angie/` 目录:
   ```console
   $ sudo mkdir -p /etc/ssl/angie/
   ```
2. 安装添加 Angie 仓库的
   先决条件:
   ```console
   $ sudo apt-get update
   $ sudo apt-get install -y curl apt-https
   ```
3. 下载 Angie 仓库的公钥
   用于软件包验证:
   ```console
   $ sudo curl -o /etc/ssl/angie/angie-signing.gpg \
         https://angie.software/keys/angie-signing.gpg
   ```
4. 将下载的密钥导入到受信任的密钥环:
   ```console
   $ sudo gpg --no-default-keyring \
         --keyring /usr/lib/alt-gpgkeys/pubring.gpg --import /etc/ssl/angie/angie-signing.gpg
   ```
5. 保存密钥的签名:
   ```sh
   $ echo 'simple-key "angie" {
             Fingerprint "EB8EAF3D4EF1B1ECF34865A2617AB978CB849A76";
             Name "Angie (Signing Key) <devops@tech.wbsrv.ru>";
     }' | sudo tee /etc/apt/vendors.list.d/angie.list > /dev/null
   ```
6. 添加 Angie 仓库:

   Alt 11
   ```console
   $ echo "rpm [angie] https://download.angie.software/angie/altlinux/11/ $(uname -m) main" \
       | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```

   Alt 10
   ```console
   $ echo "rpm [angie] https://download.angie.software/angie/altlinux/10/ $(uname -m) main" \
       | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```

   Alt SP 10
   ```console
   $ echo "rpm [angie] https://download.angie.software/angie/altlinux-sp/10/ $(uname -m) main" \
       | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```

   Alt SP 8
   ```console
   $ echo "rpm [angie] https://download.angie.software/angie/altlinux-sp/8/ $(uname -m) main" \
       | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```
7. 更新仓库索引:
   ```console
   $ sudo apt-get update
   ```
8. 安装 Angie 软件包:
   ```console
   $ sudo apt-get install -y angie
   ```
9. ( *可选*) 安装您需要的任何 [额外](#install-extras-oss)
   软件包:
   ```console
   $ sudo apt-get install -y <PACKAGE NAME>
   ```
10. 启动服务:
    ```console
    $ sudo systemctl start angie
    ```
11. 要在服务器重启后自动启动 Angie:
    ```console
    $ sudo systemctl enable angie
    ```

<a id="install-astrase-oss"></a>

### Astra SE

1. 安装添加 Angie 仓库所需的前置软件包:
   ```console
   $ sudo apt-get update
   $ sudo apt-get install -y ca-certificates curl lsb-release
   ```
2. 下载 Angie 仓库的公钥用于软件包验证:
   ```console
   $ sudo curl -o /etc/apt/trusted.gpg.d/angie-signing.gpg \
               https://angie.software/keys/angie-signing.gpg
   ```
3. 添加 Angie 仓库:
   ```console
   $ echo "deb https://download.angie.software/angie/astra-se/$(egrep -o \
          '[0-9]+.[0-9]+' /etc/astra_version) unstable main" \
          | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```
4. 更新仓库索引:
   ```console
   $ sudo apt-get update
   ```
5. ( *可选*) 当运行封闭软件环境 ([CSE](https://wiki.astralinux.ru/pages/viewpage.action?pageId=41190634)) 时,
   安装用于 Angie 二进制文件验证的密钥软件包:
   ```console
   $ sudo apt-get install -y angie-digsig-key
   ```

   更新 CSE:
   ```console
   $ sudo update-initramfs -uk all
   ```

   然后 **重启服务器**:
   ```console
   $ sudo shutdown -r now
   ```
6. 安装 Angie 软件包:
   ```console
   $ sudo apt-get install -y angie
   ```
7. ( *可选*) 安装您需要的任何 [额外](#install-extras-oss) 软件包:
   ```console
   $ sudo apt-get install -y <PACKAGE NAME>
   ```

<a id="install-deb-oss"></a>

### Debian, Ubuntu

1. 安装添加 Angie 仓库所需的前置软件包:
   ```console
   $ sudo apt-get update
   $ sudo apt-get install -y ca-certificates curl
   ```
2. 下载 Angie 仓库的公钥用于软件包验证:
   ```console
   $ sudo curl -o /etc/apt/trusted.gpg.d/angie-signing.gpg \
               https://angie.software/keys/angie-signing.gpg
   ```
3. 添加 Angie 仓库:
   ```console
   $ echo "deb https://download.angie.software/angie/$(. /etc/os-release && echo "$ID/$VERSION_ID $VERSION_CODENAME") main" \
       | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```
4. 更新仓库索引:
   ```console
   $ sudo apt-get update
   ```
5. 安装 Angie 软件包:
   ```console
   $ sudo apt-get install -y angie
   ```
6. ( *可选*) 安装您需要的任何 [额外](#install-extras-oss) 软件包:
   ```console
   $ sudo apt-get install -y <PACKAGE NAME>
   ```

<a id="install-osnova-oss"></a>

### OSNova

1. 安装添加 Angie 仓库所需的前置软件包:
   ```console
   $ sudo apt-get update
   $ sudo apt-get install -y ca-certificates curl
   ```
2. 下载 Angie 仓库的公钥用于软件包验证:
   ```console
   $ sudo curl -o /etc/apt/trusted.gpg.d/angie-signing.gpg \
               https://angie.software/keys/angie-signing.gpg
   ```
3. 添加 Angie 仓库:
   ```console
   $ echo "deb https://download.angie.software/angie/osnova/$(egrep -o \
          '[0-9]*' /etc/osnova_version | head -1) \
          $(. /etc/os-release && echo "$VERSION_CODENAME") main" \
          | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```
4. 更新仓库索引:
   ```console
   $ sudo apt-get update
   ```
5. 安装 Angie 软件包:
   ```console
   $ sudo apt-get install -y angie
   ```
6. ( *可选*) 安装您需要的任何 [额外](#install-extras-oss) 软件包:
   ```console
   $ sudo apt-get install -y <PACKAGE NAME>
   ```

<a id="install-freebsd-oss"></a>

### FreeBSD

1. 要添加 Angie 仓库,请创建目录:
   ```console
   $ sudo mkdir -p /usr/local/etc/pkg/angie/ /usr/local/etc/pkg/repos/
   ```
2. 要配置仓库,请创建名为 `/usr/local/etc/pkg/repos/angie.conf` 的文件,
   内容如下:
   ```console
   angie: {
      url: "https://download.angie.software/angie/freebsd/${VERSION_MAJOR}/${ARCH}",
      signature_type: "pubkey",
      pubkey: "/usr/local/etc/pkg/angie/angie-signing.rsa",
      enabled: yes
   }
   ```
3. 下载 Angie 仓库的公钥用于软件包验证:
   ```console
   $ sudo curl -o /usr/local/etc/pkg/angie/angie-signing.rsa \
               https://angie.software/keys/angie-signing.rsa
   ```
4. 更新仓库索引:
   ```console
   $ sudo pkg update
   ```
5. 安装 Angie 软件包:
   ```console
   $ sudo pkg install -r angie -y angie
   ```
6. ( *可选*) 安装您需要的任何 [额外](#install-extras-oss) 软件包:
   ```console
   $ sudo pkg install -r angie -y <PACKAGE NAME>
   ```
7. 启动服务:
   ```console
   $ sudo service angie start
   ```
8. 设置服务器重启后自动启动 Angie:
   ```console
   $ sudo sysrc angie_enable=YES
   ```

#### NOTE
由于 FreeBSD 软件包管理器可能无法正确确定最新版本,
请使用以下方法更新已安装的软件包:

```console
$ sudo pkg upgrade `pkg search -r angie angie-[0-9] | sort -Vr | head -1 | awk {'print $1'}`
```

<a id="install-opensuse-oss"></a>

### openSUSE

1. 要添加仓库,请创建名为 `/etc/zypp/repos.d/angie.repo` 的文件,
   内容如下:
   ```ini
   [angie]
   name=Angie repo
   baseurl=https://download.angie.software/angie/opensuse/$releasever_major/
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```
2. 更新仓库索引:
   ```console
   $ sudo zypper refresh
   ```
3. 安装 Angie 软件包:
   ```console
   $ sudo zypper install -y angie
   ```
4. ( *可选*) 安装您需要的任何 [额外](#install-extras-oss) 软件包:
   ```console
   $ sudo zypper install -y <PACKAGE NAME>
   ```
5. 启动服务:
   ```console
   $ sudo systemctl start angie
   ```
6. 设置服务器重启后自动启动 Angie:
   ```console
   $ sudo systemctl enable angie
   ```

<a id="install-extras-oss"></a>

## 额外软件包

除了提供基本功能的软件包外,
我们还发布了一些额外的软件包,
包括我们自己的软件包和从精选的第三方源构建的软件包。

<a id="install-console-light-oss"></a>

### Console Light 网页面板

Console Light 是一个用于 Angie 的轻量级网页监控面板,
在我们的仓库中以 `angie-console-light` 发布。
它的安装方式与上述步骤中的 `angie` 软件包相同;
配置步骤请参见 [Console Light Web 监控面板](https://cn.angie.software//angie/docs/configuration/monitoring.md#monitoring)。

<a id="install-dynamicmodules-oss"></a>

### 动态模块

为了扩展 Angie 的基本功能,
您可以添加各种动态模块。
模块可以针对相应版本的 Angie [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild),
但从我们的仓库获取现成的软件包会更容易:

| [angie-module-image-filter](https://cn.angie.software//angie/docs/configuration/modules/http/http_image_filter.md#http-image-filter)                                                                                                     | 为 JPEG、GIF、PNG 和 WebP 图像添加转换功能。                                                                             |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
| angie-module-njs:<br/>[JS](https://cn.angie.software//angie/docs/installation/external-modules/http_js.md#http-js) (HTTP),<br/>[JS](https://cn.angie.software//angie/docs/installation/external-modules/stream_js.md#stream-js) (stream) | 允许在 Angie 配置中分别在 `http` 和 `stream` 上下文中<br/>使用 njs(JavaScript 子集)。                                          |
| [angie-module-perl](https://cn.angie.software//angie/docs/configuration/modules/http/http_perl.md#http-perl)                                                                                                                             | 允许使用 Perl 编写 `location` 和变量处理程序,<br/>以及从 SSI 调用 Perl。                                                       |
| [angie-module-wamr](https://cn.angie.software//angie/docs/configuration/modules/wasm/wasm_wamr.md#wasm-wamr)                                                                                                                             | 启用与 [WebAssembly Micro Runtime](https://github.com/bytecodealliance/wasm-micro-runtime)<br/>的集成以执行 WASM 代码。 |
| [angie-module-wasm](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#wasm-core)                                                                                                                                 | 添加核心 WASM 支持。                                                                                               |
| [angie-module-wasmtime](https://cn.angie.software//angie/docs/configuration/modules/wasm/wasm_wasmtime.md#wasm-wasmtime)                                                                                                                 | 启用与 [Wasmtime](https://wasmtime.dev/)<br/>运行时的集成以执行 WASM 代码。                                                |
| [angie-module-xslt](https://cn.angie.software//angie/docs/configuration/modules/http/http_xslt.md#http-xslt)                                                                                                                             | 添加过滤器以使用 XSLT 样式表转换 XML 响应。                                                                                 |

要在 [配置](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile) 中使用已安装的模块,
请在 `main` 上下文中使用 [load_module](https://cn.angie.software//angie/docs/configuration/modules/core.md#load-module) 指令加载它:

```nginx
load_module modules/<module name>.so;
```

还有大量的 [第三方模块](https://cn.angie.software//angie/docs/installation/external-modules/index.md#install-thirdpartymodules) 可用。


# https://cn.angie.software/angie/docs/installation/external-modules/otel.md

<!-- review: finished -->

<a id="external-otel"></a>

# OTel

OTel 模块提供对 OpenTelemetry 分布式追踪的支持。
该模块支持 W3C 上下文传播和 OTLP/gRPC 导出协议。

<a id="installation-21"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-otel`
- Angie PRO：`angie-pro-module-otel`

<a id="loading-the-module-21"></a>

## 加载模块

要使用该模块，必须在 `main{}` 上下文中加载它：

```nginx
load_module modules/ngx_otel_module.so;
```

<a id="configuration-example-95"></a>

## 配置示例

```nginx
http {
    otel_exporter {
        endpoint localhost:4317;
    }

    server {
        listen 80;

        location / {
            otel_trace         on;
            otel_trace_context inject;

            proxy_pass http://backend;
        }
    }
}
```

<a id="additional-information-22"></a>

## 更多信息

详细文档和源代码可在以下位置获取：
[https://github.com/nginxinc/nginx-otel](https://github.com/nginxinc/nginx-otel)


# https://cn.angie.software/vacancies/partner-account-manager.md

# 合作伙伴经理

我们是 Angie Software 团队。公司的核心成员是参与了 nginx 早期开发的资深工程师，他们如今正在打造 nginx 的演进继任者——Angie。我们的产品已经在全球范围内获得越来越多的认可，我们也为自己设定了一个雄心勃勃的目标：超越 F5、Citrix、Radware 这样的行业巨头。

我们的文化是非正式的、扁平的：大家平等交流，没有官僚作风，也没有多余的繁文缛节。决策迅速做出，论据比头衔更重要。

## 您将做什么：

- 维护并发展现有商业合作伙伴关系：您将是关键联系人，负责保持持续的沟通，帮助合作伙伴成长，让他们把 Angie 视为自身业务的战略资产；
- 主导全流程交易——从条款洽谈、pre-sale 活动，到发货、续约和 upsale，为合作伙伴和最终客户提供无缝的合作体验；
- 与分销商建立关系，并联合开展市场推广（网络研讨会、文章、邮件推广），通过合作渠道提升 Angie 的知名度；
- 负责合同与法务事项：合同审定、NDA、特殊条款的协商——让合作伙伴感受到我们的速度与可靠；
- 发展技术合作：发起兼容性测试，推进合作项目，挖掘联合获客的潜力，扩展 Angie 的生态；
- 管理战略性 OEM 关系（例如与 RedOS），在这类关系中 Angie 是供应商伙伴的"客户"——您将构建双赢的协同效应，并确保服务器操作系统的稳定采购。

## 我们想招的人：

- 把合作伙伴关系视为产品增长的战略杠杆，而不仅仅是合同流转和邮件推送；
- 拥有 4 年以上 IT 行业销售或合作伙伴管理经验，理解复杂基础设施软件的特点（或愿意快速、深入地学习）；
- 善于与各类受众——从技术专家到商务总监和企业主——建立可信赖的长期关系；
- 在出色的沟通能力之外，还具备高度的条理性和对细节的关注：需要同时推进多笔交易而不丢失焦点；
- 思维主动：不只是回应需求，还会提出改善合作伙伴体验或开拓新增长点的建议；
- 希望为产品的规模化贡献个人力量。

## 我们提供：

- 真正影响产品商业成功、推动合作伙伴生态发展的机会；
- 在一支精简、业内公认的专家团队中工作，您的声音和想法真正被重视，没有官僚作风；
- 扁平结构，您将直接与技术和商务负责人协作；
- 充足的职业成长空间，配以有竞争力的薪资、补充医疗保险、报销培训和会议费用；
- 已认证的 IT 企业资质和透明的工作条件。

**工作形式：** 混合办公或全坐班（可商议），萨维奥洛夫斯卡娅（Савёловская）地铁站，Factoria 商务中心。

如果您感兴趣，请将英文简历发送至 [hr@wbsrv.ru](mailto:hr@wbsrv.ru)。

#### NOTE
我们仅接受英文简历，请用英文提交您的简历。


# https://cn.angie.software/partners.md

# 合作伙伴

## 商业合作伙伴

我们通过值得信赖的合作伙伴合作，向他们供应我们的产品和专业服务。

![](../../_images/corp_part/commercial/syssoft.svg)![](../../_images/corp_part/commercial/softline.svg)![](../../_images/corp_part/commercial/k2tex.svg)![](../../_images/corp_part/commercial/rubytech.svg)![](../../_images/corp_part/commercial/softmap.svg)![](../../_images/corp_part/commercial/innostage.svg)![](../../_images/corp_part/commercial/ocs.svg)![](../../_images/corp_part/commercial/axoft.svg)![](../../_images/corp_part/commercial/jet.svg)

如果您希望通过其他供应商购买我们的解决方案，请通过 [info@wbsrv.ru](mailto:info@wbsrv.ru) 联系我们。

## 技术合作伙伴

我们积极与平台制造商、软件和硬件系统、操作系统及应用程序合作，确保 Angie 与最终产品的集成及其完全兼容。

![](../../_images/corp_part/commercial/astralinux.svg)![](../../_images/corp_part/commercial/basealt.svg)![](../../_images/corp_part/commercial/redos.svg)![](../../_images/corp_part/commercial/msvsphere.svg)![](../../_images/corp_part/commercial/mcst.svg)

我们邀请软件开发人员、硬件制造商和培训中心与我们合作。"技术合作伙伴"身份授予与我们的产品共同创建综合解决方案并认证其兼容性的公司。

有关技术合作伙伴关系的讨论，请通过 [info@wbsrv.ru](mailto:info@wbsrv.ru) 联系我们。


# https://cn.angie.software/news/integrations/platforma-vebmonitoreks-sovmestima-s-rossijskim-veb-serverom-Angie-Pro.md

# WebmonitorEx平台与俄罗斯网络服务器Angie PRO实现兼容

*06.09.2023*

WebmonitorEx已确保其平台与俄罗斯网络服务器Angie PRO的兼容性。这为企业提供了更高的可靠性和安全性，以防御网络威胁。

WebmonitorEx已确保其平台与俄罗斯网络服务器Angie PRO的兼容性。这为企业提供了更高的可靠性和安全性，以防御网络威胁。

客户可以使用由国产产品组成的综合解决方案——Web应用程序保护平台和负载均衡器。

WebmonitorEx平台是一个强大的解决方案，用于保护Web资源和API免受攻击，分析Web流量，为受保护资源形成个性化配置文件，并即时阻止任何恶意请求。该平台原生支持HTTP/2.0、WebSockets、REST API、JSON、XML、SOAP、gRPC，可与SIEM系统集成，具备攻击源识别（地理位置、Tor、数据中心、代理）、集中化保护管理、灵活的事件通知系统以及复杂嵌套协议解析等功能。该产品已被列入国产软件注册表，编号为8985。

俄罗斯网络服务器Angie PRO已通过国产操作系统的兼容性认证：RED OS、Astra Linux Special Edition和Alt Server 10。Angie与Nginx完全兼容，使用户能够在不产生重大成本和服务中断的情况下过渡到国产解决方案。Angie PRO网络服务器已被列入国产软件注册表，编号为17604。

WebmonitorEx持续发展其技术并与新平台集成，以确保能够最便捷地部署到客户的基础设施中。

据两家公司表示，这种技术合作提供了必要的可靠性和完全的进口替代（与国产操作系统配合使用时）。

**参考信息**

WebmonitorEx是一家俄罗斯开发商，开发了同名的Web应用程序、微服务和API保护平台。十多年来，WebmonitorEx团队一直在帮助大型企业抵御网络攻击。


# https://cn.angie.software/news/integrations/poluchili-sertifikat-sovmestimosti-s-os-Alt-SP-Server.md

# 获得Alt SP Server操作系统兼容性证书

*10.11.2023*

该证书不仅证实了测试的成功完成，也是我们产品对部分客户实施的必需文件。

![Alternative text](../../_images/news/poluchili-sertifikat-sovmestimosti-s-os-Alt-SP-Server.jpeg)![Alternative text](../../_images/news/poluchili-sertifikat-sovmestimosti-s-os-Alt-SP-Server.jpeg)

大家好！

近期，Angie PRO获得了Alt SP Server操作系统最新FSTEC版本（第10版）的认证证书。

此兼容性证书不仅正式证实了与该操作系统测试的成功完成，同时也是我们产品在部分客户实施过程中的必需文件。

我们也考虑到了仍在使用Alt SP Server第8版的保守用户，因此也获得了该版本的兼容性证书。


# https://cn.angie.software/news/integrations/popolnyaem-kollektsiyu-storonnih-modulei.md

# 扩充第三方模块库：新增ModSecurity

*04.12.2023*

大家好！在我们为即将发布的Angie和Angie PRO网络服务器更新版本进行工作的同时，我们也在持续扩充我们的第三方模块库。

![Alternative text](../../_images/news/popolnyaem-kollektsiyu-storonnih-modulei.webp)![Alternative text](../../_images/news/popolnyaem-kollektsiyu-storonnih-modulei.webp)

大家好！

在我们为即将发布的Angie和Angie PRO网络服务器更新版本进行工作的同时，我们也在持续扩充我们的第三方模块库。今天，我们新增了ModSecurity，这是一个最初为Apache开发，后来与Nginx整合的流行Web应用防火墙(WAF)。

之前，俄罗斯知名WAF产品WebmonitorX和Nemesida的开发者已经为我们的网络服务器提供了支持。

另外，我们不仅在收集第三方模块，还致力于为它们提供完整的安装和配置说明。我们预计ModSecurity将成为我们未来发布模块的典范。


# https://cn.angie.software/news/articles/populyarizuem-opensource-v-rossii.md

# 在俄罗斯推广开源

*14.09.2023*

我们与科学出版物N+1的朋友们一起启动了一个在俄罗斯推广开源的特别项目。

![Alternative text](../../_images/news/populyarizuem-opensource-v-rossii.jpeg)![Alternative text](../../_images/news/populyarizuem-opensource-v-rossii.jpeg)

我们与科学出版物N+1的朋友们一起启动了一个在俄罗斯推广开源的特别项目。非常感谢所有支持该项目并参与其中的人们——提供评论、提出批评意见和建议新主题。第一篇 [概述文章已经发布在N+1网站上](https://nplus1.ru/material/2023/09/13/open-source-basics)。


# https://cn.angie.software/angie/docs/installation/external-modules/postgres.md

<!-- review: finished -->

<a id="external-postgres"></a>

# Postgres

Postgres 模块提供对 PostgreSQL 数据库的直接支持。

<a id="installation-22"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-postgres`
- Angie PRO:`angie-pro-module-postgres`

<a id="loading-the-module-22"></a>

## 加载模块

在 `main{}` 上下文中加载模块:

```nginx
load_module modules/ngx_postgres_module.so;
```

<a id="configuration-example-96"></a>

## 配置示例

```nginx
http {
    upstream database {
        postgres_server 127.0.0.1 dbname=ang_test
                         user=ang_test password=ang_test;
    }

    server {
        listen 80;
        postgres_output text;

        location /create {
            postgres_pass database;
            postgres_query "CREATE TABLE cats (id integer, name text)";
        }

        location /insert {
            postgres_pass database;
            postgres_query "INSERT INTO cats (id, name) VALUES ($arg_id, '$arg_name')";
        }

        location /select {
            postgres_pass database;
            postgres_query "SELECT name FROM cats WHERE id=$arg_id";
        }
    }
}
```

<a id="additional-information-23"></a>

## 其他信息

详细文档和源代码可在以下位置获取:
[https://github.com/FRiCKLE/ngx_postgres](https://github.com/FRiCKLE/ngx_postgres)


# https://cn.angie.software/vacancies/pre-sale-engineer.md

# Pre-sale 工程师

我们是 Angie Software 团队。公司的核心成员是参与了 nginx 早期开发的资深工程师，他们如今正在打造 nginx 的演进继任者——Angie。我们的产品已经在全球范围内获得越来越多的认可，我们也为自己设定了一个雄心勃勃的目标：超越 F5、Citrix、Radware 这样的行业巨头。

我们的文化是非正式的、扁平的：大家平等交流，没有官僚作风，也没有多余的繁文缛节。决策迅速做出，论据比头衔更重要。

## 您将做什么：

- 成为 Angie 面向客户和合作伙伴的技术代言人：识别他们真正的需求，而不仅仅是回答问题，并提出能解决基础设施实际痛点的方案；
- 进行深入的技术演讲和产品演示，让最复杂的网络概念也能让受众清晰理解、信服；
- 从头到尾跟进试点项目；
- 从客户和合作伙伴那里收集反馈，揭示瓶颈，并基于真实使用经验影响产品发展方向。

## 我们想招的人：

- 把 pre-sale 视为工程与客户信任交汇处的战略角色，而不仅仅是"回答技术问题"；
- 拥有高等技术教育背景，并有 3 年以上的实际工程经验，背后是与网络、协议和基础设施软件打交道的真实经历；
- 理解网络协议和不同 OSI 层级上的负载均衡如何工作；有 ADC 解决方案（F5、Citrix、Radware）经验是很大的加分项，能让您快速进入状态；
- 在任何受众面前都自信从容：既能为技术专家做演示，也能与业务决策者谈判，灵活调整语言和论证方式；
- 真诚地以客户为中心，同时具备工程师的诚实：不卖"空气"，而是帮助客户找到最佳方案，哪怕这需要非常规的做法；
- 希望与研发、产品和销售团队并肩协作，影响公司产品在市场上的发展。

## 我们提供：

- 真正成为技术与客户之间关键纽带的机会：您的专业能力将直接影响公司的商业成功；
- 在一支精简、业内公认的专家团队中工作，团队重视深度、主动性，以及在与客户对话中承担技术领导力的意愿；
- 扁平结构，远离官僚作风：您将做出真正的技术决策，而不是简单地复述脚本；
- 充足的职业成长空间，配以有竞争力的薪资、补充医疗保险、报销培训和会议费用；
- 已认证的 IT 企业资质和透明的工作条件。

**工作形式：** 混合办公或全坐班（可商议），萨维奥洛夫斯卡娅（Савёловская）地铁站，Factoria 商务中心。

如果您感兴趣，请将英文简历发送至 [hr@wbsrv.ru](mailto:hr@wbsrv.ru)。

#### NOTE
我们仅接受英文简历，请用英文提交您的简历。


# https://cn.angie.software/news/interviews/prekrasnoe-intervyu-gluboko-uvazhaemogo-ivana-panchenko.md

# 备受尊敬的Ivan Panchenko的精彩访谈

*07.02.2024*

从第25分钟开始，Ivan [谈论](https://www.youtube.com/watch?app=desktop&v=d9joPLRULeA) 我们的事情，
虽然他没有直接提到我们的名字。不过，这个一小时长的访谈中其他内容对所有从事开源项目的人来说都同样重要。

![Alternative text](../../_images/news/prekrasnoe-intervyu-gluboko-uvazhaemogo-ivana-panchenko.jpeg)![Alternative text](../../_images/news/prekrasnoe-intervyu-gluboko-uvazhaemogo-ivana-panchenko.jpeg)

从第25分钟开始，Ivan [谈论](https://www.youtube.com/watch?app=desktop&v=d9joPLRULeA) 我们的事情，
虽然他没有直接提到我们的名字。不过，这个一小时长的访谈中其他内容对所有从事开源项目的人来说都同样重要。

来自Postgres Professional的Ivan Panchenko和Oleg Bartunov是我们的资深前辈，他们及时给予我们宝贵建议，帮助我们避开了那些对他们来说显而易见但当时我们却看不到的陷阱。


# https://cn.angie.software/legal/privacy-policy.md

# 运营商个人数据处理政策

2024年08月01日第2版

本政策（**政策**）阐述了有限责任公司“Web Server”（统一国家注册号（ОГРН）1227700436578，以下简称\*\*运营商\*\*）在处理个人数据时所遵循的基本原则、执行的处理程序，以及为确保个人数据安全所采取的各项措施。

本个人数据处理政策的目的是保障个人数据主体在现行法律框架下的合法权益。
本政策根据俄罗斯联邦宪法、
2006年7月27日第149-ФЗ号《信息、信息技术与信息保护法》、
2006年7月27日第152-ФЗ号《个人数据法》
以及俄罗斯联邦的其他规范性法律文件制定。

1. **主要术语**

1.1. **数据中心**——专门从事服务器和网络设备托管、出租（包括虚拟服务器）的组织，运营商利用该组织来存储和处理个人数据。

1.2. **个人数据保密性**——获得数据访问权的人在未经个人数据主体同意的情况下，不得向第三方披露或传播这些数据，除非法律另有规定。

1.3. **客户**——依据相关合同获得使用运营商拥有著作权的软件（如Angie PRO、ANIC等）的权利，并有权根据相应合同获得服务的法人实体。

1.4. **登录名（Login）**——个人数据主体在网站注册时所填写的电子邮箱地址。

1.5. **个人数据处理**——使用自动化工具或不使用自动化工具对个人数据进行的任何操作或一组操作，包括收集、记录、系统化、积累、存储、更新（修改）、检索、传输（分发、提供、访问）、去标识化、封锁、删除、销毁等。

1.6. **密码（Password）**——由个人数据主体自行选择的字符组合，与电子邮箱一起，在使用网站时对账户进行身份验证。

1.7. **个人数据（数据）**——与已确定或可确定的自然人（个人数据主体）直接或间接相关的任何信息。

1.8. **个人信息**——个人数据主体在网站上自行发布的与其相关的任何信息，包括个人数据，如姓名、姓氏、父名、电话号码、电子邮箱地址，以及在使用网站过程中自动传输给运营商的信息，包括IP地址、cookies文件等。

1.9. **个人资料（Profile）**——网站上的相关版块，包含个人数据主体的个人信息，使用登录名和密码即可访问。

1.10. **注册**——个人数据主体在网站上通过填写注册表单完成的注册操作。

1.11. **网站**——位于Internet网络中的support.angie.software（技术支持网站及其用于收集个人数据的页面）。

1.12. **个人数据主体**——运营商处理的个人数据所指向的自然人。

1.13. **服务**——针对运营商拥有独家权利的软件所提供的技术支持、维护与软件正常运行相关的一系列服务，主要面向客户的员工（代表）。

1. **个人数据处理的目的**

2.1. 运营商为实现特定的、事先确定的合法目的而处理个人数据。

2.2. 运营商处理个人数据主体个人数据的目的如下：

- 为用户提供使用网站的可能性；
- 验证个人数据主体的身份；
- 与个人数据主体建立反馈，包括发送通知、提供服务、处理其请求和申请；
- 改善所提供服务的质量，优化网站的使用。

2.3. 运营商采取措施以遵守个人数据领域的法律要求，不在法律禁止或无必要实现运营商明确目的的情况下处理个人数据。

1. **个人数据处理的法律依据**

3.1. 运营商处理个人数据的法律依据包括：

- 1. 个人数据主体对其数据进行处理的同意；
- 1. 涉及个人数据主体（作为一方授权人）的合同。

3.2. 在网站上收集和处理个人数据的同意，体现为在网站相应的界面表单中填写个人数据，并通过点击网站上的界面按钮（标有"sign in"（登录）或"open a new ticket"（发送新请求）或"Check Ticket Status"（查看请求状态））确认其真实性。

1. **处理的数据类别和处理范围**

4.1. 运营商处理以下个人数据：

- 名（имя）；
- 姓（фамилия）；
- 父名（отчество）；
- 电话号码；
- 电子邮箱地址。

4.2. 运营商确保所处理的个人数据范围与所声明的处理目的相符；不进行与收集目的不相容的个人数据处理，也不处理与所声明目的无关或过量的个人数据。

4.3. 运营商不处理根据2006年7月27日第152-ФЗ号《个人数据法》中定义的特殊类别个人数据。

1. **个人数据主体的权利**

5.1. 个人数据主体有权：

- 获取与处理其个人数据相关的信息；
- 访问并查阅其个人数据，包括有权免费获得包含其个人数据的记录副本；
- 要求删除或更正不准确或不完整的个人数据；
- 获取有关受托处理其个人数据的人的信息；
- 获取有权依据与运营商签订的合同或法律规定而可访问或可获取个人数据的人员信息（不包括运营商员工）；
- 获取法律规定的其他信息。

5.2. 关于个人数据存在与否的信息由运营商向个人数据主体提供，但其中不包含与其他个人数据主体相关的数据。

5.3. 个人数据主体有权通过向运营商提交一份任意形式的书面申请来撤回其对个人数据处理的同意。如果个人数据主体撤回其对个人数据处理的同意，但在俄罗斯联邦法律规定的情况下，运营商可在具有法律依据的条件下继续处理个人数据，而无需获得个人数据主体的同意。

5.4. 如个人数据主体撤回同意，且在无法律依据继续处理个人数据的情况下，运营商应停止处理该数据（确保受托处理该数据的其他人员也停止处理），并销毁或去标识化这些数据（确保对这些数据的销毁或去标识化）。

1. **个人数据主体咨询的响应程序**

6.1. 个人数据主体可通过电子邮件方式向运营商发送有关处理其个人数据的请求，邮箱地址：[support@angie.software](mailto:support@angie.software)。

6.2. 该请求应包括：

- 个人数据主体或其代表的姓氏、名、父名；
- 个人数据主体及其代表（如果请求由代表提出）的身份证件号码、签发日期、签发机关等信息；
- 证明个人数据主体与运营商存在关系或其他方式证明运营商正在处理其个人数据的相关信息；
- 个人数据主体或其代表的签字；
- 证明代表授权的相关文件。运营商有权要求提供额外信息以确认提出请求人员的身份。

6.3. 运营商不处理通过电话或除了本节中明确指出的方式之外提交的任何与处理个人数据相关的请求。

6.4. 无论对于请求的审核结果如何，运营商都会向个人数据主体（或其代表）发送书面回复。回复期限自收到请求之日起不得超过10（十）个工作日。

6.5. 自个人数据主体或其代表提供证据表明个人数据不完整、不准确或已过期之日起7（七）个工作日内，运营商应做出必要更正。

6.6. 如发现个人数据被违法处理，运营商应对违法处理的数据进行封锁或确保被受托处理的人员进行封锁，以便在调查其处理合法性期间暂停使用这些数据。如果确认运营商或其受托人员确有违法处理个人数据的事实，运营商应在确认之日起3（三）个工作日内停止违法处理或确保受托人员停止违法处理个人数据。

1. **个人数据处理的程序与条件**

7.1. 个人数据主体通过本政策第3.2款所述方式，同意对其个人数据进行处理。

7.2. 个人数据处理的方式：运营商可通过以下行动处理个人数据：收集、系统化、积累、存储、更新（修改）、去标识化、封锁、销毁。

7.3. 运营商既可以使用自动化工具，也可以不使用自动化工具来处理个人数据。

7.4. 运营商可将其个人数据信息系统置于数据中心或云计算基础设施内。若根据与数据中心签订的合同，数据中心的工作人员被禁止访问运营商所处理的数据，则运营商不视此为委托数据中心处理个人数据，也无需征得个人数据主体的同意。与数据中心（提供方）的合同中均会明确规定对个人数据的保密和安全要求。

7.5. 在接到检察院、执法部门、侦查及调查机构、安全机构、政府劳动监察部门等依法有权在监督和检查合规性方面提出信息请求的情形下，不需要征得个人数据主体对提供其个人数据的同意。

1. **个人数据存储期限的限制**

8.1. 个人数据主体的个人数据处理，将持续至满足以下任意一个条件：

- 网站上个人数据主体的个人资料被删除；
- 个人数据主体撤回其对个人数据处理的同意。

8.2. 一旦出现第8.1款所述条件或其中任何一个条件，运营商将：

- 删除个人数据；或
- 对数据进行去标识化，使其不再与特定的个人数据主体关联。

8.3. 数据删除程序：

- 纸质媒介——在负责个人数据处理人员以及其他有权接触个人数据的运营商员工的见证下销毁；
- 电子媒介——从媒介中删除数据，并保留有关删除的记录（删除日志）。

1. **个人数据安全保障**

9.1. 在处理个人数据时，运营商采取法律、组织和技术措施，防范对数据的非法或意外访问、销毁、修改、封锁、复制、传播、提供以及其他非法行为。保障个人数据安全是运营商业务的组成部分。通过阻止未经授权或偶然的访问来实现数据安全。

9.2. 运营商可聘请拥有相应技术保护机密信息许可证以及其他在俄罗斯联邦法律要求下完成特定任务所需的许可证的机构，来协助选择并实施保护个人数据的方法和手段。

9.3. 运营商采取的法律措施包括：

- 制定符合俄罗斯法律要求的运营商内部规章制度，包括本政策；
- 放弃使用与本政策中既定目标或法律要求不符的任何个人数据处理方式。

9.4. 运营商采取的组织措施包括：

- 由运营商指派一名负责人，负责组织数据处理工作；
- 限制可访问个人数据的运营商员工范围，建立相应的访问控制系统；
- 让直接从事个人数据处理的运营商员工熟悉俄罗斯联邦在个人数据方面的法律规定，包括有关个人数据保护的要求；
- 限制无关人员进入运营商工作场所，防止其进入存放并处理个人数据以及放置用于处理个人数据的技术设备的区域。

9.5. 运营商采取的技术措施包括：

- 检测恶意软件（使用防病毒程序）；
- 监测对运营商个人数据信息系统的入侵行为，以防或排查可能破坏个人数据安全的风险；
- 确保运营商员工对个人数据信息系统的授权访问；
- 评估已采取的个人数据安全保障措施的有效性；
- 使用安全的网络交互方式。

1. **数据库位置**

10.1. 在收集个人数据时，运营商确保对俄罗斯联邦公民的个人数据进行记录、系统化、积累、存储、更新（修改）和检索，且使用位于俄罗斯联邦境内的数据库。如果运营商无法确认个人数据主体的国籍，则默认假定在俄罗斯联邦境内获取的数据来自俄罗斯公民。

1. **技术信息及Cookies文件**

11.1. Cookies文件是网站访问者的电脑或其他设备上可能存储的文件或信息片段。此类文件中可能包含各种信息，例如浏览器类型、操作系统、语言设置以及其他页面个性化设置，或有关网站使用情况的数据。

11.2. Cookies文件用于根据用户偏好调整网站页面内容，优化网站运行。通过Cookies可识别用户设备并根据其个人需求进行网站浏览设置；Cookies文件还用于处理网站的使用统计数据，并帮助在用户登录网站后保持会话状态，无需在每个网页重复输入登录名和密码。

Cookies文件被用来识别网站用户。基于这些文件，运营商能够分析访问者对网站的使用情况，从而对网站进行进一步的功能改进。

11.3. 运营商收集以下类型的Cookies文件：

-  *必要Cookies文件*：这些文件是网站运作所必需的，没有它们，网站的部分功能将无法运行。
-  *功能性Cookies文件*：用于识别访问者偏好，并据此对网站进行调整。功能性Cookies文件可记住网站的个性化设置并存储访问者和个人数据主体提供的信息（如登录名、用户名、语言及其他偏好）。这些功能让网站使用更便捷。
-  *分析和性能Cookies文件*：包含用户如何使用网站的信息，用于识别访问网站的重复使用场景，并帮助分析使用过程中出现的错误。这些Cookies文件并不识别个人身份，所有信息都是匿名的。

11.4. 网站访问者可随时更改网站收集Cookies文件的相关设置。

11.5. 大多数网络浏览器初始设置均为自动接受Cookies文件。网站访问者可更改浏览器设置，使其在发送Cookies文件到相应设备时进行阻止或预警。管理Cookies文件的方法有多种。

如果网站访问者在不同的设备（如电脑、智能手机、平板等）上访问本网站，则需要确保在每个设备的浏览器中都按照其Cookies偏好进行配置。若要了解如何通过浏览器或设备管理Cookies文件，可参考浏览器开发商或设备制造商提供的使用说明。

1. **附则**

12.1. 运营商通过在网站上发布本政策，为所有人提供不受限制的访问权。

12.2. 运营商的其他权利和义务由俄罗斯联邦在个人数据领域的法律予以确定。

12.3. 本政策视实际需要进行修订。当国际法或俄罗斯联邦个人数据领域的法律发生强制性变动时，须对本政策进行强制性审查。在对本政策进行修改时，将充分考虑运营商在信息基础设施方面的实际情况以及俄罗斯联邦关于数据保护的执法实践。

12.4. 网站上集成了Yandex.Metrica，其根据自身的隐私政策收集数据，该隐私政策可通过以下链接获取：[https://yandex.ru/legal/confidential/](https://yandex.ru/legal/confidential/)。

运营商并不单独收集或处理由Yandex.Metrica处理的数据。

有限责任公司“Web Server”（ООО "Веб-Сервер"）
统一国家注册号（ОГРН）：1227700436578
地址：127015，俄罗斯联邦，莫斯科市，维亚茨卡娅街27号7栋
电话：+7 (495) 120 50 33
电子邮箱：[legal@wbsrv.ru](mailto:legal@wbsrv.ru)


# https://cn.angie.software/angie/pro.md

# Angie PRO

Angie PRO 是 Angie 网络服务器的商业版本，具有附加功能、技术支持，并在俄罗斯软件注册处列出。

Angie PRO 是 Angie 网络服务器的商业版本。其功能包括：

- 所有对应 [免费版本](..) 的功能。
- 在企业环境中部署高可靠性应用程序的功能。
- 多层次的专业技术支持服务。
- 在 [俄罗斯软件注册处](https://reestr.digital.gov.ru/reestr/1484113/) 的列名。

客户可以获取适用于俄罗斯和国外操作系统及架构的 [二进制包](https://cn.angie.software//angie/docs/installation/pro_packages.md)。

动态模块用于扩展基本功能。它们已经过测试、编译，并且也可在 [我们的仓库](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-dynamicmodules-pro) 中获取。

**Angie PRO |angie_pro_version|** 于 **|angie_release_date|** 发布。新版本每季度发布一次；重要的修复和改进会及时发布。另请参见 [版本历史](https://cn.angie.software//angie/docs/pro_changes.md)。

您可以在 [我们的网站](https://cn.angie.software//angie/docs/index.md) 上找到完整的文档。

## 为什么选择 Angie PRO?

通过类似 REST 的 [API 接口](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config) 管理代理服务器以进行动态配置；可通过浏览器使用可视监控控制台 [Console Light](https://cn.angie.software//angie/docs/configuration/monitoring.md) 管理服务器。

根据来自代理服务器的 [平均响应时间](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-least-time)，结合 [可配置的平滑因子](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-response-time-factor) 进行负载均衡。

基于反馈的负载均衡，根据变量的值选择服务器；假设该值来自服务器本身，传输 CPU 负载或其他指标。

通过发送周期性 [测试请求](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe) 检查代理服务器的可用性。

附加的粘性绑定模式 [sticky learn](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky)，允许在共享内存中检测和记住会话。

条件 [客户端连接的绑定](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-bind-conn) 与代理服务器的连接，这也允许 NTLM 代理。

允许根据响应的属性将响应放置 [在不同位置](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache)。

## 支持与服务

我们在工作时间提供 [标准](https://cn.angie.software//support/index.md) 支持，以及 24/7 的 [企业](https://cn.angie.software//support/enterprise.md) 支持。我们还为客户的基础设施提供高质量的 [专业服务](https://cn.angie.software//professional-service.md)，包括迁移、适应和优化我们的产品。

此外，我们与合作伙伴共同开发培训课程和认证项目，以便与我们的产品一起使用。

## 附带文档

- [`Angie PRO 安装指南`](https://cn.angie.software//angie/pro/Angie_PRO_|angie_pro_pdf_version|_installation_guide.pdf)
- [`Angie PRO 功能规格`](https://cn.angie.software//angie/pro/Angie_PRO_|angie_pro_pdf_version|_functional_description.pdf)
- [`Angie PRO 操作指南`](https://cn.angie.software//angie/pro/Angie_PRO_|angie_pro_pdf_version|_operating_guide.pdf)

文档也可以在 [我们的网站](../docs/) 上获取。

### 版本存档

- Angie PRO 1.9.1:
  - [`安装指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.9.1_installation_guide.pdf)
  - [`功能规格`](https://cn.angie.software//angie/pro/Angie_PRO_1.9.1_functional_description.pdf)
  - [`操作指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.9.1_operating_guide.pdf)
- Angie PRO 1.9.0:
  - [`安装指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.9.0_installation_guide.pdf)
  - [`功能规格`](https://cn.angie.software//angie/pro/Angie_PRO_1.9.0_functional_description.pdf)
  - [`操作指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.9.0_operating_guide.pdf)
- Angie PRO 1.8.3:
  - [`安装指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.3_installation_guide.pdf)
  - [`功能规格`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.3_functional_description.pdf)
  - [`操作指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.3_operating_guide.pdf)
- Angie PRO 1.8.2:
  - [`安装指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.2_installation_guide.pdf)
  - [`功能规格`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.2_functional_description.pdf)
  - [`操作指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.2_operating_guide.pdf)
- Angie PRO 1.8.1:
  - [`安装指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.1_installation_guide.pdf)
  - [`功能规格`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.1_functional_description.pdf)
  - [`操作指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.1_operating_guide.pdf)
- Angie PRO 1.8.0:
  - [`安装指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.0_installation_guide.pdf)
  - [`功能规格`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.0_functional_description.pdf)
  - [`操作指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.8.0_operating_guide.pdf)
- Angie PRO 1.7.0:
  - [`安装指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.7.0_installation_guide.pdf)
  - [`功能规格`](https://cn.angie.software//angie/pro/Angie_PRO_1.7.0_functional_description.pdf)
  - [`操作指南`](https://cn.angie.software//angie/pro/Angie_PRO_1.7.0_operating_guide.pdf)

## 许可证获取

该软件产品根据商业许可条款分发。有关软件产品的成本、获取条款和许可协议的信息，可通过发送电子邮件至 [info@wbsrv.ru](mailto:info@wbsrv.ru) 获取。


# https://cn.angie.software/angie/docs/pro_changes.md

<!-- review: finished -->

<a id="pro-changes"></a>

# Angie PRO 版本历史

## 2026

<a id="angie-pro-1-11-6"></a>

### Angie PRO 1.11.6

发布日期： 25.05.2026.

<a id="security-pro-1-11-6"></a>

#### 安全性

- 当使用 [rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 指令时，若其正则表达式包含嵌套的 PCRE 捕获，
  且替换字符串引用了多个此类捕获，攻击者在超出攻击者控制的条件下，
  可能导致工作进程崩溃，并且在没有地址空间布局随机化的系统上，
  可能执行任意代码
  ([CVE-2026-9256](https://nvd.nist.gov/vuln/detail/CVE-2026-9256))；
  此修复从 nginx 1.31.1 移植而来。

<a id="packages-pro-1-11-6"></a>

#### 软件包

- 已更新:
  - [angie-pro-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，至版本 0.13.1
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.9
  - [angie-pro-module-testcookie](https://cn.angie.software//angie/docs/installation/external-modules/testcookie.md#external-testcookie)，至版本 7d263d4
  - [angie-pro-module-vod](https://cn.angie.software//angie/docs/installation/external-modules/vod.md#external-vod)，至版本 v1.7.2

<a id="angie-pro-1-11-5"></a>

### Angie PRO 1.11.5

发布日期：15.05.2026.

<a id="security-pro-1-11-5"></a>

#### 安全性

- 当 [rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 指令使用未命名的捕获组（例如 `$1`、`$2`）
  且替换字符串包含 `?` 时，如果其后跟随 [rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5)、[if](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#if) 或 [set](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#set)
  指令，攻击者在超出攻击者控制的条件下，可能导致工作进程崩溃，
  并且在没有地址空间布局随机化的系统上，可能执行任意代码
  ([CVE-2026-42945](https://nvd.nist.gov/vuln/detail/CVE-2026-42945))；
  此修复从 nginx 1.31.0 移植而来。
- 使用 [ssl_ocsp](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-ocsp) 指令时，在处理 DNS
  服务器响应过程中可能发生对先前已释放内存的访问，
  允许攻击者破坏工作进程内存或导致其崩溃
  ([CVE-2026-40701](https://nvd.nist.gov/vuln/detail/CVE-2026-40701))；
  此修复从 nginx 1.31.0 移植而来。
- 使用 HTTP/3 时，攻击者可能伪造 IP
  地址，从而在某些配置中绕过限制或授权
  ([CVE-2026-40460](https://nvd.nist.gov/vuln/detail/CVE-2026-40460))；
  此修复从 nginx 1.31.0 移植而来。
- 当配置了 [scgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-pass) 或 [uwsgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-pass) 时，
  处于中间人（MITM）位置并控制代理服务器响应的攻击者，
  可能导致过度的内存分配或数据越界读取，
  从而向客户端泄露工作进程的内存内容或导致进程崩溃
  ([CVE-2026-42946](https://nvd.nist.gov/vuln/detail/CVE-2026-42946))；
  此修复从 nginx 1.31.0 移植而来。
- 当通过 [charset_map](https://cn.angie.software//angie/docs/configuration/modules/http/http_charset.md#charset-map) 指令使用 UTF-8 解码处理特制响应时，
  工作进程中可能发生越界读取，允许攻击者在超出攻击者控制的条件下，
  向客户端发送有限的工作进程内存内容或导致进程崩溃
  ([CVE-2026-42934](https://nvd.nist.gov/vuln/detail/CVE-2026-42934))；
  此修复从 nginx 1.31.0 移植而来。

<a id="packages-pro-1-11-5"></a>

#### 软件包

- 已更新：
  - [angie-pro-module-auth-totp](https://cn.angie.software//angie/docs/installation/external-modules/auth-totp.md#external-auth-totp)，至版本 1.2.0
  - [angie-pro-module-cache-purge](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge)，至版本 3.0.2
  - [angie-pro-module-keyval](https://cn.angie.software//angie/docs/installation/external-modules/keyval.md#external-keyval)，至版本 0.4.0
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.8
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 v0.46.0
- 已将 [angie-pro-module-dav-ext](https://cn.angie.software//angie/docs/installation/external-modules/dav-ext.md#external-dav-ext) 的源更换为
  [mid1221213/nginx-dav-ext-module](https://github.com/mid1221213/nginx-dav-ext-module) v4.0.1。
- 已将 [angie-pro-module-vod](https://cn.angie.software//angie/docs/installation/external-modules/vod.md#external-vod) 的源更换为
  [dio-az/nginx-vod-module](https://github.com/dio-az/nginx-vod-module) v1.7.1。

<a id="angie-pro-1-11-4"></a>

### Angie PRO 1.11.4

发布日期：25.03.2026.

<a id="security-pro-1-11-4"></a>

#### 安全性

- [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中与客户端的 TLS
  握手可能在 OCSP 拒绝客户端证书的情况下仍然成功
  ([CVE-2026-28755](https://nvd.nist.gov/vuln/detail/CVE-2026-28755))；
  此修复从 nginx 1.29.7 移植而来。
- 在 DAV 模块中，在带有 [alias](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#alias) 指令的 `location` 中处理 COPY 或 MOVE
  请求时可能发生缓冲区溢出，允许攻击者将源路径或目标路径修改到文档根目录之外
  ([CVE-2026-27654](https://nvd.nist.gov/vuln/detail/CVE-2026-27654))；
  此修复从 nginx 1.29.7 移植而来。
- 在 32 位平台上，MP4 模块处理特制文件可能导致工作进程崩溃，
  或可能产生其他潜在影响
  ([CVE-2026-27784](https://nvd.nist.gov/vuln/detail/CVE-2026-27784))；
  此修复从 nginx 1.29.7 移植而来。
- MP4 模块处理特制文件可能导致工作进程崩溃，
  或可能产生其他潜在影响
  ([CVE-2026-32647](https://nvd.nist.gov/vuln/detail/CVE-2026-32647))；
  此修复从 nginx 1.29.7 移植而来。
- 如果在 [Mail](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-mail) 代理模块中使用了 CRAM-MD5 或 APOP 认证方法，
  并且启用了认证重试，则工作进程可能崩溃
  ([CVE-2026-27651](https://nvd.nist.gov/vuln/detail/CVE-2026-27651))；
  此修复从 nginx 1.29.7 移植而来。
- 使用 [Mail](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-mail) 代理模块时，攻击者可以利用 PTR DNS
  记录向认证 HTTP 请求以及向代理服务器的 SMTP 连接中的 XCLIENT 命令注入数据
  ([CVE-2026-28753](https://nvd.nist.gov/vuln/detail/CVE-2026-28753))；
  此修复从 nginx 1.29.7 移植而来。

<a id="bugfixes-pro-1-11-4"></a>

#### 错误修复

- 连接到代理服务器之前的罕见系统错误可能影响 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-http) 和
  [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中对端状态的正确性；在
  [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中还可能导致工作进程崩溃；
  该问题出现在 1.9.1 中。
- 在 [proxy_http_version](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http-version) `3` 和 [proxy_set_header](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-set-header)
  `Host ..` 指令从 `http` 块继承的配置中，发出的 HTTP/3
  请求可能不包含 `Host` 头。

<a id="packages-pro-1-11-4"></a>

#### 软件包

- 已更新：
  - [angie-pro-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，至版本 0.11.0
  - [angie-pro-module-cache-purge](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge)，至版本 2.5.6
  - [angie-pro-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)，至版本 v0.15
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.6
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 v0.43.0

<a id="angie-pro-1-11-3"></a>

### Angie PRO 1.11.3

发布日期：06.02.2026.

<a id="security-pro-1-11-3"></a>

#### 安全性

- 中间人（MITM）攻击者在使用 TLS 的代理服务器之前，在超出攻击者控制的条件下，
  可以在 TLS 握手开始之前向响应中注入明文数据
  ([CVE-2026-1642](https://nvd.nist.gov/vuln/detail/CVE-2026-1642))；
  此修复从 nginx 1.29.5 移植而来。

<a id="packages-pro-1-11-3"></a>

#### 软件包

- 已更新：
  - [angie-pro-module-jwt](https://cn.angie.software//angie/docs/installation/external-modules/jwt.md#external-jwt)，至版本 3.4.4

<a id="angie-pro-1-11-2"></a>

### Angie PRO 1.11.2

发布日期：2026 年 1 月 15 日。

<a id="bugfixes-pro-1-11-2"></a>

#### 错误修复

- 如果禁用了 BPF，HTTP/3 请求可能会失败并显示错误
  `[alert] sendmsg() failed (90: Message too large) while sending frames`；
  该错误出现在 1.11.0 版本中。
- 当启用 BPF 时，在 IPv6 通配符地址上监听时不接受 HTTP/3 请求；
  该错误出现在 1.11.0 版本中。
- 当在 [docker_endpoint](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#docker-endpoint) 指令中指定域名时，
  与 Docker API 的连接和上游服务器组的更新不会发生。

<a id="packages-pro-1-11-2"></a>

#### 软件包

- 更新：
  - [angie-pro-module-cache-purge](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge)，至版本 2.5.5

2026 年 2 月 2 日

- 更新：
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.5

## 2025

<a id="angie-pro-1-11-1"></a>

### Angie PRO 1.11.1

发布日期：2025 年 12 月 30 日。

<a id="changes-1-11-2"></a>

#### 变更

- 现在，如果在 [acme_http_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-http-port) 指令中仅指定端口而不指定 IP（默认值），
  并且存在监听该端口的 `server` 块，则 ACME 中该端口的 HTTP 质询处理
  仅在这些块的 [listen](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#listen) 指令中配置的 IP 地址上工作；不会尝试监听所有 IP 地址，
  这与之前的行为不同；这使配置更加灵活，并防止了从以前版本更新时的问题，
  即配置中仅存在监听端口 `80` 和特定 IP 地址的 `server` 块。

<a id="bugfixes-1-11-2-1"></a>

#### 错误修复

- HTTP/2 请求未在服务器区域统计中计数；
  该错误出现在 1.11.0 版本中。
- 当 ACME 客户端在配置中被禁用且没有先前获取的证书时，
  对该客户端的统计 API 请求可能导致工作进程崩溃。
- 如果在 `server` 块内的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令中使用 `$http_host` 或
  `$cookie_*` 变量作为键，HTTP/3 请求可能不会在此状态区域中计数。

<a id="packages-1-11-3-1"></a>

#### 软件包

- 更新：
  - [angie-pro-module-vts](https://cn.angie.software//angie/docs/installation/external-modules/vts.md#external-vts)，至版本 v0.2.5

<a id="angie-pro-1-11-0"></a>

### Angie PRO 1.11.0

发布日期：2025 年 12 月 24 日。

<a id="changes-1-11-1-1"></a>

#### 变更

- HTTP/3 请求中的 `$http_host` 变量现在从 `:authority` 伪头部的值初始化，
  如果未传递 `Host` 头部，这对客户端来说是正常的；
  以前，与早期协议版本的差异可能会在使用 `$http_host` 的配置中导致问题。
- 如果 `upstream` 组中的所有 HTTP 服务器都不可用或返回错误，
  现在在接收到根据 [proxy_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-next-upstream) 指令
  （及类似指令）被视为错误的状态时，始终返回自己的错误页面，
  而不是最后一个服务器的响应；这确保了所有情况下的一致行为。
- `fastcgi.conf`、`fastcgi_params`、`uwsgi_params` 和
  `scgi_params` 配置文件中的 `REQUEST_METHOD` 参数现在通过
  `$upstream_request_method` 变量设置，该变量在配置缓存时对 `HEAD` 请求
  取值 `GET`；这防止了以前 `HEAD` 请求可能导致存储空响应的问题，
  该响应随后会为 `GET` 请求提供服务，因为在常见配置中请求方法不是缓存键的一部分。
- ACME 服务器的最大响应大小现在由 [acme_max_response_size](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-max-response-size) 指令
  限制，而不是 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的 `max_cert_size=` 参数；
  默认值对大多数情况足够，但如果证书更新以 `[error] too big subrequest response while sending
  to client` 错误消息结束，应增加其值。
- HTTP 模块中 [variables_hash_max_size](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#variables-hash-max-size) 指令的默认值
  增加到 `2048`，以减少由于近年来添加的新变量而导致的关于次优哈希构建的警告的可能性：
  `[warn] could not build optimal variables_hash, you should increase either
  variables_hash_max_size: 1024 or variables_hash_bucket_size: 64;
  ignoring variables_hash_bucket_size`。

<a id="features-1-11-1"></a>

#### 功能特性

- 新的 [Metric](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#http-metric) 模块，支持任意的实时 HTTP 指标收集，
  具有完全可配置的聚合方法（计数器、直方图、移动平均等）；
  它允许在任何阶段跟踪任何请求处理数据，按自定义键分组，
  并通过 `/status/http/metric_zones/` API 部分（包括 Prometheus 支持）公开指标，
  为整个 HTTP 流量提供强大的内置分析工具。
- 支持 ACME 的 ALPN 验证，通过在 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的
  `challenge` 参数中指定 `alpn` 启用；
  允许在仅保持 HTTPS 端口开放的情况下请求多域证书。
- 统计 API 的 `/status/http/acme_clients/` 部分中的 ACME 客户端信息
  和证书请求过程（支持 Prometheus）。
- 在 HTTP 和流 SSL 模块中添加了对加密客户端 Hello (ECH) 的支持；
  新的 [ssl_encrypted_hello_key](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-encrypted-hello-key) 指令指定包含私钥的文件；
  `$ssl_encrypted_hello` 变量包含有关 ECH 使用的信息。
  感谢 Maxim Dounin (freenginx)。
- 使用 [image_filter](https://cn.angie.software//angie/docs/configuration/modules/http/http_image_filter.md#id3) 指令的 `convert` 参数进行图像格式转换。
- Image Filter 模块中支持 AVIF 和 HEIC 格式。
- 在流模块中支持与上游服务器连接的 PROXY protocol V2，
  以及使用 [proxy_protocol_tlv](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#s-proxy-protocol-tlv) 指令设置任意 TLV 值的能力，
  该指令允许包含变量的字符串。
- `$upstream_request_method` 变量，包含上游请求方法，
  当启用缓存或设置 [proxy_method](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-method) 时，该方法可能与客户端请求方法不同；
  这有助于避免常见的配置问题，即缓存的空 `HEAD` 响应为 `GET` 请求提供服务，
  以及避免分别缓存 `HEAD` 和 `GET` 响应。
- [sticky](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-sticky) 模式，其中会话仅存储在远程服务器上并始终从中请求，
  现在也可在 `stream` 模块中使用；以前仅在 HTTP 中可用。
- 在具有远程存储的 [sticky](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-sticky) 会话模式下，现在也处理响应正文；
  这允许从外部存储响应的正文中提取绑定信息，而不仅仅是从头部字段中提取。
- 消除了为 ACME HTTP 质询定义单独的带有 `listen 80` 指令的 `server` 块的需要；
  如有必要，可以使用 [acme_http_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-http-port) 指令自定义监听端口。
- 在导出 Prometheus 指标时计算列表和对象中的项目数的能力；
  以尾部斜杠结尾的路径现在返回相应 API 集合中的项目计数。
- `$sent_body` 变量，包含子请求或客户端模块的外部请求的响应正文。
- 邮件代理模块中支持 XOAUTH2 和 OAUTHBEARER 认证机制。
  感谢 Rob Mueller 和 Maxim Dounin (freenginx)。
- [sticky](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky) 指令的 `route` 参数现在可以包含任意数量变量的任意字符串。
- 在 ACME 模块中，现在自动计算续期证书的近似大小，
  消除了在为大量域颁发证书时增加 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的
  `max_cert_size` 参数的需要；
  该参数保留用于仍需要手动配置的情况。
- API 的 `/status/angie/license` 部分中的许可证和限制信息。
- `$upstream_cache_key` 变量，包含正在使用的缓存键。
  感谢 Kirill A. Korinsky 和 Maxim Dounin (freenginx)。
- nginx 1.29.3 的所有功能，除了 `add_header_inherit` 和 `add_trailer_inherit` 指令，
  由于其设计不佳而被省略。

<a id="bugfixes-1-11-1-1"></a>

#### 错误修复

- 重新加载和二进制升级过程现在可以正确处理 HTTP/3 连接；
  使用 BPF 模块将连接正确路由到所有现有进程。
- 如果 `upstream` 组中的所有服务器都不可用或返回错误，
  则从最后一个服务器接收错误响应可能被视为成功，
  尽管有 [proxy_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-next-upstream) 指令设置。
- 如果 [try_files](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#try-files) 指令中的路径短于相关 `location` 块中的前缀，
  则使用带有 URI 的 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass) 可能导致工作进程崩溃；
  该修复从 nginx 1.29.4 移植而来。
- 如果 ACME 客户端未通过任何 `acme` 指令在 `stream` 块中引用，
  则在该块中使用任何相应的 `$acme_cert_*` 变量将导致配置被拒绝，
  并显示 `unknown variable` 错误；该错误出现在 1.10.3 版本中。
- 如果配置了将缓存索引保存到文件，则在操作期间进行配置测试可能会以错误结束：
  `[alert] mmap() failed (17: File exists)` 和 `[alert] munmap()
  failed (22: Invalid argument)`。
- 如果触发了 `proxy_cache_convert_head on`，则忽略 [proxy_method](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-method) 指令。
- `upstream` 块内 `server` 指令的 `fail_timeout` 选项指定的超时持续时间
  实际上长了一秒。
- 加载为开源 Angie 版本构建的模块可能会由于 ABI 不兼容而导致问题和崩溃；
  现在禁止此类不正确的配置，并显示相关错误消息。

<a id="packages-1-11-1-1"></a>

#### 软件包

- 更新：
  - [angie-pro-module-echo](https://cn.angie.software//angie/docs/installation/external-modules/echo.md#external-echo)，至版本 v0.64

<a id="angie-pro-1-10-3"></a>

### Angie PRO 1.10.3

发布日期：2025 年 11 月 13 日。

<a id="security-2-1-1-1-1-1"></a>

#### 安全性

- 在 SMTP 模块中使用 `none` 认证方法时，处理特制的登录名/密码可能导致
  工作进程内存泄露到认证服务器
  （[CVE-2025-53859](https://nvd.nist.gov/vuln/detail/CVE-2025-53859)）；
  该修复从 nginx 1.29.1 移植而来。

<a id="bugfixes-1-1-1-1-1-1-1-1"></a>

#### 错误修复

- 当使用 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的 `renew_on_load` 选项时，
  如果先前获取的证书存在，则不会加载该证书。这可能会限制功能，
  直到证书续期完成。如果证书不存在，尝试获取新证书将失败，
  并显示错误 `[alert] lseek() failed (9: Bad file descriptor)`。
- 如果 [ACME 客户端](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 在 `stream` 块中被引用，
  但未在 `http` 块中引用，它将被禁用并显示警告 `[warn] ACME
  client ... is defined but not used`，并且永远不会获取证书。
- 如果所有 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令都具有 `enabled=off` 参数，
  并且在配置中使用了相关的 `$acme_cert_*` 变量，Angie 将无法启动，
  并报告错误 `[emerg] unknown acme_cert_* variable`。
- 如果 [ACME 客户端](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 在位于 `http` 块之前的 `stream` 块中使用，
  则 Angie 无法启动，并报告错误 `[emerg] ACME client .. is not defined but referenced`。
- 某些 `client` 块配置在使用引用传入连接的变量时可能导致工作进程崩溃，
  而在这种情况下该连接不存在。
- 通过 [Docker 模块](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker) 添加到上游组的服务器未被主动探测监控。
- 流模块中 [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#s-u-upstream-probe) 指令的 `send=` 参数在指定文件路径时，
  对 UDP 探测工作不正确：发送的是路径而不是文件内容。
- 如果使用了 [sticky](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-sticky) 指令的 `learn` 选项并重新加载配置，
  `timeout=` 参数可能不会生效，直到至少创建一个新会话。

<a id="packages-1-1-1-1-1-1-1-1"></a>

#### 软件包

- 更新：
  - [angie-pro-module-cache-purge](https://cn.angie.software//angie/docs/installation/external-modules/cache-purge.md#external-cache-purge)，至版本 2.5.4
  - [angie-pro-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)，至版本 v0.14.1
  - [angie-pro-module-lua](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua)，至版本 0.10.29
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.4

---

<a id="angie-pro-1-10-2"></a>

### Angie PRO 1.10.2

发布日期：2025 年 8 月 21 日。

<a id="bugfixes-2-1-1-1-1-1-1"></a>

#### 错误修复

- `http` 块中的代理模块设置可能会破坏使用 `client` 块进行出站请求的模块的功能；
  该错误出现在 1.10.0 版本中。
- 启用 [proxy_ignore_client_abort](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ignore-client-abort) 以及使用 `client` 块进行出站请求的模块
  可能导致工作进程崩溃；该错误出现在 1.10.0 版本中。
- 如果在上游组中预配置了单个服务器，通过 [Docker API](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker) 添加的服务器
  可能不会包含在负载均衡中。
- 如果上游组中唯一的服务器是通过 [Docker API](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker) 添加的，
  当检测到不可用时，它可能会被排除在负载均衡之外。

<a id="packages-2-1-1-1-1-1-1"></a>

#### 软件包

- 新增动态模块：
  - [angie-pro-module-auth-totp](https://cn.angie.software//angie/docs/installation/external-modules/auth-totp.md#external-auth-totp)
  - [angie-pro-module-combined-upstreams](https://cn.angie.software//angie/docs/installation/external-modules/combined-upstreams.md#external-combined-upstreams)
- 更新：
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 0.41.0

---

<a id="angie-pro-1-10-1"></a>

### Angie PRO 1.10.1

发布日期：2025 年 7 月 17 日。

<a id="changes-1-1-1-1-1-1"></a>

#### 变更

- 在 `client` 块中指定的指令现在只能被该块内显式声明的 `location` 块继承，
  因此它们不会影响隐式使用 `client` 块进行出站请求的其他模块的配置。

<a id="features-3-1-1-1-1-1-1-1"></a>

#### 功能特性

- 支持多个 `client` 块，允许将不同 `location` 块的通用设置分组到每个块中，
  从而减少配置重复。

<a id="bugfixes-2-1-1-1-1-1"></a>

#### 错误修复

- 当在 `listen` 指令中使用 `reuseport` 参数时，
  到指定地址和端口的所有连接都由单个工作进程处理；该错误出现在 1.10.0 版本中。
- 在 `stream` 粘性会话请求上下文之外访问特殊的 `$stream_*` 变量
  会导致工作进程崩溃。
- 如果服务器上启用了 QUIC 协议 `retry` 模式，使用 OpenSSL 库版本 3.5.0 或更高版本时，
  与上游服务器的 HTTP/3 握手可能会失败。

<a id="angie-pro-1-10-0"></a>

### Angie PRO 1.10.0

发布日期：2025 年 7 月 3 日。

<a id="features-3-1-1-1-1-1-1"></a>

#### 功能特性

- 基于 Docker（或 Podman）容器标签自动检索和动态更新代理服务器组，
  使用 [docker_endpoint](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#docker-endpoint) 指令进行配置。这使得能够通过指定的 Docker API 端点实时监控容器的启动和停止事件，
  并根据指定的标签将其地址添加到 `upstream` 列表或从中移除，无需重新加载配置。
- 在 `stream` 模块中支持通过 ACME 协议自动获取 TLS 证书，
  使用 [acme](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_acme.md#s-acme) 指令以及 [$acme_cert_\*](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_acme.md#v-s-acme-cert-name) 和
  [$acme_cert_key_\*](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_acme.md#v-s-acme-cert-key-name) 等变量进行配置。
- 将一组代理服务器的 `stream` 会话与 HTTP 请求绑定到外部存储，
  可通过 [sticky](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-sticky) 指令在 `learn` 模式下使用 `remote_action`、
  `remote_result` 和 `remote_uri` 参数进行配置。这使得在集群环境中实现客户端会话持久性，
  其中一组负载均衡器共享公共存储，并在会话内将客户端请求路由到同一服务器，
  无论哪个负载均衡器接收到请求。
- `sticky` 指令（在 `learn` 模式下）的新 `norefresh` 参数，
  禁用使用时的自动会话续期。
- [sticky](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky) 的新会话模式，其中会话仅存储在远程服务器上并始终从中检索。
  可以在代理模块中灵活配置远程服务器响应的缓存。
- 使用 [upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-upstream) 块中的 `backup_switch permanent[=timeout]` 指令，
  即使主服务器组再次可用后，也能保持备份 `stream` 服务器处于活动状态。
- 使用 [listen](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#listen) 指令中的 `multipath` 参数支持通过 MPTCP 协议接受连接。
  感谢 Maxim Dounin (freenginx)、Maxime Dourov 和 Anthony Doeraene。
- 新的 [client](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client) 块，用于为各种模块发起的内部 HTTP 请求指定额外配置。
- 包含 [nginx 1.27.5](https://nginx.org/en/CHANGES) 的所有功能，
  包括 QUIC 连接的 CUBIC 拥塞控制。

<a id="bugfixes-2-1-1-1-1"></a>

#### 错误修复

- 对于处于 `drain` 模式的上游服务器，
  在根据被动健康检查服务器再次可用后，统计 API 中的停机计数器未停止。

<a id="packages-2-1-1-1-1-1"></a>

#### 软件包

- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-console-light-pro)，至版本 1.8.0
  - [angie-pro-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)，至版本 0.13
  - [angie-pro-module-otel](https://cn.angie.software//angie/docs/installation/external-modules/otel.md#external-otel)，至版本 0.1.2

2025年7月14日

- 更新：
  - [angie-pro-module-headers-more](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)，至版本 v0.39
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，
    [angie-pro-module-njs-light](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.1

---

<a id="angie-pro-1-9-1"></a>

### Angie PRO 1.9.1

发布日期：2025 年 5 月 29 日。

<a id="features-3-1-1-1-1-1"></a>

#### 功能特性

- [acme_dns_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-dns-port) 指令支持 IP 地址和端口号；
  IPv4 和 IPv6 均可使用。

<a id="bugfixes-2-1-1-1"></a>

#### 错误修复

- 在 [server_name](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name) 指令中同时使用通配符域名和匹配的三级域名可能导致 ACME 服务器在为单个 ACME 客户端下的这些域名颁发证书时失败。
- 在 `stream` 模块中，在被动检查期间成功连接到代理服务器后，
  其在统计 API 中的状态在会话结束前错误地显示为 `unavailable`。
- 当 `stream` 模块中的代理服务器处于 `unhealthy` 状态时，
  统计 API 中的停机计数器可能已停止或被错误重置。
- HTTP/3 请求可能停滞并超时；该修复从 nginx 1.29.0 移植而来。
- 在建立到代理服务器的 HTTP/3 连接时发生早期错误可能导致工作进程崩溃。
- 通过 HTTP/3 协议代理时，统计信息中的活动连接数可能显示不正确。
- 当处于 `drain` 模式的代理服务器变为不可用时，
  根据 [proxy_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-next-upstream) 和类似指令尝试连接到另一台服务器可能不会发生。

<a id="packages-2-1-1-1-1"></a>

#### 软件包

- 新增动态模块：
  - [angie-pro-module-njs-light](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)
- 更新：
  - [angie-pro-module-auth-spnego](https://cn.angie.software//angie/docs/installation/external-modules/auth-spnego.md#external-auth-spnego)，至版本 1.1.3
  - [angie-pro-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)，至版本 0.12.1
  - [angie-pro-module-modsecurity](https://cn.angie.software//angie/docs/installation/external-modules/modsecurity.md#external-modsec)，至版本 1.0.4
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.9.0
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 0.40.0

---

<a id="angie-pro-1-9-0"></a>

### Angie PRO 1.9.0

发布日期：2025 年 4 月 11 日。

<a id="features-3-1-1-1-1"></a>

#### 功能特性

- 在 [proxy_cache_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-path) 指令中指定文件的功能，
  其中将保存包含缓存索引的共享内存区域的内容，以便在服务器启动之间保留；
  这消除了重启后重新加载缓存的需要，并允许服务器几乎立即恢复在线。
- 在 HTTP 模块的 `upstream` 块中使用 [backup_switch permanent[=timeout]](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-backup-switch) 指令，
  允许在主组服务器再次可访问时保持备份服务器组处于活动状态。
- 使用 [ssl_early_data](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#s-ssl-early-data) 指令在 `stream` 模块中支持 TLS 1.3 Early Data (0-RTT)。
- 统计 API 中上游对等点的新 `busy` 状态，
  表示对等点已达到 `max_conns` 选项配置的限制。
- [acme_hook](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-hook) 指令中的 `uri=` 参数允许重新定义钩子请求 URI 并支持变量。
- [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的 `renew_on_load` 参数允许在配置加载时强制证书续期。
- 现在通过 `/status/angie` 统计 API 对象的 `build_time` 字段
  以及 `-V` 命令行选项的输出显示构建时间。
- [nginx 1.27.4](https://nginx.org/en/CHANGES) 的所有功能，
  除了 `keepalive_min_timeout` 指令（类似功能自 1.8.0 版本起已存在）。

<a id="changes-2-1-1-1-1-1-1"></a>

#### 变更

- [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令中的 `enabled=off` 参数现在仅禁用给定客户端的证书续期，
  同时保留所有其他功能；密钥和证书（如果可用）可以通过 `$acme_cert_*` 变量访问，
  而使用 `$acme_hook_*` 变量和 `acme` 指令不会导致错误。
- `no valid domain name defined for ACME client` 错误现在仅在
  使用 `acme` 指令引用 ACME 客户端的 `server` 块中
  未找到有效（即符合 ACME 标准的）域名时才会发出。

<a id="bugfixes-2-1-1"></a>

#### 错误修复

- 如果构建时启用了 NTLS 支持，
  带有变量的 `proxy_ssl_certificate` 和 `proxy_ssl_certificate_key` 指令的继承无法正常工作。

<a id="packages-2-1-1-1"></a>

#### 软件包

- 更新：
  - [angie-pro-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)，至版本 0.11.1
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.8.10

---

<a id="angie-pro-1-8-3"></a>

### Angie PRO 1.8.3

发布日期：2025 年 4 月 2 日。

<a id="bugfixes-2-1"></a>

#### 错误修复

- 如果同一连接内的请求属于不同的统计区域，
  或者在早期请求处理期间发生错误，
  HTTP 模块的 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 块中的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 统计信息可能计算错误；
  该错误出现在 1.8.2 版本中。

<a id="packages-2-1-1"></a>

#### 软件包

- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-console-light-pro)，至版本 1.7.0
  - [angie-pro-module-cgi](https://cn.angie.software//angie/docs/installation/external-modules/cgi.md#external-cgi)，至版本 57f660bb2c6ef6e4b75c65406080d0236860ca08
  - [angie-pro-module-jwt](https://cn.angie.software//angie/docs/installation/external-modules/jwt.md#external-jwt)，至版本 v3.4.3
  - [angie-pro-module-ndk](https://cn.angie.software//angie/docs/installation/external-modules/ndk.md#external-ndk)，至版本 v0.3.4
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 v0.39.0
  - [angie-pro-module-vts](https://cn.angie.software//angie/docs/installation/external-modules/vts.md#external-vts)，至版本 v0.2.4

2025年4月4日

- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-console-light-pro)，至版本 1.7.1

2025年4月7日

- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-console-light-pro)，至版本 1.7.2

<a id="angie-pro-1-8-2"></a>

### Angie PRO 1.8.2

发布日期：2025 年 2 月 13 日。

<a id="security-2-1-1-1-1"></a>

#### 安全性

- 在处理带有 TLSv1.3 SNI 的虚拟服务器时验证不足，
  允许在不同的虚拟服务器中重用 SSL 会话，
  绕过客户端 SSL 证书验证（[CVE-2025-23419](https://www.cve.org/CVERecord?id=CVE-2025-23419)）；
  该修复从 nginx 1.27.4 移植而来。

<a id="bugfixes-2"></a>

#### 错误修复

- 在 `stream` 模块中使用 [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#s-u-upstream-probe) 指令配置的主动探测可能导致工作进程崩溃。
- 从通过变量设置的单个区域检索统计值的 API 请求可能导致工作进程进入无限循环。
- HTTP/3 请求未在区域统计中计数；
  该错误出现在 1.8.0 版本中。
- 使用 QUIC 协议的 TLS 握手未在 SSL 统计中计数。
- 通过 [ACME 协议](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 进行证书续期可能对 [server_name](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name) 指令中以点为前缀的服务器名称失败。

<a id="packages-2-1"></a>

#### 软件包

- 新增动态模块：
  - [angie-pro-module-auth-pam](https://github.com/sto/ngx_http_auth_pam_module)
  - [angie-pro-module-cgi](https://github.com/pjincz/nginx-cgi)

---

## 2024

<a id="angie-pro-1-8-1"></a>

### Angie PRO 1.8.1

发布日期：2024 年 12 月 28 日。

#### 错误修复

- 在 HTTP 模块的 `server` 块中使用 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令会导致在 TLS 握手时在 [access_log](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#access-log) 中过度记录空请求；该错误出现在 1.8.0 版本中。
- HTTP/3 流中的解码错误可能会在关闭 QUIC 连接时导致工作进程崩溃；该修复从 nginx 1.27.4 移植而来。
- 发送 QUIC 协议版本协商数据包可能会导致无限数据包交换循环；该修复从 nginx 1.27.4 移植而来。
- 在某些配置中，在 [ACME 模块](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 中使用不带钩子的 DNS 验证可能会导致工作进程崩溃。

<a id="packages-2"></a>

#### 软件包

- 更新：
  - [angie-pro-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，至版本 0.9.0

2025年1月23日

- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-console-light-pro)，至版本 1.6.0

2025年1月27日

- 新增动态模块：
  - [angie-pro-module-unbrotli](https://github.com/clyfish/ngx_unbrotli)
- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-console-light-pro)，至版本 1.6.1
  - [angie-pro-module-auth-spnego](https://cn.angie.software//angie/docs/installation/external-modules/auth-spnego.md#external-auth-spnego)，至版本 v1.1.2
  - [angie-pro-module-headers-more](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)，至版本 v0.38
  - [angie-pro-module-lua](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua)，至版本 0.10.28
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.8.9
  - [angie-pro-module-vts](https://cn.angie.software//angie/docs/installation/external-modules/vts.md#external-vts)，至版本 v0.2.3
  - [angie-pro-module-wasm](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#wasm-core)，至版本 v0.2-beta2

---

<a id="angie-pro-1-8-0"></a>

### Angie PRO 1.8.0

发布日期：2024 年 12 月 19 日。

<a id="features-3-1-1-1"></a>

#### 功能特性

- 通过请求外部存储为一组代理服务器实现 HTTP 会话绑定，可通过 [sticky](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky) 指令在 `learn` 模式下使用 `remote_action` 和 `remote_result` 参数进行配置；这允许在集群模式下配置客户端会话与负载均衡服务器的绑定，当一组负载均衡器通过共享存储统一管理时，可将一个会话内的客户端请求定向到同一台服务器，无论它们命中哪个负载均衡器。
- 通过处理来自 ACME 服务器的 DNS 查询来支持 `DNS-01` 验证，这允许自动请求任何类型的证书，包括通配符证书。
- ACME 模块中的钩子系统，可使用 [acme_hook](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-hook) 指令进行配置，允许使用外部应用程序处理域名验证，以提供与各种服务和 DNS 托管提供商的集成。
- ACME 模块记录一些额外信息：证书续期的具体原因、完整的域名列表、客户端账户 ID、长时间不活动期（例如轮询）以及正在验证的域名；这些信息简化了故障排查，并允许指定 CAA DNS 记录。
- [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 指令的 `account_key` 参数，允许为 ACME 服务器账户重用现有密钥，而不是自动生成新密钥。
- 在 stream 和 HTTP 模块的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令中支持变量，允许在单个 `location` 或 `server` 块中动态统计多个区域的数据；特别是当单个 `server` 块处理多个虚拟主机时非常有用。
- GZip HTTP 压缩模块与 `zlib-ng` 2.2.0 及更高版本的兼容性，之前可能会在错误日志中导致 `[alert] gzip filter failed to use preallocated memory` 消息。
- [max_headers](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#max-headers) 指令，用于限制 HTTP 请求头字段的数量，以更好地防御 DoS 攻击。感谢 Maxim Dounin (freenginx) 和 Maksim Yevmenkin。
- [http3_max_table_capacity](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#http3-max-table-capacity) 和 [proxy_http3_max_table_capacity](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http3-max-table-capacity) 指令，用于配置 HTTP/3 动态头压缩表限制。
- 交叉编译支持 - 构建系统现在可以使用包装脚本来运行自动测试，这使得可以在不直接在目标平台上运行测试程序的情况下准备构建。
- [nginx 1.27.3](https://nginx.org/en/CHANGES) 的所有功能。

#### 错误修复

- 使用 `0-RTT` 时 HTTP/3 客户端可能超时；该错误在 1.7.0 版本中从 nginx 继承而来。
- 在 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass) 指令中使用变量且未指定 `upstream` 块的情况下使用 HTTP/3 代理可能导致工作进程崩溃。
- 使用动态表的 HTTP/3 上游如果与缓存一起使用可能导致工作进程崩溃。
- 某些 SSL 握手可能未在 `stream` 模块的统计信息中计数。
- 在 `http` 或 `server` 级别指定的 HTTP/3 代理设置可能被忽略。
- 启用 NTLS 支持时，通过 HTTP/3 代理时 [proxy_ssl_certificate](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-certificate) 指令不起作用。

<a id="changes-2-1-1-1-1-1"></a>

#### 变更

- 在优雅关闭旧工作进程时，保持活动连接现在仅在 [lingering_timeout](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#lingering-timeout) 指令指定的超时时间到期后才关闭；此行为允许避免在此时接收响应时可能出现的客户端错误。感谢 Maxim Dounin (freenginx)。
- 禁用了 `stream` 模块变量 [$ssl_server_name](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-server-name)、[$ssl_server_cert_type](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-server-cert-type)、[$ssl_preread_protocol](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#v-ssl-preread-protocol) 和 [$ssl_preread_server_name](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#v-ssl-preread-server-name) 的缓存，这允许在使用虚拟服务器时获取实际值。

#### 软件包

- 新增动态模块：
  - [angie-pro-module-http-auth-radius](https://github.com/ten0s/ngx_http_auth_radius_module)
- 更新：
  - [angie-pro-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，至版本 0.8.0
  - [angie-pro-module-jwt](https://cn.angie.software//angie/docs/installation/external-modules/jwt.md#external-jwt)，至版本 3.4.2
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，至版本 0.8.8
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，至版本 0.38.0
  - [angie-pro-module-wasm](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#wasm-core)，至版本 0.1-beta5

<a id="angie-pro-1-7-0"></a>

### Angie PRO 1.7.0

发布日期：2024 年 9 月 19 日。

<a id="features-3-1-1"></a>

#### 功能特性

- 当代理服务器从组中移除时，强制关闭所有到该服务器的连接；可通过 [proxy_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-connection-drop)、
  [grpc_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_grpc.md#grpc-connection-drop)、[fastcgi_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-connection-drop)、
  [scgi_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-connection-drop) 和 [uwsgi_connection_drop](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-connection-drop) 指令进行配置，
  其值可通过 [API 请求](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config-methods) 的 `connection_drop` 参数在移除服务器时局部覆盖。
- 解析器统计 API 中的已发送 DNS 查询类型计数器，通过 [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 指令的 `status_zone` 参数收集。
- [feedback (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-feedback) 负载均衡现在可在 `stream` 模块中使用；它根据指定变量分配 TCP/UDP 会话，
  该变量可从代理的上游服务器或对外部服务的定期请求中获取。
  这允许根据代理服务器的任意指标（如资源消耗、CPU/内存利用率和队列长度）进行动态负载均衡。
- [feedback (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-feedback) 指令的 `last_byte` 选项，允许在接收到完整响应后处理上游服务器反馈，
  而不仅仅是响应头。
- [feedback (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-feedback) 负载均衡方法现在接受浮点数作为变量值。
- [least_time (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-least-time) 指令的 `account` 参数，允许使用变量指定哪些请求被考虑用于
  `least_time` 负载均衡，包括仅考虑 [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe) 请求。
- [least_time (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-least-time) 指令的 `factor` 参数，允许为 `least_time` 负载均衡器指定可调的平滑因子，
  并覆盖用于统计收集的 [response_time_factor (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-response-time-factor) 的值。
- `drain` 模式，将代理的 stream 服务器切换到新的 `draining` 状态，
  此时只有使用 [sticky](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-sticky) 模块绑定的请求才会发送到该服务器。
- [$ssl_server_cert_type](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-server-cert-type) 变量，包含为接收的 TLS 连接选择的证书类型。
- 通过 [pid](https://cn.angie.software//angie/docs/configuration/modules/core.md#pid) 指令的 `off` 参数禁用 PID 文件的创建，
  这在使用不可变镜像和由服务管理器直接控制时可能有用。感谢 Maxim Dounin (freenginx)。
- 通过中间临时文件使 PID 文件的创建具有原子性，
  这消除了文件已在目录中但仍为空的时刻，
  并允许外部程序更轻松、更可靠地处理它。
- 现在，在重新配置期间，如果 [pid](https://cn.angie.software//angie/docs/configuration/modules/core.md#pid) 指令中的名称已更改但通过符号链接指向同一文件，
  则不会尝试重新创建 PID 文件；特别是，这允许避免在从 `/var/run/angie.pid` 迁移到
  `/run/angie.pid` 的系统上出现问题。感谢 Maxim Dounin (freenginx)。
- [Syslog 日志记录](https://cn.angie.software//angie/docs/configuration/processing.md#syslog-logging) 错误现在每秒最多报告一次；
  这有助于避免在 syslog 服务器宕机或过载时用此类消息淹没日志。感谢 Maxim Dounin (freenginx)。
- 在邮件代理模块中，通过 [max_commands](https://cn.angie.software//angie/docs/configuration/modules/mail/index.md#max-commands) 指令配置的身份验证期间的最大命令数受到限制，
  以更好地防御 DoS 攻击。感谢 Maxim Dounin (freenginx)。
- **./configure** 脚本的 [--feature-cache](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 选项，
  用于缓存其结果以在构建多个模块或交叉编译时进行优化。
- [nginx 1.27.1](https://nginx.org/en/CHANGES) 的所有功能。

#### 错误修复

- 由 [queue (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-queue) 指令配置的排队请求的等待超时可能导致工作进程崩溃。
- 使用 **systemd** 启动时可能出现 `PID file ... not readable (yet?) after start` 和
  `Failed to parse PID from file...` 错误。感谢 Maxim Dounin (freenginx)。

<a id="changes-2-1-1-1-1"></a>

#### 变更

- 根据 RFC 9110 更新了 HTTP 状态码的描述。感谢 Maxim Dounin (freenginx) 和 Michiel W. Beijen。
- 现在 HTTP 请求之前最多允许一个空行，以更好地防御 DoS 攻击。感谢 Maxim Dounin (freenginx)。
- 现在禁止末尾没有冒号的 HTTP/1.x 头字段名称；
  来自客户端或代理服务器的此类无效头字段现在将导致错误响应。感谢 Maxim Dounin (freenginx) 和 Maksim Yevmenkin。
- 使用 HTTP/1.1 分块传输编码读取请求体时，
  忽略的块扩展和尾部头字段的总大小现在受 [client_max_body_size](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-max-body-size) 指令限制，
  以更好地防御 DoS 攻击。感谢 Maxim Dounin (freenginx) 和 Bartek Nowotarski。
- `mime.types` 配置文件中的 MIME 类型已更改为：
  `bmp` 扩展名对应 `image/bmp`，
  `rar` 扩展名对应 `application/vnd.rar`；
  `deb` 和 `udeb` 扩展名设置为 `application/vnd.debian.binary-package`。
  感谢 Yuriy Izorkin。

#### 软件包

- 更新：
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，更新至版本 0.36.0
  - [angie-pro-module-lua](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua)，更新至版本 0.10.27

2024 年 10 月 24 日

- 为 [SberLinux](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-yum-pro) 添加了软件包。

---

<a id="angie-pro-1-6-2"></a>

### Angie PRO 1.6.2

发布日期：2024 年 8 月 16 日。

<a id="security-2-1-1-1"></a>

#### 安全性

- 使用 [ngx_http_mp4_module](https://cn.angie.software//angie/docs/configuration/modules/http/http_mp4.md#http-mp4) 处理特制的 MP4 文件可能导致工作进程崩溃
  ([CVE-2024-7347](https://nvd.nist.gov/vuln/detail/CVE-2024-7347))；
  修复已从 nginx 1.27.1 移植。

---

<a id="angie-pro-1-6-1"></a>

### Angie PRO 1.6.1

发布日期：2024 年 8 月 8 日。

<a id="features-3-1"></a>

#### 功能特性

- [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-status-zone) 指令配置的
  [API 统计](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-stream-server-zones) 区域中新增 `passed` 计数器，
  用于跟踪使用 [pass](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_pass.md#s-pass) 指令传递到其他监听套接字的连接。

#### 错误修复

- 在 [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中使用虚拟服务器或 [pass](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_pass.md#s-pass) 指令时，
  连接可能在统计 API 中计数不正确。
- 在配置了 5 个或更多 ACME 客户端时，工作进程可能崩溃；该错误出现在 1.6.0 版本中。
- 处理带有 `X-Accel-Redirect` 头的缓存响应可能导致工作进程崩溃。
  感谢 Maxim Dounin (freenginx) 和 Jiří Setnička。

#### 软件包

- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-console-light-pro)，更新至版本 1.4.0
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，更新至版本 0.35.3
  - [angie-pro-module-zstd](https://cn.angie.software//angie/docs/installation/external-modules/zstd.md#external-zstd)，更新至修订版 `f4ba115`

---

<a id="angie-pro-1-6-0"></a>

### Angie PRO 1.6.0

发布日期：2024 年 6 月 28 日。

<a id="features-3"></a>

#### 功能特性

- 基于指定变量值的 HTTP 请求负载均衡，
  该变量可从代理服务器或对外部服务的定期轮询中获取，
  通过 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 块中的 [feedback](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-feedback) 指令配置；
  这允许根据代理服务器的任意指标动态重新分配负载：
  各种资源消耗、CPU/内存利用率、队列长度等。
- [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-upstream) 块中的
  [sticky](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-sticky) 指令及相关设置，
  允许配置会话持久性模式，
  其中会话内的所有连接都路由到同一服务器。
- 使用 [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块的 [rdp_preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#s-rdp-preread) 指令
  从 RDP 连接中提取 Cookie 值到 [$rdp_cookie](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#v-rdp-cookie) 和
  [$rdp_cookie_NAME](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#id5) 变量，
  这允许在负载均衡时记录日志并将 RDP 客户端会话绑定到同一服务器。
- [upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe) 指令的 `persistent` 选项，
  允许在配置重新加载后避免等待 `essential` 探测通过，
  对于之前健康的服务器。
- 支持在单个 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 块中使用多个 [acme](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 指令，
  这允许在该虚拟服务器内同时配置获取两种类型的证书。
- 命令行选项 `-m` 和 `-M`，用于显示内置和已加载模块的列表。
- [$upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#v-upstream-probe) 变量，
  包含由 [upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe) 发出的当前活动探测的名称。
- [ACME](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 模块中支持 [BoringSSL](https://www.chromium.org/Home/chromium-security/boringssl/)。
- [nginx 1.27.0](https://nginx.org/en/CHANGES) 的所有功能，
  包括 [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中的虚拟服务器支持
  和 `pass` 指令，
  允许将接受的连接传递给其他监听套接字进行处理，
  包括 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-http) 和 [Mail](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-mail) 模块。

#### 错误修复

- 在某些配置上，活动 [upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe) 探测可能无法工作，
  同时记录类似 `[alert] getsockname() failed (9: Bad file descriptor)` 的错误消息。
- 在某些配置上，通过 ACME 协议请求证书可能失败，
  并记录类似 `[alert] getsockname() failed (9: Bad file descriptor)` 的日志消息。
- 通过 ACME 协议请求包含大量域名的证书可能失败，
  并记录类似 `[error] JSON parser error` 的日志消息。
- 在配置了多个 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 指令的情况下，
  ACME 客户端可能将消息输出到错误的日志。

#### 软件包

- 更新：
  - [angie-pro-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，更新至版本 0.7.0
  - [angie-pro-module-auth-ldap](https://cn.angie.software//angie/docs/installation/external-modules/auth-ldap.md#external-ldap)，更新至修订版 `241200e`
  - [angie-pro-module-jwt](https://cn.angie.software//angie/docs/installation/external-modules/jwt.md#external-jwt)，更新至版本 3.4.1
  - [angie-pro-module-keyval](https://cn.angie.software//angie/docs/installation/external-modules/keyval.md#external-keyval)，更新至版本 0.3.0
  - [angie-pro-module-lua](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua)：
    `stream_lua_module`，更新至修订版 `bea8a0c`
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，更新至版本 0.8.5

---

<a id="angie-pro-1-5-2"></a>

### Angie PRO 1.5.2

发布日期：2024 年 6 月 3 日。

<a id="security-2-1-1"></a>

#### 安全性

- 使用 HTTP/3 时，处理特制的 QUIC 会话可能导致工作进程崩溃，在 MTU 大于 4096 字节的系统上可能导致工作进程内存泄露，或有其他影响（[CVE-2024-32760](https://nvd.nist.gov/vuln/detail/CVE-2024-32760)，
  [CVE-2024-31079](https://nvd.nist.gov/vuln/detail/CVE-2024-31079)，
  [CVE-2024-35200](https://nvd.nist.gov/vuln/detail/CVE-2024-35200)，
  [CVE-2024-34161](https://nvd.nist.gov/vuln/detail/CVE-2024-34161)）；
  修复已从 nginx 1.26.1 移植。

#### 软件包

- 更新：
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，更新至版本 0.35.2

---

<a id="angie-pro-1-5-1"></a>

### Angie PRO 1.5.1

发布日期：2024 年 5 月 16 日。

#### 错误修复

- 当通过 API 编辑一组代理服务器时，`proxy_next_upstream` 机制未能正常工作，
  并且当在 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 块中的 [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 指令使用
  [resolve](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve) 选项时，如果解析的 IP 地址数量与指定服务器的数量不同。
- 在通过 ACME 协议请求证书时，可能会在工作进程中发生段错误。
- 在 `learn` 模式下的 [sticky](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky) 指令在 `lookup` 和 `create`
  变量数量不同的情况下可能会不正确地工作。
- 在 [stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 模块中代理 TCP 连接时，
  [slow_start](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-slow-start) 机制未能正常工作。
- 如果以 TLS 1.3 早期数据的形式接收，HTTP/3 请求可能失败；该错误出现在 1.4.0 版本中。
- 在使用 QUIC 的 0-RTT 时，HTTP/3 连接可能会被过早关闭。
- 从快速连接读取请求体时，可能会长时间读取。感谢 Maxim Dounin (freenginx)。

<a id="changes-2-1-1-1"></a>

#### 变更

- 现在 ACME 客户端不会丢弃之前存储的过期或为不同域名列表颁发的证书，
  而是在续订进行时使用它们。

#### 软件包

2024 年 5 月 27 日

- 为 [Alpine](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-alpine-pro) 3.20 添加了软件包。

---

<a id="angie-pro-1-5-0"></a>

### Angie PRO 1.5.0

发布日期：2024 年 3 月 27 日。

#### 功能特性

- 初步支持使用 [ACME 协议](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 自动获取和更新证书，
  可通过 [acme_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#acme-client) 和 [acme](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 指令进行配置，
  以及形如 [$acme_cert_=](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-cert-name) 和
  [$acme_cert_key_=](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-cert-key-name) 的变量。
- `drain` 模式，将代理的 HTTP 服务器切换到新的 `draining` 状态，
  此时只有使用 [sticky](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky) 模块绑定的请求才会发送到该服务器。
- 通过 [auto_redirect](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#auto-redirect) 指令配置自动重定向，为请求 URI 添加尾部斜杠。
- 在 Prometheus 中使用 Unix 时间戳格式而非 ISO 8601 格式输出包含日期的 [指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics)，
  并且在使用 `?date-epoch` 参数请求时也在 JSON API 中使用。
- 现在 `-V` 选项也会显示相关的 nginx 版本，
  这对于与第三方工具（特别是 **certbot**）的兼容性很有用。
  感谢 [AdvTechnoKing](https://github.com/webserver-llc/angie/commit/eb914d43aa6a2231d7321c808cb4180abb013ca0)。
- [nginx 1.25.4](https://nginx.org/en/CHANGES) 的所有功能。

#### 错误修复

- 如果使用 SSL 会话重用机制 ([proxy_ssl_session_reuse](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-session-reuse))，
  则在动态更新代理服务器列表时，
  可能会在为相应 `upstream` 块配置的共享内存区域 (`zone`) 中发生泄漏。

#### 软件包

- 为 [FreeBSD 13](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-freebsd-pro) (arm64) 和
  [RED OS 8](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-yum-pro) (x86-64) 添加了软件包。
- 新增动态模块：
  - [angie-pro-module-otel](https://github.com/nginxinc/nginx-otel)
- 更新：
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，更新至版本 0.34.0

2024 年 3 月 28 日

- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#pro-packages)，更新至版本 1.3.0

2024 年 4 月 16 日

- 新增动态模块：
  - [angie-pro-module-zstd](https://github.com/tokers/zstd-nginx-module)
- 更新：
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，更新至版本 0.8.4

2024 年 4 月 25 日

- 新增动态模块：
  - angie-pro-module-vts：包含
    [module-vts](https://github.com/vozlt/nginx-module-vts)、
    [module-sts](https://github.com/vozlt/nginx-module-sts)、
    [module-stream-sts](https://github.com/vozlt/nginx-module-stream-sts)

---

<a id="angie-pro-1-4-1"></a>

### Angie PRO 1.4.1

发布日期：2024 年 2 月 15 日。

<a id="security-2-1"></a>

#### 安全性

- 使用 HTTP/3 时，处理特制的 QUIC 会话可能在工作进程中发生段错误
  ([CVE-2024-24989](https://nvd.nist.gov/vuln/detail/CVE-2024-24989))；
  请注意，Angie PRO 自 1.4.0 起已不再易受
  [CVE-2024-24990](https://nvd.nist.gov/vuln/detail/CVE-2024-24990) 的影响。

#### 软件包

- 新增动态模块：
  - [angie-pro-module-dynamic-limit-req](https://github.com/limithit/ngx_dynamic_limit_req_module)
- 更新：
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，更新至版本 0.8.3
  - [angie-pro-module-vod](https://cn.angie.software//angie/docs/installation/external-modules/vod.md#external-vod)，更新至版本 1.33

## 2023

<a id="angie-pro-1-4-0"></a>

### Angie PRO 1.4.0

发布日期：2023 年 12 月 21 日。

#### 功能特性

- 支持在 [HTTP 代理模块](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy) 中建立到上游服务器的 [HTTP/3](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#http-v3) 连接，
  同时允许客户端使用任意 HTTP 版本。通过 [proxy_http_version](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-http-version) 指令
  以及一组 `proxy_quic_` 和 `proxy_http3_` 指令进行配置。
- [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#s-u-upstream-probe) 指令，用于通过定期创建测试连接或发送数据报
  来检查 [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 模块中服务器的健康状况。
- [sticky](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky) 指令的附加 `learn` 模式，
  用于将会话绑定到代理服务器，允许发现会话并将其保存在服务器的共享内存中。
- 等待队列用于无法首次尝试负载均衡的请求，
  通过在 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块的 `upstream` 块中使用 [queue (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-queue) 指令配置。
- HTTP RESTful [JSON 接口](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config-stream-upstreams-servers)，
  用于在 [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 模块的 `upstream` 块中重新配置、添加或删除服务器，
  以及用于持久化这些更改的 [state](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-state) 指令。
- 通过平均建立连接时间、接收响应的第一个或最后一个字节的时间，
  对代理的 [stream upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 服务器进行负载均衡，
  使用 [least_time (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-least-time) 和 [response_time_factor (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-response-time-factor) 指令
  在 `upstream` 块中进行可调平滑因子。
- 通过 [api](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 指令提供的接口，
  获取代理的 [stream upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 服务器的
  平均建立连接时间、接收响应的第一个和最后一个字节的统计信息，
  并能够通过 `upstream` 块的 [response_time_factor (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-response-time-factor) 指令调整平均平滑因子。
- 使用 `slow_start` 选项，
  在 `upstream` 块中的 [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 指令中平滑地将代理服务器上线，经过故障后。
- [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#stream-mqtt-preread) 模块中的 [mqtt_preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#s-mqtt-preread) 指令，
  允许从 MQTT 协议的 CONNECT 数据包中提取用户名和客户端 ID 到
  [$mqtt_preread_username](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#v-mqtt-preread-username) 和
  [$mqtt_preread_clientid](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#v-mqtt-preread-clientid) 变量中。
- 通过 [mp4_limit_rate](https://cn.angie.software//angie/docs/configuration/modules/http/http_mp4.md#mp4-limit-rate) 和 [mp4_limit_rate_after](https://cn.angie.software//angie/docs/configuration/modules/http/http_mp4.md#mp4-limit-rate-after) 指令，
  按比特率限制传输到客户端的 MP4 文件的响应速率，从而减少带宽负载。
- [nginx 1.25.3](https://nginx.org/en/CHANGES) 的所有功能。

#### 错误修复

- 如果代理服务器是组中的唯一服务器，
  可能会在 [统计 API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics) 中错误地报告为 `unavailable`，即使在恢复后也是如此。

<a id="changes-2-1-1"></a>

#### 变更

- 现在代理服务器处于 `checking` 状态的时间不计入 `downtime`。
- 标准 [prometheus_all.conf](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#prometheus-all) 模板包括所有额外的 Prometheus 指标
  和仅由 PRO 版本公开的可能 `state` 值。

#### 软件包

- 为 [Alpine](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-alpine-pro) 3.19 添加了软件包。
- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#pro-packages)，更新至版本 1.2.0
  - [angie-pro-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，更新至版本 0.4.0
  - [angie-pro-module-headers-more](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)，更新至版本 0.36
  - [angie-pro-module-ndk](https://cn.angie.software//angie/docs/installation/external-modules/ndk.md#external-ndk)，更新至版本 0.3.3
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，更新至版本 0.33.0

2023 年 12 月 25 日

- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#pro-packages)，更新至版本 1.2.1

2024 年 1 月 22 日

- 新增动态模块：
  - [angie-pro-module-zip](https://github.com/evanmiller/mod_zip)
- 更新：
  - [angie-pro-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，更新至版本 0.6.0
  - [angie-pro-module-headers-more](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)，更新至版本 0.37
  - [angie-pro-module-lua](https://cn.angie.software//angie/docs/installation/external-modules/lua.md#external-lua)：
    `http_lua_module`，更新至版本 0.10.26；
    `stream_lua_module`，更新至版本 0.0.14

---

<a id="angie-pro-1-3-2"></a>

### Angie PRO 1.3.2

发布日期：2023 年 11 月 23 日。

#### 错误修复

- 带有 `essential` 标志的主动 [健康探测](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe)
  在初始检查失败时未正确处理服务器从 `checking` 到 `unhealthy` 的转换，
  导致用户请求被路由到故障服务器。
- [Prometheus](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#id3) 输出中使用 `$p8s_value` 以外的变量作为值的指标
  可能出现不正确的值；实际上该问题可能出现在标准 `prometheus_all.conf` 模板中的
  `angie_http_upstreams_peers_state` 和 `angie_stream_upstreams_peers_state`。
- 如果某些连接上游服务器的尝试立即失败，可能未在 [统计 API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 中正确计数；
  该错误出现在 1.3.0 版本中。

#### 软件包

2023 年 12 月 4 日

- 新增动态模块：
  - [angie-pro-module-modsecurity](https://github.com/owasp-modsecurity/ModSecurity-nginx)

2023 年 12 月 7 日

- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#pro-packages)，更新至版本 1.1.1

2023 年 12 月 12 日

- 新增动态模块：
  - [angie-pro-module-auth-ldap](https://github.com/kvspb/nginx-auth-ldap)
- 更新：
  - [angie-pro-module-auth-jwt](https://cn.angie.software//angie/docs/installation/external-modules/auth-jwt.md#external-auth-jwt)，更新至版本 0.4.0
  - [angie-pro-module-headers-more](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)，更新至版本 0.36
  - [angie-pro-module-ndk](https://cn.angie.software//angie/docs/installation/external-modules/ndk.md#external-ndk)，更新至版本 0.3.3
  - [angie-pro-module-opentracing](https://cn.angie.software//angie/docs/installation/external-modules/opentracing.md#external-opentracing)，更新至版本 0.33.0

---

<a id="angie-pro-1-3-1"></a>

### Angie PRO 1.3.1

发布日期：2023 年 10 月 18 日。

<a id="security-2"></a>

#### 安全性

- 为 HTTP/2 流处理添加了额外的限制，以更好地防御被称为 "HTTP/2 Rapid Reset" 的 DoS 攻击
  ([CVE-2023-44487](https://nvd.nist.gov/vuln/detail/CVE-2023-44487))。

#### 软件包

2023 年 10 月 26 日

- 新增动态模块：
  - [angie-pro-module-opentracing](https://github.com/opentracing-contrib/nginx-opentracing/)

2023 年 11 月 13 日

- 新增动态模块：
  - [angie-pro-module-testcookie](https://github.com/kyprizel/testcookie-nginx-module/)
- 更新：
  - [angie-pro-console-light](https://cn.angie.software//angie/docs/installation/pro_packages.md#pro-packages)，更新至版本 1.1.0
  - [angie-pro-module-headers-more](https://cn.angie.software//angie/docs/installation/external-modules/headers-more.md#external-headers-more)，更新至版本 0.35
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs)，更新至版本 0.8.2
  - [angie-pro-module-vod](https://cn.angie.software//angie/docs/installation/external-modules/vod.md#external-vod)，更新至版本 1.32

---

<a id="angie-pro-1-3-0"></a>

### Angie PRO 1.3.0

发布日期:2023 年 10 月 3 日。

#### 功能特性

- 能够在 `location` 指令中指定多个匹配模式,
  允许 [组合](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#combined-locations) 多个具有相似设置的 `location` 块,
  从而通过减少重复来简化配置。
- 根据从代理 HTTP 服务器接收响应头或完整响应的平均时间进行负载均衡,
  具有可调的平滑因子,使用 `upstream` 块中的
  [least_time (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-least-time) 和 [response_time_factor (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-response-time-factor) 指令。
- 以 Prometheus 格式导出各种统计指标,使用新的 [prometheus](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#id3) 和
  [prometheus_template](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#prometheus-template) 指令进行灵活的模板配置。
- 在 [api](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 指令提供的接口中显示代理 HTTP 服务器接收响应头和完整响应的平均时间统计,
  能够通过 `upstream` 块的 [response_time_factor (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-response-time-factor) 指令调整平均平滑因子。
- 在 [api](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 指令提供的统计接口中显示 stream 上游服务器组的详细信息和
  [指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-stream-upstreams)。
- [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 模块的 `upstream` 块中
  `server` 指令的 [resolve](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-reresolve) 选项,
  允许监控与域名对应的 IP 地址列表的变化,并自动更新它而无需重新加载配置。
- [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 模块的 `upstream` 块中
  `server` 指令的 [service](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-reresolve) 选项,
  允许从 DNS SRV 记录中检索地址列表,并提供基本的优先级支持。
- 支持使用 [http](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块的 `upstream` 块中的
  [bind_conn (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-bind-conn) 指令将客户端连接绑定到后端服务器连接,
  特别适用于代理使用 NT LAN Manager (NTLM) 身份验证的连接。
- 通过 [api](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 指令提供的接口访问当前工作进程使用的配置文件内容,
  需要启用 [api_config_files](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api-config-files) 指令。
- 在进程标题中显示 [配置代数](https://cn.angie.software//angie/docs/configuration/runtime.md#control-config-change) 编号,
  允许使用 `ps` 工具监控配置重新加载的成功情况以及先前工作进程代数的数量。
- [nginx 1.25.2](https://nginx.org/en/CHANGES) 的所有功能。

<a id="changes-2-1"></a>

#### 变更

- 现在在加载 OpenSSL 配置时使用应用名称 `angie`。

#### 软件包

- 更新:
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs),更新至版本 0.8.1

---

<a id="angie-pro-1-2-0"></a>

### Angie PRO 1.2.0

发布日期:2023 年 8 月 15 日。

#### 功能特性

- 用于重新配置、添加或删除 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream)
  块中服务器的 [HTTP RESTful JSON 接口](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config),
  以及用于持久化这些更改的 [state](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-state) 指令。
- [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe) 指令,通过定期发送探测请求来检查
  [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 块中服务器的健康状况。
- [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy) 代理模块中的缓存分片支持,
  可以根据任意响应参数将响应缓存到不同的目录(驱动器)中,
  通过 [proxy_cache](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache) 指令的新 `path-` 选项使用变量进行配置。
- 在使用 [TongSuo](https://github.com/Tongsuo-Project/Tongsuo) TLS 库时,
  [HTTP](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#stream-ssl) 模块中的 NTLS 支持;
  可以通过 `‑‑with‑ntls` 构建时选项启用该支持,
  并使用相应的 [ssl_ntls](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-ntls) 和 [proxy_ssl_ntls](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-ntls) 指令进行配置。
- 在 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#stream-proxy) 代理模块中,
  能够使用 [proxy_ssl_certificate](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-certificate) 和 [proxy_ssl_certificate_key](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-certificate-key) 指令
  指定多个不同类型(RSA 和 ECDSA)的证书及相应的密钥。
- 在 `master` 进程标题中显示版本和构建名称,
  这允许使用 `ps` 工具获取正在运行的服务器实例的此信息。
- [gzip](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#http-gzip) 模块能够压缩 "207 Multi-Status" 响应。
  感谢 [DBotThePony](https://github.com/webserver-llc/angie/pull/26)。
- [nginx 1.25.0](https://nginx.org/en/CHANGES) 的所有功能,
  包括 [HTTP/3](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#http-v3) 支持。

<a id="changes-2"></a>

#### 变更

- [$upstream_sticky_status](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-sticky-status) 变量值现在为大写,
  以与 [$upstream_cache_status](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-cache-status) 值的风格保持一致。

#### 软件包

- 新增动态模块:
  - [angie-pro-module-enhanced-memcached](https://github.com/bpaquet/ngx_http_enhanced_memcached_module)
  - [angie-pro-module-eval](https://github.com/openresty/nginx-eval-module)

---

<a id="angie-pro-1-1-0-p1"></a>

### Angie PRO 1.1.0-p1

发布日期:2023 年 3 月 1 日。

#### 功能特性

- [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 块中的
  [sticky](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky) 指令及相关选项,允许配置会话保持模式,
  其中会话的所有请求都路由到同一服务器。
- [$upstream_sticky_status](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-sticky-status) 变量,根据启用会话保持时请求相关上游服务器的成功情况,
  可以是 `NEW`、`HIT` 或 `MISS`。

---

<a id="angie-pro-1-1-0"></a>

### Angie PRO 1.1.0

发布日期:2023 年 2 月 7 日。

#### 功能特性

- [api](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#a-api) 指令,提供 HTTP RESTful 接口,
  以 JSON 或 Prometheus 格式访问 Web 服务器实例的基本信息,
  以及客户端连接、共享内存区域、DNS 查询、HTTP 请求、HTTP 响应缓存、
  [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#stream-core) 模块的 TCP/UDP 会话、
  [limit_conn](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_conn.md#http-limit-conn)/[limit_req](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_req.md#http-limit-req) 模块的区域
  和 [HTTP 上游服务器组](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 的 [指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#metrics)。
- [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 块中
  [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 指令的 [resolve](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve) 选项,
  允许监控与域名对应的 IP 地址列表的变化,并自动更新它而无需重新加载配置。
- [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块的 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 块中
  [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 指令的 [service](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve) 选项,
  允许从 DNS SRV 记录中检索地址列表,并提供基本的优先级支持。
- [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#http-core) 模块中的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#status-zone) 指令,
  用于在 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 和 [location](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#location) 上下文中指定区域以收集请求指标。
- [stream](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#stream-core) 模块中的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-status-zone) 指令,
  用于指定区域以收集 TCP/UDP 会话指标。
- [resolver](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver) 指令的 [status_zone](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#resolver-status) 参数,
  用于指定区域以收集 DNS 查询指标。
- [autoindex](https://cn.angie.software//angie/docs/configuration/modules/http/http_autoindex.md#id3) 对目录列表使用自然排序顺序。
- 通过 [server_tokens](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-tokens) 指令任意配置默认错误页面上的签名和
  `Server` 响应头字段。
- [$angie_version](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-angie-version) 变量,包含 Angie 的版本。
- [nginx 1.23.3](https://nginx.org/en/CHANGES) 的所有功能。

#### 软件包

2023 年 4 月 7 日

- 新增 [ALT](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-alt-pro) Linux 软件包。

2023 年 5 月 12 日

- 新增 [FreeBSD](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-freebsd-pro) 软件包。
- 新增动态模块:
  - [angie-pro-module-subs](https://github.com/yaoweibin/ngx_http_substitutions_filter_module)
  - [angie-pro-module-upload](https://github.com/fdintino/nginx-upload-module)
  - [angie-pro-module-vod](https://github.com/kaltura/nginx-vod-module)

2023 年 5 月 26 日

- 新增 [Astra](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-astrase-pro) Linux Special Edition 软件包。

2023 年 6 月 13 日

- 新增 [Debian 12 "Bookworm"](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-deb-pro) 和
  [AlmaLinux](https://cn.angie.software//angie/docs/installation/pro_packages.md#install-yum-pro) 软件包。

2023 年 7 月 12 日

- 新增动态模块:
  - [angie-pro-module-cache-purge](https://github.com/nginx-modules/ngx_cache_purge)
  - [angie-pro-module-echo](https://github.com/openresty/echo-nginx-module)
  - [angie-pro-module-keyval](https://github.com/kjdev/nginx-keyval)
  - [angie-pro-module-postgres](https://github.com/FRiCKLE/ngx_postgres)
- 更新:
  - [angie-pro-module-njs](https://cn.angie.software//angie/docs/installation/external-modules/njs.md#external-njs),更新至版本 0.8.0

2023 年 7 月 31 日

- 新增动态模块:
  - [angie-pro-module-auth-jwt](https://github.com/kjdev/nginx-auth-jwt)


# https://cn.angie.software/angie/docs/installation/pro_packages.md

<!-- review: finished -->

<a id="pro-packages"></a>

# Angie PRO 软件包安装

要访问软件包仓库，
您需要签订合同并购买许可证。
有关许可证、合同和定制构建的问题，请联系：

- [info@wbsrv.ru](mailto:info@wbsrv.ru)
- [https://angie.software/](https://angie.software/)
- +7 (495) 120 50 33

然后，为您的发行版的软件包管理器配置仓库
以安装和更新 Angie PRO
以及您需要的 [动态模块](#install-dynamicmodules-pro)。
最后，安装 [许可证文件](#install-license)
并解除限制。

<a id="distributions-1"></a>

## 发行版

| 名称                                | 版本                             | 架构                            |
|-----------------------------------|--------------------------------|-------------------------------|
| [AlmaLinux](#install-yum-pro)     | 10,  9,  8                     | x86-64, arm64                 |
| [Alpine](#install-alpine-pro)     | 3.23,  3.22,  3.21,  3.20      | x86-64, arm64                 |
| [Alt](#install-alt-pro)           | 11,  10  8                     | x86-64, arm64  x86-64         |
| [Astra SE](#install-astrase-pro)  | 4.7  1.8, 1.7                  | arm64  x86-64                 |
| [CentOS](#install-yum-pro)        | 10,  9                         | x86-64, arm64                 |
| [Debian](#install-deb-pro)        | 13,  12,  11                   | x86-64, arm64                 |
| [Fedora](#install-yum-pro)        | 44,  43                        | x86-64, arm64                 |
| [FreeBSD](#install-freebsd-pro)   | 15,  14,  13                   | x86-64, arm64                 |
| [MSVSphere](#install-yum-pro)     | 10,  9  8                      | x86-64, arm64  x86-64         |
| [openSUSE](#install-opensuse-pro) | 16,  15                        | x86-64, arm64                 |
| [Oracle Linux](#install-yum-pro)  | 10,  9,  8                     | x86-64, arm64                 |
| [OSNova](#install-osnova-pro)     | 3.3.0,  2.13                   | x86-64                        |
| [RED OS](#install-yum-pro)        | 8,  7                          | x86-64, arm64                 |
| [Rocky Linux](#install-yum-pro)   | 10,  9,  8                     | x86-64, arm64                 |
| [ROSA](#install-yum-pro)          | Chrome 13  Chrome 12  Fresh 12 | x86-64  x86-64, arm64  x86-64 |
| [SberLinux](#install-yum-pro)     | 9                              | x86-64                        |
| [Ubuntu](#install-deb-pro)        | 26.04,  24.04,  22.04          | x86-64, arm64                 |

<a id="install-yum-pro"></a>

### Alma、CentOS、Fedora、MSVSphere、Oracle、RED OS、Rocky、ROSA、SberLinux

1. 创建 `/etc/ssl/angie/` 目录：
   ```console
   $ sudo mkdir -p /etc/ssl/angie/
   ```
2. 传输您随许可证收到的文件：

   | 文件类型   | 原始名称             | 放置位置                            |
   |--------|------------------|---------------------------------|
   | 证书     | `angie-repo.crt` | `/etc/ssl/angie/angie-repo.crt` |
   | 私钥     | `angie-repo.key` | `/etc/ssl/angie/angie-repo.key` |
3. 要添加仓库，
   创建文件
   `/etc/yum.repos.d/angie.repo`
   包含以下内容：

   Alma
   ```ini
   [angie-pro]
   name=Angie PRO repo
   baseurl=https://download.angie.software/angie-pro/almalinux/$releasever/
   sslclientcert=/etc/ssl/angie/angie-repo.crt
   sslclientkey=/etc/ssl/angie/angie-repo.key
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   CentOS
   ```ini
   [angie-pro]
   name=Angie PRO repo
   baseurl=https://download.angie.software/angie-pro/centos/$releasever/
   sslclientcert=/etc/ssl/angie/angie-repo.crt
   sslclientkey=/etc/ssl/angie/angie-repo.key
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   Fedora
   ```ini
   [angie-pro]
   name=Angie PRO repo
   baseurl=https://download.angie.software/angie-pro/fedora/$releasever/
   sslclientcert=/etc/ssl/angie/angie-repo.crt
   sslclientkey=/etc/ssl/angie/angie-repo.key
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   MSVSphere
   ```ini
   [angie-pro]
   name=Angie PRO repo
   baseurl=https://download.angie.software/angie-pro/msvsphere/$releasever/
   sslclientcert=/etc/ssl/angie/angie-repo.crt
   sslclientkey=/etc/ssl/angie/angie-repo.key
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   Oracle
   ```ini
   [angie-pro]
   name=Angie PRO repo
   baseurl=https://download.angie.software/angie-pro/oracle/$releasever/
   sslclientcert=/etc/ssl/angie/angie-repo.crt
   sslclientkey=/etc/ssl/angie/angie-repo.key
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   RED OS
   ```ini
   [angie-pro]
   name=Angie PRO repo
   baseurl=https://download.angie.software/angie-pro/redos/$releasever/
   sslclientcert=/etc/ssl/angie/angie-repo.crt
   sslclientkey=/etc/ssl/angie/angie-repo.key
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   Rocky
   ```ini
   [angie-pro]
   name=Angie PRO repo
   baseurl=https://download.angie.software/angie-pro/rocky/$releasever/
   sslclientcert=/etc/ssl/angie/angie-repo.crt
   sslclientkey=/etc/ssl/angie/angie-repo.key
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   ROSA Chrome
   ```ini
   [angie-pro]
   name=Angie PRO repo
   baseurl=https://download.angie.software/angie-pro/rosa-chrome/$releasever/
   sslclientcert=/etc/ssl/angie/angie-repo.crt
   sslclientkey=/etc/ssl/angie/angie-repo.key
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   ROSA Fresh
   ```ini
   [angie-pro]
   name=Angie PRO repo
   baseurl=https://download.angie.software/angie-pro/rosa/$releasever/
   sslclientcert=/etc/ssl/angie/angie-repo.crt
   sslclientkey=/etc/ssl/angie/angie-repo.key
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```

   SberLinux
   ```ini
   [angie-pro]
   name=Angie PRO repo
   baseurl=https://download.angie.software/angie-pro/sberlinux/$releasever/
   sslclientcert=/etc/ssl/angie/angie-repo.crt
   sslclientkey=/etc/ssl/angie/angie-repo.key
   gpgcheck=1
   enabled=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```
4. 安装 Angie PRO 软件包：
   ```console
   $ sudo yum install -y angie-pro
   $ # -- 或 --
   $ sudo dnf install -y angie-pro
   ```
5. （ *可选*）安装您需要的任何 [额外](#install-extras-pro)
   软件包：
   ```console
   $ sudo yum install -y <软件包名称>
   $ # -- 或 --
   $ sudo dnf install -y <软件包名称>
   ```
6. 启动服务：
   ```console
   $ sudo systemctl start angie
   ```
7. 要在服务器重启后自动启动 Angie PRO：
   ```console
   $ sudo systemctl enable angie
   ```

<a id="install-alpine-pro"></a>

### Alpine

1. 传输您随许可证收到的文件：

   | 文件类型   | 原始名称             | 放置位置                |
   |--------|------------------|---------------------|
   | 证书     | `angie-repo.crt` | `/etc/apk/cert.pem` |
   | 私钥     | `angie-repo.key` | `/etc/apk/cert.key` |
2. 安装用于添加 Angie PRO 仓库的辅助软件包：
   ```console
   $ sudo apk update
   $ sudo apk add curl ca-certificates
   ```
3. 下载 Angie PRO 仓库的公钥用于软件包验证：
   ```console
   $ sudo curl -o /etc/apk/keys/angie-signing.rsa \
               https://angie.software/keys/angie-signing.rsa
   ```
4. 添加 Angie PRO 仓库：
   ```console
   $ echo "https://download.angie.software/angie-pro/alpine/v$(egrep -o \
          '[0-9]+\.[0-9]+' /etc/alpine-release)/main" \
          | sudo tee -a /etc/apk/repositories > /dev/null
   ```
5. 更新仓库索引：
   ```console
   $ sudo apk update
   ```
6. 安装 Angie PRO 软件包：
   ```console
   $ sudo apk add angie-pro
   ```
7. （ *可选*）安装您需要的任何 [额外](#install-extras-pro)
   软件包：
   ```console
   $ sudo apk add <软件包名称>
   ```
8. 启动服务：
   ```console
   $ sudo service angie start
   ```
9. 要在服务器重启后自动启动 Angie PRO：
   ```console
   $ sudo rc-update add angie
   ```

<a id="install-alt-pro"></a>

### Alt

1. 创建 `/etc/ssl/angie/` 目录:
   ```console
   $ sudo mkdir -p /etc/ssl/angie/
   ```
2. 传输您随许可证收到的文件:

   | 文件类型   | 原始名称             | 放置位置                            |
   |--------|------------------|---------------------------------|
   | 证书     | `angie-repo.crt` | `/etc/ssl/angie/angie-repo.crt` |
   | 私钥     | `angie-repo.key` | `/etc/ssl/angie/angie-repo.key` |
3. 下载 Angie PRO 仓库的公钥用于软件包验证:
   ```console
   $ curl -o ~/angie-signing.gpg https://angie.software/keys/angie-signing.gpg && \
          sudo gpg --no-default-keyring --keyring /usr/lib/alt-gpgkeys/pubring.gpg --import ~/angie-signing.gpg
   ```
4. 保存密钥签名:
   ```sh
   $ echo 'simple-key "angie-pro" {
             Fingerprint "EB8EAF3D4EF1B1ECF34865A2617AB978CB849A76";
             Name "Angie PRO (Signing Key) <devops@tech.wbsrv.ru>";
     }' | sudo tee /etc/apt/vendors.list.d/angie.list > /dev/null
   ```
5. 添加 Angie PRO 仓库:

   Alt 11
   ```console
   $ echo "rpm [angie-pro] https://download.angie.software/angie-pro/altlinux/11/ $(uname -m) main" \
       | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```

   Alt 10
   ```console
   $ echo "rpm [angie-pro] https://download.angie.software/angie-pro/altlinux/10/ $(uname -m) main" \
       | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```

   Alt SP 10
   ```console
   $ echo "rpm [angie-pro] https://download.angie.software/angie-pro/altlinux-sp/10/ $(uname -m) main" \
       | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```

   Alt SP 8
   ```console
   $ echo "rpm [angie-pro] https://download.angie.software/angie-pro/altlinux-sp/8/ $(uname -m) main" \
       | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```
6. 在 `/etc/apt/apt.conf.d` 中创建 Angie PRO 仓库 `apt` 配置文件:
   ```console
   $ ( echo 'Acquire::https::Verify-Peer "true";';
       echo 'Acquire::https::Verify-Host "true";';
       echo 'Acquire::https::SslCert     "/etc/ssl/angie/angie-repo.crt";';
       echo 'Acquire::https::SslKey      "/etc/ssl/angie/angie-repo.key";';
     )  | sudo tee -a /etc/apt/apt.conf >/dev/null
   ```
7. 更新仓库索引:
   ```console
   $ sudo apt-get update
   ```
8. 安装 Angie PRO 软件包:
   ```console
   $ sudo apt-get install -y angie-pro
   ```
9. ( *可选*) 安装您需要的任何 [额外](#install-extras-pro) 软件包:
   ```console
   $ sudo apt-get install -y <PACKAGE NAME>
   ```
10. 启动服务:
    ```console
    $ sudo systemctl start angie
    ```
11. 要在服务器重启后自动启动 Angie PRO:
    ```console
    $ sudo systemctl enable angie
    ```

<a id="install-astrase-pro"></a>

### Astra SE

1. 创建 `/etc/ssl/angie/` 目录:
   ```console
   $ sudo mkdir -p /etc/ssl/angie/
   ```
2. 传输您随许可证收到的文件:

   | 文件类型   | 原始名称             | 放置位置                            |
   |--------|------------------|---------------------------------|
   | 证书     | `angie-repo.crt` | `/etc/ssl/angie/angie-repo.crt` |
   | 私钥     | `angie-repo.key` | `/etc/ssl/angie/angie-repo.key` |

   限制对目录和文件的访问:
   ```console
   $ sudo chown -R _apt:nogroup /etc/ssl/angie/
   ```
3. 安装用于添加 Angie PRO 仓库的辅助软件包:
   ```console
   $ sudo apt-get update
   $ sudo apt-get install -y apt-transport-https lsb-release \
                  ca-certificates curl gnupg2
   ```
4. 下载 Angie PRO 仓库的公钥用于软件包验证:
   ```console
   $ sudo curl -o /etc/apt/trusted.gpg.d/angie-signing.gpg \
               https://angie.software/keys/angie-signing.gpg
   ```
5. 添加 Angie PRO 仓库:
   ```console
   $ echo "deb https://download.angie.software/angie-pro/astra-se/$(egrep -o \
          '[0-9]+\.[0-9]+' /etc/astra_version) unstable main" \
          | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```
6. 要配置仓库,创建文件 `/etc/apt/apt.conf.d/90download-angie`,内容如下:
   ```console
   Acquire::https::download.angie.software::Verify-Peer "true";
   Acquire::https::download.angie.software::Verify-Host "true";
   Acquire::https::download.angie.software::SslCert     "/etc/ssl/angie/angie-repo.crt";
   Acquire::https::download.angie.software::SslKey      "/etc/ssl/angie/angie-repo.key";
   ```
7. 更新仓库索引:
   ```console
   $ sudo apt-get update
   ```
8. ( *可选*) 当在封闭软件环境模式 ([CSE](https://wiki.astralinux.ru/pages/viewpage.action?pageId=41190634)) 下运行时,
   安装用于验证 Angie PRO 可执行文件真实性的密钥软件包:
   ```console
   $ sudo apt-get install -y angie-digsig-key
   ```

   更新 CSE:
   ```console
   $ sudo update-initramfs -uk all
   ```

   然后 **重启服务器**:
   ```console
   $ sudo shutdown -r now
   ```
9. 安装 Angie PRO 软件包:
   ```console
   $ sudo apt-get install -y angie-pro
   ```
10. ( *可选*) 安装您需要的任何 [额外](#install-extras-pro) 软件包:
    ```console
    $ sudo apt-get install -y <PACKAGE NAME>
    ```

<a id="install-deb-pro"></a>

### Debian、Ubuntu

1. 创建 `/etc/ssl/angie/` 目录:
   ```console
   $ sudo mkdir -p /etc/ssl/angie/
   ```
2. 传输您随许可证收到的文件:

   | 文件类型   | 原始名称             | 放置位置                            |
   |--------|------------------|---------------------------------|
   | 证书     | `angie-repo.crt` | `/etc/ssl/angie/angie-repo.crt` |
   | 私钥     | `angie-repo.key` | `/etc/ssl/angie/angie-repo.key` |

   限制对目录和文件的访问:
   ```console
   $ sudo chown -R _apt:nogroup /etc/ssl/angie/
   ```
3. 安装添加 Angie PRO 仓库所需的前置条件:
   ```console
   $ sudo apt-get update
   $ sudo apt-get install -y apt-transport-https lsb-release \
                  ca-certificates curl gnupg2
   ```
4. 下载 Angie PRO 仓库的公钥用于软件包验证:
   ```console
   $ sudo curl -o /etc/apt/trusted.gpg.d/angie-signing.gpg \
               https://angie.software/keys/angie-signing.gpg
   ```
5. 添加 Angie PRO 仓库:
   ```console
   $ echo "deb https://download.angie.software/angie-pro/$(. /etc/os-release && echo "$ID/$VERSION_ID $VERSION_CODENAME") main" \
       | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```
6. 要配置仓库,创建名为 `/etc/apt/apt.conf.d/90download-angie` 的文件,内容如下:
   ```console
   Acquire::https::download.angie.software::Verify-Peer "true";
   Acquire::https::download.angie.software::Verify-Host "true";
   Acquire::https::download.angie.software::SslCert     "/etc/ssl/angie/angie-repo.crt";
   Acquire::https::download.angie.software::SslKey      "/etc/ssl/angie/angie-repo.key";
   ```
7. 更新仓库索引:
   ```console
   $ sudo apt-get update
   ```
8. 安装 Angie PRO 软件包:
   ```console
   $ sudo apt-get install -y angie-pro
   ```
9. ( *可选*) 安装您需要的任何 [额外](#install-extras-pro) 软件包:
   ```console
   $ sudo apt-get install -y <PACKAGE NAME>
   ```

<a id="install-osnova-pro"></a>

### OSNova

1. 安装添加 Angie PRO 仓库所需的前置条件:
   ```console
   $ sudo apt-get update
   $ sudo apt-get install -y ca-certificates curl
   ```
2. 下载 Angie PRO 仓库的公钥用于软件包验证:
   ```console
   $ sudo curl -o /etc/apt/trusted.gpg.d/angie-signing.gpg \
               https://angie.software/keys/angie-signing.gpg
   ```
3. 添加 Angie PRO 仓库:
   ```console
   $ echo "deb https://download.angie.software/angie-pro/osnova/$(egrep -o \
          '[0-9]*' /etc/osnova_version | head -1) \
          $(. /etc/os-release && echo "$VERSION_CODENAME") main" \
          | sudo tee /etc/apt/sources.list.d/angie.list > /dev/null
   ```
4. 更新仓库索引:
   ```console
   $ sudo apt-get update
   ```
5. 安装 Angie PRO 软件包:
   ```console
   $ sudo apt-get install -y angie
   ```
6. ( *可选*) 安装您需要的任何 [额外](#install-extras-pro) 软件包:
   ```console
   $ sudo apt-get install -y <PACKAGE NAME>
   ```

<a id="install-freebsd-pro"></a>

### FreeBSD

1. 要添加 Angie PRO 仓库，创建以下目录：
   ```console
   $ sudo mkdir -p /usr/local/etc/pkg/angie/ /usr/local/etc/pkg/repos/
   ```
2. 要配置仓库，创建名为 `/usr/local/etc/pkg/repos/angie.conf` 的文件，内容如下：
   ```pkgconfig
   angie: {
      url: "https://download.angie.software/angie-pro/freebsd/${VERSION_MAJOR}/${ARCH}",
      signature_type: "pubkey",
      pubkey: "/usr/local/etc/pkg/angie/angie-signing.rsa",
      enabled: yes
   }
   ```
3. 下载 Angie PRO 仓库的公钥用于软件包验证：
   ```console
   $ sudo curl -o /usr/local/etc/pkg/angie/angie-signing.rsa \
               https://angie.software/keys/angie-signing.rsa
   ```
4. 传输您随许可证收到的文件：

   | 文件类型   | 原始名称             | 位置                                        |
   |--------|------------------|-------------------------------------------|
   | 证书     | `angie-repo.crt` | `/usr/local/etc/pkg/angie/angie-repo.crt` |
   | 私钥     | `angie-repo.key` | `/usr/local/etc/pkg/angie/angie-repo.key` |
5. 将证书和密钥添加到软件包管理器的配置中：
   ```sh
   $ echo '
     PKG_ENV: {
       SSL_CLIENT_CERT_FILE: "/usr/local/etc/pkg/angie/angie-repo.crt",
       SSL_CLIENT_KEY_FILE:  "/usr/local/etc/pkg/angie/angie-repo.key"
     }' | sudo tee -a /usr/local/etc/pkg.conf > /dev/null
   ```
6. 更新仓库索引：
   ```console
   $ sudo pkg update
   ```
7. 安装 Angie PRO 软件包：
   ```console
   $ sudo pkg install -r angie -y angie-pro
   ```
8. （ *可选*）安装您需要的任何 [额外](#install-extras-pro) 软件包：
   ```console
   $ sudo pkg install -r angie -y <PACKAGE NAME>
   ```
9. 启动服务：
   ```console
   $ sudo service angie start
   ```
10. 要在服务器重启后自动启动 Angie PRO：
    ```console
    $ sudo sysrc angie_enable=YES
    ```

#### NOTE
由于 FreeBSD 软件包管理器可能无法正确确定最新版本，
请使用以下方法更新已安装的软件包：

```console
$ sudo pkg upgrade `pkg search -r angie angie-pro-[0-9] | sort -Vr | head -1 | awk {'print $1'}`
```

<a id="install-opensuse-pro"></a>

### openSUSE

1. 创建 `/etc/ssl/angie/` 目录：
   ```console
   $ sudo mkdir -p /etc/ssl/angie/
   ```
2. 传输您随许可证收到的文件：

   | 文件类型   | 原始名称             | 位置                              |
   |--------|------------------|---------------------------------|
   | 证书     | `angie-repo.crt` | `/etc/ssl/angie/angie-repo.crt` |
   | 私钥     | `angie-repo.key` | `/etc/ssl/angie/angie-repo.key` |

   然后将它们合并到捆绑文件 `/etc/ssl/angie/angie-repo-bundle.crt` 中：
   ```console
   $ cat /etc/ssl/angie/angie-repo.crt /etc/ssl/angie/angie-repo.key | \
         sudo tee -a /etc/ssl/angie/angie-repo-bundle.crt > /dev/null
   ```
3. 要添加仓库，创建名为 `/etc/zypp/repos.d/angie.repo` 的文件，内容如下：
   ```ini
   [angie-pro]
   enabled=1
   autorefresh=1
   baseurl=https://download.angie.software/angie-pro/opensuse/$releasever_major?ssl_clientcert=/etc/ssl/angie/angie-repo-bundle.crt&ssl_verify=peer
   gpgcheck=1
   gpgkey=https://angie.software/keys/angie-signing.gpg.asc
   ```
4. 更新仓库索引：
   ```console
   $ sudo zypper refresh
   ```
5. 安装 Angie PRO 软件包：
   ```console
   $ sudo zypper install -y angie-pro
   ```
6. （ *可选*）安装您需要的任何 [额外](#install-extras-pro) 软件包：
   ```console
   $ sudo zypper install -y <PACKAGE NAME>
   ```
7. 启动服务：
   ```console
   $ sudo systemctl start angie
   ```
8. 要在服务器重启后自动启动 Angie PRO：
   ```console
   $ sudo systemctl enable angie
   ```

<a id="install-extras-pro"></a>

## 额外软件包

除了提供核心功能的软件包外，
我们还发布了几个额外的软件包，
包括我们自己的和来自精选第三方来源的软件包。

<a id="install-console-light-pro"></a>

### Console Light 网页面板

Console Light 是一个轻量级的 Angie PRO [监控网页面板](https://cn.angie.software//angie/docs/configuration/monitoring.md#monitoring)，
在我们的仓库中以 `angie-pro-console-light` 软件包发布。
它的安装方式与上述说明中的 `angie` 软件包相同；
有关配置说明，请参阅 [Console Light Web 监控面板](https://cn.angie.software//angie/docs/configuration/monitoring.md#monitoring) 部分。

<a id="install-dynamicmodules-pro"></a>

### 动态模块

要扩展 Angie PRO 的基本功能，
您可以添加各种动态模块。
您可以从我们的仓库获取现成的软件包：

| [angie-pro-module-image-filter](https://cn.angie.software//angie/docs/configuration/modules/http/http_image_filter.md#http-image-filter)                                                                                                     | 为 JPEG、GIF、PNG 和 WebP 格式添加图像转换功能。                                     |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| angie-pro-module-njs：<br/>[JS](https://cn.angie.software//angie/docs/installation/external-modules/http_js.md#http-js) （HTTP），<br/>[JS](https://cn.angie.software//angie/docs/installation/external-modules/stream_js.md#stream-js) （stream） | 允许在 Angie PRO 配置中分别在 `http` 和 `stream` 上下文中使用 njs 语言（JavaScript 的子集）。 |
| [angie-pro-module-perl](https://cn.angie.software//angie/docs/configuration/modules/http/http_perl.md#http-perl)                                                                                                                             | 允许用 Perl 编写 `location` 和变量处理程序，<br/>以及从 SSI 调用 Perl。                  |
| [angie-pro-module-xslt](https://cn.angie.software//angie/docs/configuration/modules/http/http_xslt.md#http-xslt)                                                                                                                             | 添加一个过滤器，使用 XSLT 模板转换 XML 响应。                                          |

要在您的 [配置](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile) 中应用已安装的模块，
请在 `main` 上下文中使用 [load_module](https://cn.angie.software//angie/docs/configuration/modules/core.md#load-module) 指令加载它：

```nginx
load_module modules/<module name>.so;
```

还有大量的 [第三方模块](https://cn.angie.software//angie/docs/installation/external-modules/index.md#install-thirdpartymodules) 可用。

<a id="install-license"></a>

## 许可证文件

配置 Angie PRO 的许可证：

1. 将许可证文件保存为 `/etc/angie/license.pem`，
   设置与您的 [客户端证书](https://cn.angie.software//angie/docs/configuration/ssl.md#ssl-config) 相同的权限。
2. 验证许可证是否有效；
   否则，检查详细信息：
   ```console
   $ sudo angie -t

     angie: Valid license found:
     angie:   - owner: CN=Angie Client License
     angie:   - period: Jul  8 21:00:00 2024 GMT .. Jul 17 20:59:59 2024 GMT
     angie:
     angie: Limitations:
     angie:   - worker_processes_limit: 8
     angie:   - worker_connections_limit: 0
   ```
3. 监控控制台和日志以查看任何许可证问题。
   如果许可证在运行期间过期，
   Angie PRO 会定期发出相应的警告。
   此外，在重新加载时，如果例如超出了许可证条款中
   指定的工作进程数量，将会出现配置错误消息。
4. 修改 `/etc/angie/angie.conf` 文件；
   安装后，其中的两个参数限制了运行：
   ```nginx
   worker_processes 1;
   worker_connections 256;
   ```

   保存许可证文件后，
   根据您的许可证条款更改它们，例如：
   ```nginx
   worker_processes 8;
   worker_connections 65535;
   ```


# https://cn.angie.software/angie/docs/configuration/processing.md

<!-- review: finished -->

<a id="processing"></a>

# 连接、会话、请求、日志

<a id="methods-use"></a>

## 连接处理机制

Angie 支持多种连接处理方法。特定方法的可用性取决于所使用的平台。在支持多种方法的平台上,Angie 通常会自动选择最高效的方法。但是,如有必要,可以使用 [use](https://cn.angie.software//angie/docs/configuration/modules/core.md#use) 指令显式选择连接处理方法。

以下是可用的连接处理方法:

<!-- Legacy links -->

<a id="select"></a>

<a id="poll"></a>

<a id="kqueue"></a>

<a id="epoll"></a>

<a id="dev-poll"></a>

<a id="eventport"></a>

| 方法          | 描述                                                                                                     |
|-------------|--------------------------------------------------------------------------------------------------------|
| `select`    | 标准方法。在没有更高效方法的平台上会自动构建支持模块。可以使用 `--with-select_module` 和 `--without-select_module` 构建选项来强制启用或禁用此模块的构建。 |
| `poll`      | 标准方法。在没有更高效方法的平台上会自动构建支持模块。可以使用 `--with-poll_module` 和 `--without-poll_module` 构建选项来强制启用或禁用此模块的构建。     |
| `kqueue`    | 高效方法,可用于 FreeBSD 4.1+、OpenBSD 2.9+、NetBSD 2.0 和 macOS。                                                 |
| `epoll`     | 高效方法,可用于 Linux 2.6+。                                                                                   |
| `/dev/poll` | 高效方法,可用于 Solaris 7 11/99+、HP/UX 11.22+ (eventport)、IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+。                    |
| `eventport` | `event ports` 方法可用于 Solaris 10+。(由于已知问题,建议改用 `/dev/poll` 方法。)                                          |

<a id="http-sessions"></a>

## HTTP 请求处理

HTTP 请求会经历一系列阶段,在每个阶段执行特定类型的处理。

| `Post-read`      | 初始阶段。在此阶段调用 [RealIP](https://cn.angie.software//angie/docs/configuration/modules/http/http_realip.md#http-realip) 模块。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
|------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `Server-rewrite` | 处理 [Rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#http-rewrite) 模块中定义在 `server` 块(但在 `location` 块之外)的指令的阶段。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `Find-config`    | 特殊阶段,根据请求 URI 选择 [location](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#location)。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `Rewrite`        | 类似于 `Server-rewrite` 阶段,但它应用于在上一阶段选择的 location 块中定义的 [rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 规则。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `Post-rewrite`   | 特殊阶段,如果在 `Rewrite` 阶段修改了请求的 URI,则将请求重定向到新的 location,如同 `Find-config` 阶段。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `Preaccess`      | 在此阶段,标准 Angie 模块(如 [Limit Req](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_req.md#http-limit-req))注册它们的处理程序。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `Access`         | 验证客户端是否有权发出请求的阶段,通常通过调用标准 Angie 模块(如 [Auth Basic](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_basic.md#http-auth-basic))来实现。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `Post-access`    | 特殊阶段,处理 [satisfy any](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#satisfy) 指令。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `Precontent`     | 标准模块指令(如 [try_files](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#try-files) 和 [mirror](https://cn.angie.software//angie/docs/configuration/modules/http/http_mirror.md#id3))在此阶段注册它们的处理程序。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `Content`        | 通常生成响应的阶段。多个标准 Angie 模块在此阶段注册它们的处理程序,包括 [Index](https://cn.angie.software//angie/docs/configuration/modules/http/http_index.md#http-index)。[proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass)、[fastcgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-pass)、[uwsgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-pass)、[scgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-pass) 和 [grpc_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_grpc.md#grpc-pass) 指令也在此处理。<br/><br/>处理程序按顺序调用,直到其中一个产生输出。 |
| `Log`            | 最后阶段,执行请求日志记录。目前只有 [Log](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#http-log) 模块在此阶段注册其处理程序以进行访问日志记录。                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |

<a id="stream-sessions"></a>

## TCP/UDP 会话处理

来自客户端的 TCP/UDP 会话会经历一系列阶段,在每个阶段执行特定类型的处理:

| `Post-accept`   | 接受客户端连接后的初始阶段。在此阶段调用 [RealIP](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_realip.md#stream-realip) 模块。                                                                                                                                   |
|-----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `Pre-access`    | 检查访问权限的预备阶段。在此阶段调用 [Set](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_set.md#stream-set) 模块。                                                                                                                                              |
| `Access`        | 在实际数据处理之前限制客户端访问的阶段。在此阶段调用 [Access](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_access.md#stream-access) 模块。                                                                                                                             |
| `SSL`           | 发生 TLS/SSL 终止的阶段。在此阶段调用 [SSL](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#stream-ssl) 模块。                                                                                                                                         |
| `Preread`       | 将初始数据字节读入 [预读缓冲区](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-preread-buffer-size) 的阶段,以允许模块(如 [SSL Preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#stream-ssl-preread))在处理之前分析数据。 |
| `Content`       | 实际处理数据的强制阶段,通常涉及 [Return](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_return.md#stream-return) 模块向客户端发送响应。[proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#s-proxy-pass) 指令也在此处理。         |
| `Log`           | 记录客户端会话处理结果的最后阶段。在此阶段调用 [Log](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_log.md#stream-log) 模块。                                                                                                                                         |

<a id="request-processing"></a>

## 处理请求

<a id="virtual-server-selection"></a>

### 虚拟服务器选择

最初,连接是在默认服务器的上下文中创建的。然后可以在请求处理的以下阶段确定服务器名称,每个阶段都参与服务器配置的选择:

- 在 SSL 握手期间,根据 SNI 提前确定。
- 处理请求行之后。
- 处理 `Host` 头字段之后。

如果在处理请求行或 `Host` 头字段之后未确定服务器名称,Angie 将使用空名称作为服务器名称。

在这些阶段的每一个阶段,都可能应用不同的服务器配置。因此,某些指令应谨慎指定:

- 对于 [ssl_protocols](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-protocols) 指令,协议列表由 OpenSSL 库在根据通过 SNI 请求的名称应用服务器配置之前设置。因此,协议应仅为默认服务器指定。
- [client_header_buffer_size](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-header-buffer-size) 和 [merge_slashes](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#merge-slashes) 指令在读取请求行之前应用。因此,这些指令使用默认服务器配置或由 SNI 选择的服务器配置。
- 对于 [ignore_invalid_headers](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#ignore-invalid-headers)、[large_client_header_buffers](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#large-client-header-buffers) 和 [underscores_in_headers](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#underscores-in-headers) 指令,它们参与处理请求头字段,服务器配置还取决于是否根据请求行或 `Host` 头字段进行了更新。
- 错误响应使用当前正在处理请求的服务器中的 [error_page](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#error-page) 指令处理。

<a id="name-based-virtual-servers"></a>

### 基于名称的虚拟服务器

Angie 首先确定哪个服务器应该处理请求。考虑一个简单的配置,其中所有三个虚拟服务器都监听端口 80:

```nginx
server {

    listen 80;
    server_name example.org www.example.org;
    # ...
}

server {

    listen 80;
    server_name example.net www.example.net;
    #  ...
}

server {

    listen 80;
    server_name example.com www.example.com;
    #  ...
}
```

在此配置中,Angie 仅根据 `Host` 头字段确定哪个服务器应该处理请求。如果此头的值与任何服务器名称都不匹配,或者请求不包含此头字段,Angie 将把请求路由到此端口的默认服务器。在上面的配置中,默认服务器是第一个——这是 Angie 的标准默认行为。也可以使用 [listen](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#listen) 指令中的 `default_server` 参数显式指定哪个服务器应该是默认服务器:

```nginx
server {

    listen 80 default_server;
    server_name example.net www.example.net;
    #  ...
}
```

#### NOTE
请注意,默认服务器是监听套接字的属性,而不是服务器名称的属性。

<a id="internationalized"></a>

### 国际化名称

国际化域名([IDN](https://en.wikipedia.org/wiki/Internationalized_domain_name))应在 [server_name](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name)
指令中使用 ASCII(Punycode)表示形式指定:

```nginx
server {

    listen 80;
    server_name xn--e1afmkfd.xn--80akhbyknj4f; # пример.испытание
    #    ...
}
```

<a id="dummy-server"></a>

### 阻止未定义服务器名称的请求

如果不应允许没有 `Host` 头字段的请求,可以定义一个简单丢弃此类请求的服务器:

```nginx
server {

    listen 80;
    server_name "";
    return 444;
}
```

在此配置中,服务器名称设置为空字符串,它匹配没有 `Host` 头字段的请求。然后返回一个特殊的非标准代码 444,该代码会关闭连接。

<a id="combining-name-based-and-ip-based-virtual-servers"></a>

### 组合基于名称和基于 IP 的虚拟服务器

让我们来看一个更复杂的配置,其中一些虚拟服务器监听不同的地址:

```nginx
server {

    listen 192.168.1.1:80;
    server_name example.org www.example.org;
    #  ...
}

server {

    listen 192.168.1.1:80;
    server_name example.net www.example.net;
    #  ...
}

server {

    listen 192.168.1.2:80;
    server_name example.com www.example.com;
    #  ...
}
```

在此配置中,Angie 首先根据 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 块的 [listen](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#listen) 指令测试请求的 IP 地址和端口。然后,它根据匹配 IP 地址和端口的 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 块的 [server_name](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server-name) 条目测试请求的 `Host` 头字段。如果未找到服务器名称,该请求将由默认服务器处理。例如,在端口 192.168.1.1:80 上接收到的对 `www.example.com` 的请求将由该端口的默认服务器处理——即第一个服务器——因为 `www.example.com` 未为此端口定义。

如前所述,默认服务器是监听端口的属性,可以为不同的端口定义不同的默认服务器:

```nginx
server {

    listen 192.168.1.1:80;
    server_name example.org www.example.org;
    #  ...
}

server {

    listen 192.168.1.1:80 default_server;
    server_name example.net www.example.net;
    #  ...
}

server {

    listen 192.168.1.2:80 default_server;
    server_name example.com www.example.com;
    #  ...
}
```

<a id="pick-location"></a>

### 选择位置

考虑一个简单的PHP网站配置：

```nginx
server {

    listen 80;
    server_name example.org www.example.org;
    root /data/www;

    location / {

        index index.html index.php;
    }

    location ~* \.(gif|jpg|png)$ {

        expires 30d;
    }

    location ~ \.php$ {

        fastcgi_pass localhost:9000;
        fastcgi_param SCRIPT_FILENAME
        $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}
```

Angie 首先搜索由字面字符串给出的最具体的前缀 `location`，而不考虑它们的列出顺序。在上面的配置中，唯一的前缀 location 是 `location /`，它匹配任何请求，并将作为最后的选择。然后 Angie 按照配置文件中出现的顺序检查由正则表达式定义的 location。第一个匹配的表达式会停止搜索，Angie 将使用该 `location`。如果没有正则表达式匹配请求，Angie 将使用之前找到的最具体的前缀 `location`。

#### NOTE
所有类型的 location 仅测试请求行的 URI 部分，不包括参数。这是因为查询字符串中的参数可以以各种方式指定，例如：

- `/index.php?user=john&page=1`
- `/index.php?page=1&user=john`

此外，查询字符串可能包含任意数量的参数：

- `/index.php?page=1&something+else&user=john`

现在让我们看看在上述配置中如何处理请求：

- 请求 `/logo.gif` 首先由前缀 `location /` 匹配，然后由正则表达式 `.(gif|jpg|png)$` 匹配。因此，它由后者 location 处理。使用指令 `root /data/www`，请求被映射到文件 `/data/www/logo.gif`，并将文件发送给客户端。
- 请求 `/index.php` 也首先由前缀 `location /` 匹配，然后由正则表达式 `.(php)$` 匹配。因此，它由后者 location 处理，请求被传递到监听 `localhost:9000` 的 FastCGI 服务器。[fastcgi_param](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-param) 指令将 FastCGI 参数 `SCRIPT_FILENAME` 设置为 `/data/www/index.php`，FastCGI 服务器执行该文件。变量 [$document_root](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-document-root) 设置为 `root` 指令的值，变量 [$fastcgi_script_name](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#v-fastcgi-script-name) 设置为请求 URI，即 `/index.php`。
- 请求 `/about.html` 仅由前缀 `location /` 匹配，因此在此 location 中处理。使用指令 `root /data/www`，请求被映射到文件 `/data/www/about.html`，并将文件发送给客户端。

处理请求 `/` 更为复杂。它仅由前缀 `location /` 匹配，因此由此 location 处理。然后 [index](https://cn.angie.software//angie/docs/configuration/modules/http/http_index.md#id3) 指令根据其参数和 `root /data/www` 指令测试索引文件是否存在。如果文件 `/data/www/index.html` 不存在但文件 `/data/www/index.php` 存在，该指令执行到 `/index.php` 的内部重定向，Angie 再次搜索 location，就像请求是由客户端发送的一样。如前所述，重定向的请求最终将由 FastCGI 服务器处理。

<a id="proxying"></a>

## 代理和负载均衡

Angie 的一个常见用途是将其设置为代理服务器。在此角色中，Angie 接收请求，将它们转发到被代理的服务器，从这些服务器检索响应，并将响应发送回客户端。

一个简单的代理服务器：

```nginx
server {

    location / {

        proxy_pass http://backend:8080;
    }
```

[proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass) 指令指示 Angie 将客户端请求传递给后端 `backend:8080` （被代理的服务器）。还有许多其他 [指令](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy) 可用于进一步配置代理连接。

<a id="fastcgi-proxying"></a>

### FastCGI 代理

Angie 可用于将请求路由到运行使用各种框架和编程语言（如 PHP）构建的应用程序的 FastCGI 服务器。

与 FastCGI 服务器配合使用的最基本的 Angie 配置涉及使用 [fastcgi_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-pass) 指令代替 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-pass) 指令，以及使用 [fastcgi_param](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-param) 指令设置传递给 FastCGI 服务器的参数。假设 FastCGI 服务器可在 `localhost:9000` 访问。在 PHP 中，`SCRIPT_FILENAME` 参数用于确定脚本名称，`QUERY_STRING` 参数用于传递请求参数。生成的配置如下：

```nginx
server {

    location / {

        fastcgi_pass localhost:9000;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param QUERY_STRING $query_string;
    }

    location ~ \.(gif|jpg|png)$ {

        root /data/images;
    }
}
```

此配置设置了一个服务器，该服务器将所有请求（静态图像请求除外）通过 FastCGI 协议路由到在 `localhost:9000` 上运行的被代理服务器。

<a id="websocket-proxy"></a>

### WebSocket 代理

要将连接从 HTTP/1.1 升级到 WebSocket，需要使用 HTTP/1.1 中提供的\`协议切换
<[https://datatracker.ietf.org/doc/html/rfc2616#section-14.42](https://datatracker.ietf.org/doc/html/rfc2616#section-14.42)>\`_机制。

然而，这里有一个微妙之处：由于 `Upgrade` 头是一个\`逐跳头
<[https://datatracker.ietf.org/doc/html/rfc2616#section-13.5.1](https://datatracker.ietf.org/doc/html/rfc2616#section-13.5.1)>\`_，它不会从客户端传递到被代理的服务器。在正向代理中，客户端可以使用 CONNECT 方法来规避这个问题。但这种方法不适用于反向代理，因为客户端不知道任何代理服务器的存在，需要在代理服务器上进行特殊处理。

Angie 实现了一种特殊的操作模式，如果被代理的服务器返回代码为 101（切换协议）的响应，并且客户端通过请求中的 `Upgrade` 头请求协议切换，则允许在客户端和被代理服务器之间建立隧道。

如前所述，逐跳头（包括 `Upgrade` 和 `Connection`）不会从客户端传递到被代理的服务器。因此，为了让被代理的服务器知道客户端切换到 WebSocket 协议的意图，必须显式传递这些头：

```nginx
location /chat/ {

    proxy_pass http://backend;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
}
```

一个更复杂的示例演示了如何根据客户端请求头中是否存在 `Upgrade` 字段，来决定发送到被代理服务器的请求中 `Connection` 头字段的值：

```nginx
http {

    map $http_upgrade $connection_upgrade {

        default upgrade;
        '' close;
    }

    server {

        ...

        location /chat/ {

            proxy_pass http://backend;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection $connection_upgrade;
        }
    }
}
```

默认情况下，如果被代理的服务器在 60 秒内没有传输任何数据，连接将被关闭。可以使用 [proxy_read_timeout](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-read-timeout) 指令增加此超时时间。或者，可以将被代理的服务器配置为定期发送 WebSocket ping 帧以重置超时并检查连接是否仍然活动。

<a id="load-balancing"></a>

### 负载均衡

在多个应用程序实例之间进行负载均衡是一种广泛使用的技术，用于优化资源利用率、最大化吞吐量、减少延迟并确保容错配置。

Angie 可以用作高效的 HTTP 负载均衡器，将流量分配到多个应用程序服务器，从而提高 Web 应用程序的性能、可扩展性和可靠性。

使用 Angie 进行负载均衡的最简单配置可能如下所示：

```nginx
http {

    upstream myapp1 {

        server srv1.example.com;
        server srv2.example.com;
        server srv3.example.com;
    }

    server {

        listen 80;

        location / {

            proxy_pass http://myapp1;
        }
    }
}
```

在上面的示例中，同一应用程序的三个实例分别运行在 `srv1` 到 `srv3` 上。当没有显式配置负载均衡方法时，默认使用轮询。其他支持的负载均衡机制包括：[weight](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server)、[least_conn](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-least-conn) 和 [ip_hash](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-ip-hash)。Angie 中的反向代理实现还支持带内（或被动）服务器健康探测。这些探测使用 [upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-upstream) 上下文中 [server](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-server) 块内的 [max_fails](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#max-fails) 和 [fail_timeout](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#fail-timeout) 指令进行配置。

<a id="logging"></a>

## 日志记录

#### NOTE
除了此处列出的选项外，
您还可以启用 [调试日志](https://cn.angie.software//angie/docs/troubleshooting.md#debug-logging)。

<a id="syslog-logging"></a>

### Syslog

[error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 和 [access_log](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#access-log) 指令支持记录到 `syslog`。以下参数用于配置到 `syslog` 的日志记录：

| `server=`address   | 指定 `syslog` 服务器的地址。地址可以是域名或 IP 地址（带可选端口），或在 `"unix:"` 前缀后指定的 UNIX 域套接字路径。如果未指定端口，则使用 UDP 端口 514。如果域名解析为多个 IP 地址，则使用第一个解析的地址。                                                                                                                                                                                                                                                                                                                                |
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `facility=`string  | 设置 `syslog` 消息的设施，如 [RFC 3164](https://datatracker.ietf.org/doc/html/rfc3164.html) 中定义。可能的设施包括：`"kern"`、`"user"`、`"mail"`、<br/>`"daemon"`、`"auth"`、`"intern"`、`"lpr"`、<br/>`"news"`、`"uucp"`、`"clock"`、`"authpriv"`、<br/>`"ftp"`、`"ntp"`、`"audit"`、`"alert"`、<br/>`"cron"`、`"local0".."local7"`。默认值为<br/>`"local7"`。                                                                                                                                        |
| `severity=`string  | 定义 [access_log](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#access-log) 的 `syslog` 消息的严重性级别，如 [RFC 3164](https://datatracker.ietf.org/doc/html/rfc3164.html) 中指定。可能的值与 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 指令的第二个参数（级别）相同。默认值为 `"info"`。错误消息的严重性由 Angie 确定，因此在 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 指令中忽略此参数。 |
| `tag=`string       | 设置 `syslog` 消息的标签。默认标签为<br/>`"angie"`。                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `nohostname`       | 禁止在 `syslog` 消息头中添加 `hostname` 字段。                                                                                                                                                                                                                                                                                                                                                                                                                          |

syslog 配置示例：

```nginx
error_log syslog:server=192.168.1.1 debug;

access_log syslog:server=unix:/var/log/angie.sock,nohostname;
access_log syslog:server=[2001:db8::1]:12345,facility=local7,tag=angie,severity=info combined;
```


# https://cn.angie.software/products.md

# 产品

我们提供帮助您有效管理负载均衡系统的解决方案。

我们的产品提供：

- 安全的内容交付；
- 在私有、公共和混合云及企业基础设施中的网络流量管理；
- 在企业网络和分布式数据中心中的负载分配；
- 在应用程序网络交互层面的安全性；
- SSL 加密；
- 在异构环境中处理网络流量和流量平衡。

Angie 是一个高性能的现代可扩展的 Web 服务器，基于 nginx 的一个分支的开源代码。它由一组之前属于 nginx 团队的俄罗斯开发者创建并维护。

Angie PRO 是一个商业产品，代表了 Angie 的扩展版本。Angie PRO 的功能满足企业对高负载解决方案的要求。该产品已被纳入软件注册，并与各种俄罗斯 IT 解决方案集成。

Angie Ingress Controller (ANIC) 是一个用于管理 Kubernetes 中容器化应用程序流量的解决方案。ANIC 允许您管理 Ingress 功能并配置流量处理规则。它基于 Angie PRO 的功能。

## 兼容性证书

我们的产品已通过俄罗斯操作系统要求的合规性测试，相关兼容性证书予以确认：

![](../../_images/corp_part/certs/cert_redsoft.jpg)![](../../_images/corp_part/certs/cert_astra.jpg)![](../../_images/corp_part/certs/cert_basealt.jpg)

## 集成

我们与领先的软件制造商合作，并提供与其产品的集成：

![](../../_images/corp_part/integrations/integration1.webp)![](../../_images/corp_part/integrations/integration2.webp)![](../../_images/corp_part/integrations/integration3.webp)


# https://cn.angie.software/professional-service.md

# 专业服务

由Web Server有限责任公司的工程师提供的Angie PRO和客户操作系统调优服务，以确保Angie PRO的有效运行。

该服务通过为客户提供SSH和/或RDP远程访问客户服务器的方式进行。也可以采用咨询形式，由我们的工程师通过视频会议回答客户的问题。

所有与服务相关的互动都在工程师根据预付费小时数评估任务后的单独合同框架内进行。

如果您想购买我们的服务，请通过info@wbsrv.ru与我们联系。

## 服务如何提供？

1. 客户联系Web Server有限责任公司。
2. 对客户任务进行初步评估。
3. 客户支付解决任务所需的时间费用。
4. Web Server有限责任公司的工程师在约定的预付费时间内，在客户服务器上手动（独立）执行任务，或以专家观察模式监督客户工程师的工作。

该服务包括以下客户与我们工程师之间的互动可能性：

- 分析客户的基础设施并提供优化系统与Angie PRO交互的建议。
- 分析资源/网络映射。
- 分析客户现有Web服务和系统的交互。
- 提供调优现有Angie PRO配置的建议，以提高Angie PRO与服务之间集成的性能和容错性。

## 客户请求和解决方案示例

### 示例1

**请求**：客户的工程师在服务器日志中周期性地遇到502错误，请求协助了解发生原因。

**解决方案**：分析现有Angie PRO配置文件并调优Angie配置的"精细"方面，包括但不限于：内存消耗/缓冲、最佳实践应用和基本安全性。

### 示例2

**请求**：客户通过limit_req设置了请求数量限制，但该限制并不总是生效。客户的工程师遇到困难，客户请求帮助理解问题并协助工程师配置Angie。

**解决方案**：根据客户的具体任务从头编写Angie PRO配置文件，并就所创建配置的运行提供咨询。

### 示例3

**请求**：客户有一个由多个子服务组成的Web服务，需要配置蓝绿部署以提高容错性。

**解决方案**：根据客户要求，配置或排查与Angie PRO相关/配合工作的软件（如PHP-FPM、Apache、uWSGI、Envoy、自定义后端）的问题（如果可行）。

### 示例4

**请求**：客户的工程师发现Angie PRO代理的服务后端周期性地断开连接，无法找出原因。

**解决方案**：配置客户的操作系统设置以提高Angie PRO的性能。


# https://cn.angie.software/angie/docs/configuration/quickaccess.md

<!-- review: finished -->

<a id="quickaccess"></a>

# 快速访问 Angie 指令和变量

您可以通过我们的短链接服务 [https://angie.ws/en/](https://angie.ws/en/) 快速访问所有 Angie 指令和变量的文档，而无需在网站上搜索。
它提供了对常用指令、变量和主题的快捷方式。

<a id="http-and-core-directives"></a>

## HTTP 和核心指令

在 [核心设置](https://cn.angie.software//angie/docs/configuration/modules/core.md#core) 和 [HTTP 模块](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-http) 下的指令使用 `/h/` 前缀（即 `http` 的缩写）。

示例：

- [listen](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#listen): [https://angie.ws/en/h/listen](https://angie.ws/en/h/listen)
- [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server): [https://angie.ws/en/h/server](https://angie.ws/en/h/server)
- [worker_connections](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-connections): [https://angie.ws/en/h/worker_connections](https://angie.ws/en/h/worker_connections)

等等。

#### NOTE
[Upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块中的 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 指令位于 [https://angie.ws/en/hu/server](https://angie.ws/en/hu/server)。

<a id="upstream-directives-1"></a>

### 上游指令

[Upstream](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#http-upstream) 模块中的指令使用 `/hu/` 前缀（即 `http upstream` 的缩写）。示例：

- [keepalive_requests](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-keepalive-requests): [https://angie.ws/en/hu/keepalive_requests](https://angie.ws/en/hu/keepalive_requests)
- [keepalive_time](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-keepalive-time): [https://angie.ws/en/hu/keepalive_time](https://angie.ws/en/hu/keepalive_time)
- [keepalive_timeout](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-keepalive-timeout): [https://angie.ws/en/hu/keepalive_timeout](https://angie.ws/en/hu/keepalive_timeout)

等等。

<a id="stream-module-directives"></a>

## 流模块指令

[流模块](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 中的指令使用 `/s/` 前缀（即 `stream` 的缩写）：

- [listen](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-listen): [https://angie.ws/en/s/listen](https://angie.ws/en/s/listen)
- [map](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_map.md#s-map): [https://angie.ws/en/s/map](https://angie.ws/en/s/map)
- [server](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-server): [https://angie.ws/en/s/server](https://angie.ws/en/s/server)

等等。

#### NOTE
[Upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 模块中的 [server](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-server) 指令位于 [https://angie.ws/en/su/server](https://angie.ws/en/su/server)。

<a id="upstream-directives"></a>

### 上游指令

[Upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 模块中的指令使用 `/su/` 前缀（即 `stream upstream` 的缩写）：

- [upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-upstream): [https://angie.ws/en/su/upstream](https://angie.ws/en/su/upstream)
- [server](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-server): [https://angie.ws/en/su/server](https://angie.ws/en/su/server)
- [state (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-state): [https://angie.ws/en/su/state](https://angie.ws/en/su/state)

等等。

<a id="variables-1"></a>

## 变量

变量遵循相同的前缀方案。

HTTP 变量（`/h/` 前缀）：

- [$angie_version](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-angie-version): [https://angie.ws/en/h/$angie_version](https://angie.ws/en/h/$angie_version)
- [$upstream_status](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-status): [https://angie.ws/en/h/$upstream_status](https://angie.ws/en/h/$upstream_status)

流变量（`/s/` 前缀）：

- [$angie_version](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-angie-version): [https://angie.ws/en/s/$angie_version](https://angie.ws/en/s/$angie_version)
- [$upstream_session_time](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#v-s-upstream-session-time): [https://angie.ws/en/s/$upstream_session_time](https://angie.ws/en/s/$upstream_session_time)

对于占位符变量，如 `$http_<HEADER>` 或 `$cookie_<NAME>`，
请使用下划线之前的前缀：[https://angie.ws/en/h/$http](https://angie.ws/en/h/$http)。

<a id="additional-topics"></a>

## 其他主题

短链接也可用于其他主题：

- [证书链](https://angie.ws/en/certificate_chaining)
- [组合位置](https://angie.ws/en/combined_locations)
- [紧凑服务器](https://angie.ws/en/compact_server)
- [配置](https://angie.ws/en/configure)
- [配置文件重新加载](https://angie.ws/en/configfile_reloading)
- [配置哈希](https://angie.ws/en/configure_hashes)
- [控制配置更改](https://angie.ws/en/control_config_change)
- [控制信号](https://angie.ws/en/control_signals)
- [循环内存缓冲区](https://angie.ws/en/cyclic_memory_buffer)
- [调试日志](https://angie.ws/en/debug_logging)
- [虚拟服务器](https://angie.ws/en/dummy_server)
- [HTTPS 配置](https://angie.ws/en/https_configuration)
- [HTTPS 优化](https://angie.ws/en/https_optimization)
- [使用单独 IP 的 HTTPS](https://angie.ws/en/https_separate_ips)
- [HTTP 会话](https://angie.ws/en/http_sessions)
- [继承](https://angie.ws/en/inheritance)
- [负载均衡](https://angie.ws/en/load_balancing)
- [位置重定向](https://angie.ws/en/location_redirect)
- [日志轮换](https://angie.ws/en/log_rotation)
- [方法使用](https://angie.ws/en/methods_use)
- [命名位置](https://angie.ws/en/named_location)
- [路径](https://angie.ws/en/paths)
- [选择位置](https://angie.ws/en/pick_location)
- [代理传递 URI](https://angie.ws/en/proxy_pass_uri)
- [代理](https://angie.ws/en/proxying)
- [请求处理](https://angie.ws/en/request_processing)
- [运行时 CLI 选项](https://angie.ws/en/runtime_cli_options)
- [服务升级](https://angie.ws/en/service_upgrade)
- [SNI（服务器名称指示）](https://angie.ws/en/sni)
- [源构建特性](https://angie.ws/en/sourcebuild_features)
- [SSL 错误代码](https://angie.ws/en/ssl_error_codes)
- [流会话](https://angie.ws/en/stream_sessions)
- [语法](https://angie.ws/en/syntax)
- [Syslog 日志](https://angie.ws/en/syslog_logging)
- [虚拟服务器选择](https://angie.ws/en/virtual_server_selection)
- [WebSocket 代理](https://angie.ws/en/websocket_proxy)


# https://cn.angie.software/angie/docs/installation/external-modules/redis2.md

<!-- review: finished -->

<a id="external-redis2"></a>

# Redis2

`redis2` 模块提供与 Redis 2.x 服务器交互的能力。它实现了完整的统一 Redis 2.0 协议,包括对 Redis 管道的支持。

<a id="installation-23"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-redis2`
- Angie PRO:`angie-pro-module-redis2`

<a id="loading-the-module-23"></a>

## 加载模块

要使用该模块,必须在 `main{}` 上下文中加载它。
下面的示例还使用了 [set-misc](https://cn.angie.software//angie/docs/installation/external-modules/set-misc.md#external-set-misc) 模块的指令:

```nginx
load_module modules/ndk_http_module.so;
load_module modules/ngx_http_set_misc_module.so;
load_module modules/ngx_http_redis2_module.so;
```

<a id="configuration-example-97"></a>

## 配置示例

```nginx
upstream redis_upstream {
    server 127.0.0.1:6379;
}

server {
    listen       80;
    server_name  localhost;

    # 设置键值
    location /foo {
        set $value 'first';
        redis2_query set one $value;
        redis2_pass redis_upstream;
    }

    # 通过键获取值
    location /bar {
        redis2_query get one;
        redis2_pass redis_upstream;
    }

    # 从查询参数设置键值
    location /set {
        set_unescape_uri $key $arg_key;
        set_unescape_uri $val $arg_val;
        redis2_query set $key $val;
        redis2_pass 127.0.0.1:6379;
    }

    # 从查询参数通过键获取值
    location /get {
        set_unescape_uri $key $arg_key;
        redis2_query get $key;
        redis2_pass 127.0.0.1:6379;
    }

    # 执行多个管道命令
    location /pipeline {
        set $value 'first';
        redis2_query set one $value;
        redis2_query get one;
        redis2_query set one 'first first';
        redis2_query get one;
        redis2_pass 127.0.0.1:6379;
    }

    # 执行在查询参数中传递的任意命令
    location /cmd {
        set_unescape_uri $cmd $arg_command;
        redis2_raw_query "$cmd\r\n";
        redis2_pass 127.0.0.1:6379;
    }
}
```

#### WARNING
重要!与 Angie 中的 `proxy_pass` 指令不同,不允许在 `redis2_pass` 指令的参数中使用变量。

<a id="request-execution-demonstration"></a>

## 请求执行演示

模块使用示例。

```console
$ curl localhost/foo
+OK

$ curl localhost/bar
$5
first
```

这里 `$5` 是值的长度(5 字节),:samp:first 是值本身。

```console
$ curl 'localhost/set/?key=two&val=second%20value'
+OK

$ curl 'localhost/get/?key=two'
$12
second value

$ curl 'localhost/get/?key=three'
$-1
```

值 `$-1` 表示键 `three` 不存在。

```console
$ curl localhost/pipeline
+OK
$5
first
+OK
$11
first first
```

执行任意 Redis 命令:

```console
$ curl 'localhost/cmd/?command=set%20three%20"third%20value"'
+OK

$ curl 'localhost/cmd/?command=get%20three'
$11
third value
```

<a id="additional-information-24"></a>

## 其他信息

详细文档和源代码可在以下位置获取:
[https://github.com/openresty/redis2-nginx-module](https://github.com/openresty/redis2-nginx-module)。


# https://cn.angie.software/news/releases.md

# 版本发布

## [Angie 和 Angie PRO 更新至 1.11.6 版本](https://cn.angie.software//news/releases/angie-1-11-6.md)

*25.05.2026*

Angie 和 Angie PRO 1.11.6 修复版本已发布，移植了前一日在 nginx 中发现的
[rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#id5) 指令漏洞 CVE-2026-9256 的修复。

## [Angie 和 Angie PRO 更新至 1.11.5 版本](https://cn.angie.software//news/releases/angie-1-11-5.md)

*15.05.2026*

Angie 和 Angie PRO 1.11.5 修复版本已发布，移植了 nginx 中发现的五个漏洞的
修复。这些漏洞涉及 `rewrite`、`ssl_ocsp`、`scgi_pass`、
`uwsgi_pass` 和 `charset_map` 指令的工作，以及 `HTTP/3`
协议请求的处理。

## [Angie 和 Angie PRO 更新至 1.11.0 版本](https://cn.angie.software//news/releases/angie-1-11-0.md)

*24.12.2025*

Angie 和 Angie PRO 1.11.0 已发布 — 这是该项目历史上规模最大的更新。
此版本引入了 Metrics 模块，修复了 `HTTP/3` 可靠性问题，扩展了
ACME 和图像过滤器功能；Angie PRO 改进了具有外部存储的粘性会话，并在
API 中添加了许可证详情。

## [Angie 和 Angie PRO 更新至 1.10.3 版本](https://cn.angie.software//news/releases/angie-1-10-3.md)

*13.11.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 发布了修复版本 1.10.3。
从 nginx 1.29 移植了邮件 SMTP 模块的一个潜在漏洞修复。修复了 ACME 配置
错误，并解决了在 client 块中使用变量访问传入连接时的潜在崩溃问题。
PRO 版本还修复了 UDP 健康检查和 Docker 模块服务器的相关问题。

## [Angie 和 Angie PRO 更新至 1.10.2 版本](https://cn.angie.software//news/releases/angie-1-10-2.md)

*22.08.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 发布了修复版本 1.10.2。
这些版本修复了在 1.10 版本中引入 client 块实现时出现的问题，该问题
可能会干扰 stream 模块中 ACME、Docker 和 sticky remote 模块的功能。
同时修复了通过 Docker API 更新代理服务器组的问题，并添加了两个新的
第三方模块。

## [Angie 和 Angie PRO 更新至 1.10.1 版本](https://cn.angie.software//news/releases/angie-1-10-1.md)

*17.07.2025*

发布了 Angie 和 Angie PRO 的 1.10.1 修复版本。此次更新修复了
reuseport 和 HTTP/3 的相关问题，改进了 client 配置块的逻辑，
增加了对新版本 GCC 的兼容性，并解决了 Angie PRO 中使用特殊变量时的崩溃问题。

## [Angie 和 Angie PRO 更新至 1.10.0 版本](https://cn.angie.software//news/releases/angie-1-10-0.md)

*04.07.2025*

开源 Web 服务器 Angie 及其商业版 Angie PRO 已发布 1.10.0 版本。
主要更新包括自动代理 Docker 容器、改进流模块中的 ACME 支持、
支持多路径 TCP 和带 CUBIC 的 QUIC，以及集群模式下 Angie PRO 的新功能。

## [Angie 和 Angie PRO 更新至版本 1.9.1](https://cn.angie.software//news/releases/angie-1-9-1.md)

*29.05.2025*

开源 Web 服务器 Angie 及其商业版 Angie PRO 发布了 1.9.1 版本。
本次更新重点提升了对 HTTP/3 的支持，并改进了对非标准 ACME 配置的处理，
同时修复了流模块中的一些问题。

## [Angie 和 Angie PRO 更新至 1.9.0 版本](https://cn.angie.software//news/releases/angie-1-9-0.md)

*11.04.2025*

开源网页服务器 Angie 及其商业版本 Angie PRO 已发布 1.9.0 版本。
主要更新包括将缓存索引保存到磁盘以加快重启速度、
在流模块中支持 TLS 1.3 Early Data，以及 Angie PRO 中 HTTP 负载均衡器的新功能。

## [Angie 和 Angie PRO 发布了 1.8.3 版本；Console Light 更新至 1.7.0 版本](https://cn.angie.software//news/releases/angie-1-8-3.md)

*02.04.2025*

开源版 Angie 网络服务器及其商业版 Angie PRO 发布了 1.8.3 版本，修复了统计功能；
Console Light 更新至 1.7.0 版本。

## [Angie 和 Angie PRO 发布 1.8.2 更新](https://cn.angie.software//news/releases/angie-1-8-2.md)

*13.02.2025*

开源 Web 服务器 Angie 及其商业版本 Angie PRO 的 1.8.2 版本包含重要的安全修复，以及其他多项改进。

## [Angie 和 Angie PRO 升级至 1.8.1 版本](https://cn.angie.software//news/releases/angie-1-8-1.md)

*28.12.2024*

开源网络服务器 Angie 和其商业版本 Angie PRO 发布了 1.8.1 版本。
此更新修复了服务器统计区域的问题，改进了 ACME 模块对通配符证书的支持，并包含 HTTP/3 的重要修复。

## [Angie 和 Angie PRO 更新至版本 1.8.0](https://cn.angie.software//news/releases/angie-1-8-0.md)

*19.12.2024*

Angie 网络服务器及其商业版本 Angie PRO 的 1.8.0 版本已发布。此更新包括 ACME 模块的新功能、对 WebAssembly 的支持，以及 API 和功能的改进。

## [Angie 和 Angie PRO 收到更新 1.7.0](https://cn.angie.software//news/releases/angie-i-angie-pro-poluchili-obnovlenie-1-7-0.md)

*20.09.2024*

新版本的开源网页服务器 Angie 1.7.0 和商业版 Angie PRO 1.7.0 现已推出，提供显著的改进和新功能。

## [Angie 和 Angie PRO 发布 1.6.1 更新](https://cn.angie.software//news/releases/angie-i-angie-pro-poluchili-obnovlenie-1.6.1.md)

*08.08.2024*

Web Server公司发布了开源网络服务器 Angie 1.6.1 和其商业版本 Angie PRO 1.6.1。

## [Angie和Angie PRO Web服务器发布更新](https://cn.angie.software//news/releases/vishli-obnovlenia-web-servera-angie-i-angie-pro.md)

*28.06.2024*

新版本显著扩展了负载均衡功能，并继续开发ACME模块。

## [Web服务器Angie新增ACME支持](https://cn.angie.software//news/releases/veb-server-angie-poluchil-podderzhku-acme.md)

*27.03.2024*

新增了http_acme模块，实现了对ACME(自动化证书管理环境)协议的支持，简化了网站数字证书的工作流程，
无需使用像EFF Certbot这样的第三方解决方案。

## [国产云环境Kubernetes解决方案Angie Ingress Controller (ANIC)发布更新](https://cn.angie.software//news/releases/vishli-obnovleniya-otechestvennogo-reshenia-ANIC.md)

*02.03.2024*

Web Server公司发布了用于Kubernetes容器化应用流量管理的俄罗斯解决方案Angie Ingress Controller (ANIC) 0.3.0版本。

## [Angie Web服务器及其专有版本Angie PRO发布更新](https://cn.angie.software//news/releases/vishli-obnovleniya-veb-servera-angie-i-ego-proprietarnoi-versii-angie-pro.md)

*15.02.2024*

Web Server公司发布了俄罗斯开源Web服务器Angie 1.4.1及其商业版本Angie PRO 1.4.1。

## [俄罗斯网络服务器Angie PRO更新发布](https://cn.angie.software//news/releases/vishli-obnovleniya-rossiiskogo-veb-servera-Angie-Pro.md)

*21.12.2023*

Web Server公司宣布发布新版本的俄罗斯网络服务器Angie PRO 1.4.0。

## [俄罗斯开源Web服务器Angie发布更新](https://cn.angie.software//news/releases/vishli-obnovleniya-rossiiskogo-veb-servera-s-otkrytym-iskhodnym-kodom-Angie.md)

*12.12.2023*

"Web Server"公司发布了俄罗斯开源Web服务器Angie 1.4.0新版本。

## [Angie和Angie PRO发布1.3.2更新](https://cn.angie.software//news/releases/angie-i-angie-pro-poluchili-obnovlenie-1.3.2.md)

*24.11.2023*

Web Server公司发布了Web服务器Angie及其商业版本Angie PRO的更新。

## [Angie和Angie PRO针对DoS攻击的防护得到增强](https://cn.angie.software//news/releases/angie-i-angie-pro-obnovleni-dlya-uluchsheniya-zashchity-ot-dos-ataki.md)

*18.10.2023*

Web Server公司宣布发布Angie和Angie PRO的1.3.1版本。

## [Web服务器Angie PRO发布1.3.0更新](https://cn.angie.software//news/releases/veb-server-angie-pro-poluchil-obnovlenie-1.3.0.md)

*03.10.2023*

"Web Server"公司宣布发布俄罗斯Web服务器Angie PRO 1.3.0新版本。

## [开源代码的Web服务器Angie更新至版本1.3.0](https://cn.angie.software//news/releases/veb-server-angie-s-otkritim-ishodnim-kodom-1.3.0.md)

*19.09.2023*

公司“Web服务器”宣布发布俄罗斯开源Web服务器Angie 1.3.0的新版本。

## [Web服务器Angie PRO发布1.2.0更新](https://cn.angie.software//news/releases/veb-server-angie-pro-poluchil-obnovlenie-1.2.0.md)

*19.08.2023*

"Web Server"公司宣布发布其俄罗斯Web服务器Angie PRO 1.2.0新版本。

## [Web Server公司推出Angie入口控制器](https://cn.angie.software//news/releases/kompaniya-veb-server-predstavila-angie-ingress-controller.md)

*29.06.2023*

Web Server公司推出了新产品Angie入口控制器（ANIC），可实现Kubernetes网络中的高效流量管理。

## [公司Web Server更新开源Web服务器Angie](https://cn.angie.software//news/releases/kompaniya-veb-server-obnovila-veb-server.md)

*08.06.2023*

俄罗斯开源Web服务器Angie 1.2.0新版本发布。


# https://cn.angie.software/news/integrations/reshenie-po-zaschite-web-prilojenii-solidwall-sovmestimo-s-angie-pro.md

# SolidWall Web应用程序防护解决方案兼容Angie PRO

*15.07.2024*

与Angie PRO的集成增强了SolidWall WAF的功能，例如，实现了对HTTP/3协议的支持。

Web Server公司已确认俄罗斯解决方案SolidWall WAF与Web服务器Angie PRO的兼容性。

SolidSoft应用安全部门负责人格里戈里·瓦西里耶夫表示："在企业和组织倾向于在其基础设施中使用国产软件产品的背景下，将智能网络防火墙SolidWall与俄罗斯Web服务器Angie PRO结合使用可以满足其主要需求。这些解决方案将帮助保护Web应用免受各种威胁。此外，与Angie PRO的集成增强了SolidWall WAF的功能，例如，实现了对HTTP/3协议的支持。"

俄罗斯Web服务器开发商Angie的首席执行官扎乌尔·阿巴斯米尔佐耶夫指出，这两款产品在关键信息基础设施（CII）中得到广泛应用。该专家强调："在推进国产化替代的趋势下，Angie PRO和SolidWall之间的兼容性测试进一步证实了业务防护系统针对网络威胁的可靠性和安全性得到了显著提升。"

SolidWall WAF智能网络防火墙旨在保护Web应用程序及其用户免受网络攻击，识别针对Web应用和移动应用后端的定向攻击，并确保业务逻辑免受机器人和恶意活动的影响。该解决方案可无缝集成到安全软件开发生命周期（sSDLC）中，实现新功能保护的自动化和用户行为监控。

SolidWall WAF具有受保护应用程序运行的详细模型和基于签名的行为异常检测方法。这为防范简单类型的攻击和复杂的定向攻击提供了高水平的保护。抑制误报的工具和机器学习算法的应用有助于快速部署SolidWall WAF。

此前，俄罗斯Web服务器Angie PRO已通过与国产操作系统的兼容性认证：Red OS、Astra Linux Special Edition、ROSA Chrome 12 Server、Alt及其FSTEC版本Alt SP，并已被列入国产软件注册表（编号17604）。该Web服务器与nginx最新版本向后兼容，使用户无需承担重大成本和服务中断即可过渡到国产解决方案。该Web服务器支持ACME协议，简化了处理网站数字证书的流程，消除了对EFF Certbot等第三方解决方案的需求，使Angie在这方面可以与Caddy等解决方案竞争。

**参考信息**

SolidSoft是一家俄罗斯Web应用程序保护解决方案开发商，以SolidWall品牌发布产品。该公司成立于2014年，其前身是独立安全实验室SolidLab，专门从事信息资源安全分析、配置保护工具、组织安全应用程序开发以及事件监控和响应。


# https://cn.angie.software/news/rossiya-poluchit-nezavisimii-veb-server.md

# 俄罗斯将推出自主研发的Web服务器Angie

*27.10.2022*

俄罗斯已开发出名为Angie的Web服务器，这将使俄罗斯企业能够替代国外解决方案并确保其基础设施的安全。

俄罗斯已开发出名为Angie的Web服务器，这将使俄罗斯企业能够替代国外解决方案并确保其基础设施的安全。这款新产品将命名为Angie，并将以开放许可证的形式发布。

Angie是全球最受欢迎的Web服务器之一Nginx的一个分支。该项目由Web Server公司开发，该公司汇集了前Nginx核心工程师和支持团队。

与Nginx相比，Angie将为国际开发者社区和俄罗斯企业提供功能更为强大的Web服务器版本。得益于其动态重配置功能，Angie在处理扩展性和容错性任务方面表现更好。通过增强的指标跟踪功能，Angie显著简化了Web服务器与公司基础设施整体监控的集成。

Angie将具有用于动态配置Web服务器参数的应用程序编程接口（API），这将在使用Kubernetes等应用程序集群管理软件开发现代Web应用时带来便利。

Web Server公司CEO Zaur Abasmirzoev表示： *"项目第一阶段的投资约为100万美元。我们主要针对俄罗斯市场，但国外公司已经对我们的开发表现出兴趣。"*

Angie产品总监Ivan Poluyanov指出： *"公司还将为Angie用户和Nginx用户提供技术支持，并开发用于管理和监控关键IT基础设施的工具。"*

Angie的核心团队由顶级工程师和技术支持专家组成。Web Server的专家们在开发NGINX及其商业版本方面拥有独特经验，并为财富500强公司提供了全天候不间断的技术支持。许多团队成员都获得过国际奖项。

Angie的开发在俄罗斯进行，源代码将被放置在数字发展部的可信存储库中，以进行必要的认证。

您可以在 [这里](https://cn.angie.software) 了解更多关于Angie的信息。


# https://cn.angie.software/angie/docs/installation/external-modules/rtmp.md

<!-- review: finished -->

<a id="external-rtmp"></a>

# RTMP

RTMP 模块为希望使用基于 HTTP 协议的简化解决方案的用户提供 HLS 和 MPEG-DASH 格式的实时流媒体功能。流以 MPEG-TS 格式通过 HTTP 发布。

<a id="installation-24"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-rtmp`;
- Angie PRO:`angie-pro-module-rtmp`。

<a id="loading-the-module-24"></a>

## 加载模块

在 `main{}` 上下文中加载模块:

```nginx
load_module modules/ngx_rtmp_module.so;
```

<a id="configuration-example-98"></a>

## 配置示例

```nginx
http {
    server {
        listen 443 ssl;
        server_name example.com;

        ssl_certificate /var/ssl/example.com.pem;
        ssl_certificate_key /var/ssl/example.com.private;

        location /keys {
            root /tmp;
        }
    }

    server {
        listen 80;
        server_name example.com;

        location /hls {
            root /tmp;
        }
    }
}

rtmp {
    server {
        listen 1935;

        hls on;
        hls_path /tmp/hls;
        hls_keys on;
        hls_key_path /tmp/keys;
        hls_key_url https://example.com/keys/;
        hls_fragments_per_key 2;
    }
}
```

<a id="additional-information-25"></a>

## 附加信息

详细文档和源代码可在以下位置获取:
[https://github.com/arut/nginx-rtmp-module](https://github.com/arut/nginx-rtmp-module)


# https://cn.angie.software/angie/docs/configuration/runtime.md

<!-- review: finished -->

<a id="runtime"></a>

# 运行时控制

要启动 Angie,请使用 **systemd** 执行以下命令:

```console
$ sudo service angie start
```

建议事先检查配置语法。方法如下:

```console
$ sudo angie -t && sudo service angie start
```

重新加载配置:

```console
$ sudo angie -t && sudo service angie reload
```

停止 Angie:

```console
$ sudo service angie stop
```

安装后,运行以下命令以确保 Angie 已启动并正在运行:

```console
$ curl localhost:80
```

#### NOTE
开源版本 Angie 的运行方法可能因安装方式而异。

Angie 有一个主进程和多个工作进程。主进程负责读取和评估配置,并维护工作进程。工作进程处理实际的请求。Angie 使用基于事件的模型和依赖于操作系统的机制,在工作进程之间高效分配请求。工作进程的数量在配置文件中定义,可以针对给定配置固定,也可以根据可用 CPU 核心数自动调整(参见 [worker_processes](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-processes))。

配置后,Angie 还会在退出前将某些共享内存区域(目前是 [proxy_cache_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-path) 中的 `keys_zone`)刷新到磁盘,以便新的主进程可以恢复它们,从而提高性能。如果由于区域大小更改、二进制版本不兼容或其他原因导致恢复失败,Angie 将记录警告(`failed to restore zone at address`),并且不会使用区域恢复机制。

<a id="control-signals"></a>

## 使用信号

也可以使用信号来控制 Angie。默认情况下,主进程的进程 ID 会写入文件 `/run/angie.pid`。此文件名可以在配置时或在 `angie.conf` 中使用 [pid](https://cn.angie.software//angie/docs/configuration/modules/core.md#pid) 指令更改。主进程支持以下信号:

| `TERM`、`INT`   | 快速关闭                                                                                                     |
|----------------|----------------------------------------------------------------------------------------------------------|
| `QUIT`         | [优雅](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-shutdown-timeout) 关闭     |
| `HUP`          | 重新加载配置,更新时区(仅适用于 FreeBSD 和 Linux),使用更新后的配置启动新的工作进程,:ref:优雅 <worker_shutdown_timeout> 关闭旧的工作进程            |
| `USR1`         | 重新打开日志文件                                                                                                 |
| `USR2`         | 升级可执行文件                                                                                                  |
| `WINCH`        | [优雅](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-shutdown-timeout) 关闭工作进程 |

您可以使用 **kill** 发送信号:

```console
$ sudo kill -QUIT $(cat /run/angie.pid)
```

也可以使用信号控制单个工作进程,尽管这是可选的。支持的信号有:

| `TERM`、`INT`   | 快速关闭                                                                                                             |
|----------------|------------------------------------------------------------------------------------------------------------------|
| `QUIT`         | [优雅](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-shutdown-timeout) 关闭             |
| `USR1`         | 重新打开日志文件                                                                                                         |
| `WINCH`        | 用于调试的异常终止(需要启用 [debug_points](https://cn.angie.software//angie/docs/configuration/modules/core.md#debug-points)) |

<a id="control-config-change"></a>

## 更改配置

为了让 Angie 重新读取配置文件,应向主进程发送 `HUP` 信号。主进程首先检查语法有效性,然后尝试应用新配置,包括打开新的日志文件和监听套接字。如果应用新配置失败,主进程将回滚更改并继续使用旧配置运行。如果应用成功,主进程将启动新的工作进程,并向旧的工作进程发送消息,请求它们 [优雅](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-shutdown-timeout) 关闭。旧的工作进程关闭其监听套接字并继续为现有客户端提供服务。在所有客户端都得到服务后,旧的工作进程将关闭。

Angie 跟踪每个进程的配置更改。代数从服务器首次启动时的 1 开始。这些数字随着每次配置重新加载而递增,并在进程标题中可见:

```console
$ sudo angie
$ ps aux | grep angie

    angie: master process v|version| #1 [angie]
    angie: worker process #1
```

成功重新加载配置后(无论是否有实际更改),Angie 会为接收到新配置的进程递增代数:

```console
$ sudo kill -HUP $(cat /run/angie.pid)
$ ps aux | grep angie

    angie: master process v|version| #2 [angie]
    angie: worker process #2
```

如果前几代的任何工作进程继续运行,它们将立即可见:

```console
$ ps aux | grep angie

    angie: worker process #1
    angie: worker process #2
```

#### NOTE
不要将配置代数与"进程编号"混淆;出于实际目的,Angie 不使用连续的进程编号。

<a id="log-rotation"></a>

## 轮转日志文件

要轮转日志文件,首先重命名文件。然后,向主进程发送 `USR1` 信号。主进程将重新打开所有当前打开的日志文件,并将它们分配给运行工作进程的非特权用户。成功重新打开文件后,主进程关闭所有打开的文件并通知工作进程重新打开其日志文件。工作进程也将立即打开新文件并关闭旧文件。因此,旧文件几乎立即可用于后处理,例如压缩。

<a id="service-upgrade"></a>

## 在线升级可执行文件

要升级服务器可执行文件,首先用新文件替换旧的可执行文件。然后,向主进程发送 `USR2` 信号。主进程将把其当前带有进程 ID 的文件重命名为带有 `.oldbin` 后缀的新文件,例如 `/usr/local/angie/logs/angie.pid.oldbin`,然后启动新的可执行文件,新可执行文件又会启动新的工作进程。

请注意,旧的主进程不会关闭其监听套接字,如有必要,可以管理它以重新启动其工作进程。如果新的可执行文件未按预期执行,您可以采取以下操作之一:

* 向旧的主进程发送 `HUP` 信号。这将在不重新读取配置的情况下启动新的工作进程。然后,您可以通过向新的主进程发送 `QUIT` 信号来 [优雅](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-shutdown-timeout) 关闭所有新进程。
* 向新的主进程发送 `TERM` 信号。它将向其工作进程发送消息,请求它们立即退出。如果有任何进程未退出,请发送 `KILL` 信号强制它们退出。当新的主进程退出时,旧的主进程将自动启动新的工作进程。

如果新的主进程退出,旧的主进程将从带有进程 ID 的文件名中删除 `.oldbin` 后缀。

如果升级成功,向旧的主进程发送 `QUIT` 信号,只有新进程将保留。

配置后,Angie 还会在升级前将某些共享内存区域(目前是 [proxy_cache_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-cache-path) 中的 `keys_zone`)刷新到磁盘,以便新的主进程可以恢复它们,从而提高性能。如果由于区域大小更改、二进制版本不兼容或其他原因导致恢复失败,Angie 将记录警告(`failed to restore zone at address`),并且不会使用区域恢复机制。

<a id="runtime-cli-options"></a>

## 命令行选项

| `-?`、`-h`       | 显示命令行参数的帮助信息,然后退出。                                                                                                                                                            |
|-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `--build-env`   | 显示有关构建环境的辅助信息,然后退出。                                                                                                                                                           |
| `-c` file       | 使用 file 作为配置文件,而不是使用 [默认文件](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)。                                                                    |
| `-e` file       | 使用 file 作为错误日志文件,而不是使用 [默认文件](https://cn.angie.software//angie/docs/configuration/processing.md#logging)。特殊值 `stderr` 指定标准错误<br/>输出。                                          |
| `-g` directives | 设置 [全局配置指令](https://cn.angie.software//angie/docs/configuration/modules/core.md#core),<br/>例如:`angie -g "pid /var/run/angie.pid; worker_processes<br/>`sysctl -n hw.ncpu`;"`。 |
| `-m`、`-M`       | 显示内置模块(`-m`)或内置和已加载模块<br/>(`-M`)的列表,然后退出。                                                                                                                                     |
| `-p` prefix     | 为 `angie` 使用指定的 prefix 路径(服务器<br/>文件所在的目录;默认为 `/usr/local/angie/`)。                                                                                                           |
| `-q`            | 如果设置了 `-t` 或 `-T`,则仅显示错误消息;<br/>否则,无效果。                                                                                                                                       |
| `-s` signal     | 向主进程发送 [信号](#control-signals):<br/>`stop`、`quit`、`reopen`、`reload` 等。                                                                                                         |
| `-t`            | 测试配置文件,然后退出。Angie 检查<br/>配置语法,递归包含其中提到的文件。                                                                                                                                    |
| `-T`            | 与 `-t` 相同,但在递归包含配置中提到的所有文件后,<br/>还会将汇总配置输出到标准输出。                                                                                                                              |
| `-v`            | 显示 Angie 版本,然后退出。                                                                                                                                                             |
| `-V`            | 显示 Angie 版本、编译器版本、构建时间<br/>以及使用的 [构建参数](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure),然后退出。                                                    |


# https://cn.angie.software/vacancies/senior-go-developer.md

# 高级 Go 开发工程师（Angie ADC）

我们是 Angie Software 团队。公司的核心成员是参与了 nginx 早期开发的资深工程师，他们如今正在打造 nginx 的演进继任者——Angie。我们的产品已经在全球范围内获得越来越多的认可，我们也为自己设定了一个雄心勃勃的目标：超越 F5、Citrix、Radware 这样的行业巨头。

Angie ADC 是一款现代的企业级应用交付控制器。它负责流量路由、负载均衡、SSL 卸载和安全防护——确保应用程序在复杂网络环境中稳定运行所需的一切。我们坚信，制胜的关键不仅在于"引擎"的技术卓越，还在于对市场需求的深刻理解——正是这种理解将复杂的事物转化为真正受欢迎的产品。

我们的文化是非正式的、扁平的：大家平等交流，没有官僚作风，也没有多余的繁文缛节。决策迅速做出，论据比头衔更重要。

## 您将做什么：

- 用 Go 设计和开发 Angie ADC 的服务器端逻辑——从想法和架构到生产代码；
- 深入研究网络协议和高负载系统的内部机制，在技术栈的每一层都给出最优解；
- 参与生命周期的所有环节：规划、API 设计、编写可测试代码、代码评审、部署和维护；
- 影响技术决策，与架构师和团队紧密协作，提出多线程、异步和性能方面的最佳实践。

## 我们想招的人：

- 把 Go 视为打造可靠、高性能、复杂系统软件的工具，而不仅仅是一门语言；
- 拥有扎实的经验——5 年以上 Go 开发经历——在多任务、异步请求和性能调优等场景中游刃有余；
- 具备工程上的好奇心：深入研究网络协议的细节和高负载系统的内部机制；
- 熟悉数据库、容器化（Docker）、发布管理，理解高质量代码评审的价值；
- 善于倾听同事，能清晰阐述自己的观点，在没有层级壁垒的跨职能团队中协作自如。

## 我们提供：

- 真正影响一款世界级产品的机会，看到您的决策落地，而不必承受大公司的惯性；
- 在一支业内公认的专家团队中工作，团队重视专业能力、主动性和担当；
- 扁平结构，您的声音真正被重视，官僚作风不复存在；
- 有竞争力的薪资、补充医疗保险、报销培训和会议费用——我们支持您的职业成长；
- 已认证的 IT 企业资质和透明的工作条件。

**工作形式：** 混合办公或全坐班（可商议），萨维奥洛夫斯卡娅（Савёловская）地铁站，Factoria 商务中心。

如果您感兴趣，请将英文简历发送至 [hr@wbsrv.ru](mailto:hr@wbsrv.ru)。

#### NOTE
我们仅接受英文简历，请用英文提交您的简历。


# https://cn.angie.software/service.md

# 支持与服务

我们为产品用户提供广泛的服务：

- 对于Angie的开源版本，我们提供社区支持。
  我们积极监控各种平台，
  包括 [Telegram上的支持聊天](https://t.me/angie_support)、
  [论坛](https://forum.angie.support/)、
  [GitHub](https://github.com/webserver-llc/angie/issues)，
  以及各种技术文章的评论，并努力回答所有出现的问题。
- 我们的商业版本产品的许可证持有者可获得 [标准](https://cn.angie.software//support/index.md)
  和 [企业级](https://cn.angie.software//support/enterprise.md) 技术支持。
- 我们还提供高质量的 [专业服务](https://cn.angie.software//professional-service.md)，用于在客户基础设施中进行产品迁移、
  适配和优化。
- 我们与合作伙伴一起开发培训课程和
  产品使用认证项目。

## 我们的技术支持团队

同一个团队同时支持开源版本
和商业客户，确保为每位用户提供高水平的
服务和关注。
我们的团队成员获得过多项殊荣：2016年销售和客户服务银质Stevie奖
以及2017年销售和客户服务金质Stevie奖。
这些奖项凸显了我们同事在客户服务方面的杰出成就和专业水平。

工作日，响应时间——最长4小时。

24/7全天候，响应时间最长2小时。

由我们的工程师手动配置产品，确保在您的环境中获得最佳性能。

与合作伙伴共同开发的教育课程和认证项目。


# https://cn.angie.software/angie/docs/installation/external-modules/set-misc.md

<!-- review: finished -->

<a id="external-set-misc"></a>

# Set-Misc

`set-misc` 模块通过添加对 URI 转义和反转义、JSON 引号处理以及各种编码和解码方法（HEX、MD5、SHA1、Base32、Base64）和其他操作的支持，扩展了 Rewrite 模块的标准功能。

它可以解决以下任务：

- **URI 处理**：转义和反转义 URI。
- **编码和解码**：支持 HEX、MD5、SHA1、Base32、Base64。
- **附加功能**：处理 JSON 引号和其他实用功能。

<a id="installation-25"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-set-misc`
- Angie PRO：`angie-pro-module-set-misc`

<a id="loading-the-module-25"></a>

## 加载模块

要使用该模块，必须在 `main{}` 上下文中加载它。下面的示例还使用了来自 [echo](https://cn.angie.software//angie/docs/installation/external-modules/echo.md#external-echo) 模块的指令：

```nginx
load_module modules/ndk_http_module.so;
load_module modules/ngx_http_set_misc_module.so;
load_module modules/ngx_http_echo_module.so;
```

<a id="configuration-example-99"></a>

## 配置示例

```nginx
server {
    listen 80;
    server_name localhost;

    location /ifempty {
        set $a $arg_a;
        set_if_empty $a 56;

        echo "arg_a = '$arg_a'";
        echo "a = '$a'";
    }

    location /unescape {
        set_unescape_uri $a $arg_a;
        set_escape_uri $b $a;

        echo "arg_a = '$arg_a'";
        echo "a = '$a'";
        echo "b = '$b'";
    }

    location /base32 {
        set_encode_base32 $a $arg_a;
        set_decode_base32 $b $a;

        echo "arg_a = '$arg_a'";
        echo "a = '$a'";
        echo "b = '$b'";
    }

    location /hex {
        set_encode_hex $a $arg_a;
        set_decode_hex $b $a;

        echo "arg_a = '$arg_a'";
        echo "a = '$a'";
        echo "b = '$b'";
    }
}
```

<a id="demonstration-2"></a>

## 演示

```console
$ curl localhost/ifempty/?a=100

  arg_a = '100'
  a = '100'

$ curl localhost/ifempty

  arg_a = ''
  a = '56'

$ curl localhost/unescape/?a=Hello%20world!

  arg_a = 'Hello%20world!'
  a = 'Hello world!'
  b = 'Hello%20world!'

$ curl localhost/base32/?a=abcde

  arg_a = 'abcde'
  a = 'c5h66p35'
  b = 'abcde'

$ curl localhost/hex/?a=abcde

  arg_a = 'abcde'
  a = '6162636465'
  b = 'abcde'
```

<a id="additional-information-26"></a>

## 附加信息

指令的完整说明和源代码可在以下位置获取：
[https://github.com/openresty/set-misc-nginx-module](https://github.com/openresty/set-misc-nginx-module).


# https://cn.angie.software/news/articles/shodstva-i-razlichiya-angie-i-nginx.md

# Angie 与 nginx 的异同点

*25.08.2023*

Angie 项目和 Angie PRO 产品与其前身 nginx 及其商业版本 NGINX Plus 的关系。

![Angie vs. nginx](../../_images/news/shodstva-i-razlichiya-angie-i-nginx.webp)![Angie vs. nginx](../../_images/news/shodstva-i-razlichiya-angie-i-nginx.webp)

## **引言**

今天我们将讨论一个让所有了解我们项目的人都感兴趣的话题——Angie 项目和 Angie PRO 产品与其前身 nginx 及其商业版本 NGINX Plus 的关系。通过阅读俄语互联网上的相关讨论，我们发现这些问题仍在被积极讨论；我们将试图阐明所有引起特别关注的问题。

简而言之：不，我们不只是换了个标签。

## Angie 与 nginx 的关系

从一开始，Angie 就被定位为 nginx 的一个分支。这个概念（不要与"branch"——代码分支混淆）可能是开源软件的基石之一。另一方面，它经常伴随着误解和错误解释。

当一个新项目基于开源项目开始，完全或部分借用其前身的代码时，就会产生分支。借用本身不应引起质疑：这正是创作者最初开放代码的原因。正如经典所说："百花齐放，百家争鸣。"

新项目通常与其前身没有直接关系：它由不同的人开发，他们对未来有自己的愿景。自然地，分支经常由离开团队的项目前参与者创建。另一种典型情况是商业公司参与开源项目的开发：比如 MariaDB。

同时，分支并非静态副本——如果前身的代码在不断发展，改进和补充会定期整合到新项目中。这正是 Angie 的情况：每次新版本发布时，我们都会"引入"开源版本 nginx 中发生的变化（通常是重大变化）。

最后，我们要指出，Angie 不包含任何来自 NGINX Plus（nginx 的闭源商业版本）的代码；此外，我们的付费 Web 服务器 [Angie PRO](https://cn.angie.software/angie/docs/) 也不打算成为 NGINX Plus 的百分百功能复制品。如另一位经典所说："我们将走一条不同的道路。"

## Angie 如何替代 nginx

Angie 可以完全替代开源版本的 nginx，提供与其前身相应版本相同的功能（关于我们自己的功能将在下文详述）。

同时，除了熟悉的操作系统和计算架构外，Angie 还有意识地针对一些"官方" nginx 短期内不会支持的平台：包括俄罗斯认证的操作系统，如 ALT Linux、Astra Linux SE 和 RED OS，以及"Baikal"和"Elbrus"处理器。

另一个区别在于我们对第三方模块的处理方式。nginx 受欢迎的原因之一是其可扩展的架构——任何人都可以编写实现新功能的模块并自由公开发布。

随着时间推移，互联网上形成了一个完整的第三方模块生态系统；但是，用户必须自己组装这些模块。我们决定简化他们的工作，在我们的仓库中维护一个统一的 [现成软件包集合](https://cn.angie.software/angie/docs/installation/oss_packages/#install-dynamicmodules-oss/)，利用我们的经验和知识。

## Angie 如何改进 nginx

按照软件行业的标准，nginx 项目创建已有相当长的时间。在此期间，用户积累了许多需求，我们努力在开发 Angie 时考虑这些需求，以适应现代动态 IT 基础设施的需要；简单来说，我们重视速度、配置便利性和监控便利性。此外，我们致力于支持当前和与我们相关的标准。

## 标准和认证

我们适应我们运营的环境。在项目存在期间，我们已经：

- 将开发本地化到俄罗斯，并进入了俄罗斯电子计算机和数据库软件统一注册表；
- 启动了支持符合 GOST 标准加密的积极工作；
- 实现了对中国使用的多个加密标准的支持（[Tongsuo](https://github.com/Tongsuo-Project/Tongsuo/) 库的作者甚至 [推荐使用我们的产品](https://github.com/Tongsuo-Project/Tongsuo#典型应用/)）。

## 速度

我们工作中关注的另一个因素是通过消除不必要的延迟来加速 Web 服务器本身，以及快速适应不断变化的工作条件。我们：

- 添加了动态配置 API 和自适应 DNS 寻址工具，这有助于绕过前身的结构限制，并在不过度使用资源的情况下更快地更改设置；
- 实现了用户会话与代理服务器绑定的机制，扩展了 Angie 在不同使用场景下的适用性并节省资源；
- 引入了代理服务器的主动健康检查，降低了向不工作的服务器发送实际请求的可能性；这减少了请求处理的延迟，提高了最终用户的服务质量；
- 创建了代理缓存分段的功能，从而更有效地利用所有服务器资源。

## 可配置性

我们致力于改进的另一个领域是 Web 服务器配置的灵活性和便利性。我们已经：

- 添加了上述用于代理服务器组的动态配置 API，简化了 Angie 与现代 IT 基础设施的集成，以及允许动态适应 DNS 寻址变化的设置；
- 提供了一些其他小但有用的配置选项。

## 可观察性

最后，对我们来说，Angie 开发的一个重要方面是监控 Web 服务器本身和代理服务器的状态。我们已经：

- 在 API 中实现了检索 Web 服务器基本信息的功能，以及以流行的现代格式提供其运行的所有关键方面的统计数据；
- 引入了上述代理服务器的主动健康检查，可自主监控其运行状态；
- 添加了一系列设置，用于收集数据传输会话和地址解析请求的统计信息。

## 结论

我们简要概述了 Angie 的特性，并列出了进一步项目开发的主要优先事项；我们将在另外的文章中详细介绍我们的未来计划以及我们的 Ingress Controller 版本。我们希望现在 Angie 和 nginx 之间的异同点不会引起太多疑问。感谢您一直支持我们！


# https://cn.angie.software/angie/docs/installation/sourcebuild.md

<!-- review: finished -->

<a id="sourcebuild"></a>

# 从源代码构建 Angie

我们建议从官方预构建的 [软件包](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages) 安装 Angie。
但是,如果您仍然需要自己构建:

1. 从 [我们的网站](https://download.angie.software/files/) 下载 `.tar.gz` 归档文件:
   ```console
   $ curl -O https://download.angie.software/files/angie-|version|.tar.gz
   ```
2. 解压归档文件并导航到源代码目录:
   ```console
   $ tar -xpf angie-|version|.tar.gz
   $ cd angie-|version|
   ```
3. 要准备构建,请使用 **./configure** 脚本,
   该脚本确定构建所在操作系统的特定特征,
   特别是 Angie 可以用来处理连接的方法。
   成功运行后,该脚本会创建一个 `Makefile`。

   在运行 **./configure** 之前,请查看并设置所需的
   [构建选项](#configure):
   ```console
   $ ./configure <OPTIONS>
   ```
4. 当 `Makefile` 准备就绪后,构建并安装 Angie:
   ```console
   $ make
   $ make install
   ```

<a id="configure"></a>

## 构建选项

<a id="general"></a>

### 常规

| 选项                     | 描述                                                                                                                                                     | 默认值                            |
|------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|
| `--help`               | 打印帮助信息。                                                                                                                                                |                                |
| `--user=`name          | 设置非特权用户的名称,工作进程将使用其凭据。安装后,可以随时在<br/>`angie.conf` 配置文件中使用 [user](https://cn.angie.software//angie/docs/configuration/modules/core.md#user)<br/>指令更改该名称。 | `nobody`                       |
| `--group=`name         | 设置组的名称,工作进程将使用其凭据。安装后,可以随时在<br/>`angie.conf` 配置文件中使用 [user](https://cn.angie.software//angie/docs/configuration/modules/core.md#user)<br/>指令更改该名称。     | `--user` 设置                    |
| `--build=`name         | 为构建设置一个可选名称。                                                                                                                                           |                                |
| `--builddir=`path      | 设置构建目录。                                                                                                                                                | `objs`                         |
| `--feature-cache=`path | 指定用于缓存构建工件的目录。                                                                                                                                         | 如果设置时未指定路径,则使用 `--builddir` 设置 |

<a id="paths"></a>

### 路径

| 选项                                  | 描述                                                                                                                                                                                                                                            | 默认值                         |
|-------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------|
| `--prefix=`path                     | 定义将存储服务器文件的目录。此目录也将用于<br/>**./configure** 设置的所有相对路径(库源代码路径除外)<br/>以及 `angie.conf` 配置文件中的路径。                                                                                                                                                   | `/usr/local/angie`          |
| `--sbin-path=`path                  | 设置 Angie 可执行文件的名称。此名称仅在安装期间使用。                                                                                                                                                                                                                | `<prefix>/sbin/angie`       |
| `--modules-path=`path               | 定义将安装动态模块的目录。                                                                                                                                                                                                                                 | `<prefix>/modules`          |
| `--conf-path=`path                  | 设置 `angie.conf` [配置文件](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile) 的名称。<br/>如果需要,您可以随时使用 `-c` [命令行选项](https://cn.angie.software//angie/docs/configuration/runtime.md#runtime-cli-options) 以不同的配置文件启动 Angie。 | `<prefix>/conf/angie.conf`  |
| `--error-log-path=`path             | 设置主要错误、警告和诊断日志文件的名称。<br/>安装后,可以随时在 `angie.conf` 配置文件中使用<br/>[error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 指令更改文件名。                                                                               | `<prefix>/logs/error.log`   |
| `--pid-path=`path                   | 设置 `angie.pid` 文件的名称,该文件将存储主进程的进程 ID。<br/>安装后,可以随时在 `angie.conf` 配置文件中使用 [pid](https://cn.angie.software//angie/docs/configuration/modules/core.md#pid)<br/>指令更改文件名。                                                                          | `<prefix>/logs/angie.pid`   |
| `--lock-path=`path                  | 设置锁文件名的前缀。安装后,可以随时在 `angie.conf`<br/>配置文件中使用 [lock_file](https://cn.angie.software//angie/docs/configuration/modules/core.md#lock-file) 指令更改该值。                                                                                               | `<prefix>/logs/angie.lock`  |
| `--http-acme-client-path=`path      | 设置用于存储已定义 [acme](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#id4) 指令的 `server`<br/>块的证书和密钥的目录。                                                                                                              | `<prefix>/acme_client`      |
| `--http-log-path=`path              | 设置 HTTP 服务器的主要请求日志文件的名称。安装后,<br/>可以随时在 `angie.conf` 配置文件中使用<br/>[access_log](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#access-log) 指令更改文件名。                                                                | `<prefix>/logs/access.log`  |
| `--http-client-body-temp-path=`path | 定义用于存储保存客户端请求正文的临时文件的目录。安装后,<br/>可以随时在 `angie.conf` 配置文件中使用<br/>[client_body_temp_path](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client-body-temp-path) 指令更改该目录。                                             | `<prefix>/client_body_temp` |
| `--http-proxy-temp-path=`path       | 定义用于存储从代理服务器接收的数据的临时文件的目录。安装后,<br/>可以随时在 `angie.conf` 配置文件中使用<br/>[proxy_temp_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-temp-path) 指令更改该目录。                                                  | `<prefix>/proxy_temp`       |
| `--http-fastcgi-temp-path=`path     | 定义用于存储从 FastCGI 服务器接收的数据的临时文件的目录。<br/>安装后,可以随时在 `angie.conf` 配置文件中使用<br/>[fastcgi_temp_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#fastcgi-temp-path) 指令更改该目录。                                     | `<prefix>/fastcgi_temp`     |
| `--http-uwsgi-temp-path=`path       | 定义用于存储从 uWSGI 服务器接收的数据的临时文件的目录。<br/>安装后,可以随时在 `angie.conf` 配置文件中使用<br/>[uwsgi_temp_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#uwsgi-temp-path) 指令更改该目录。                                             | `<prefix>/uwsgi_temp`       |
| `--http-scgi-temp-path=`path        | 定义用于存储从 SCGI 服务器接收的数据的临时文件的目录。<br/>安装后,可以随时在 `angie.conf` 配置文件中使用<br/>[scgi_temp_path](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#scgi-temp-path) 指令更改该目录。                                                 | `<prefix>/scgi_temp`        |

<a id="install-source-features"></a>

### 功能和依赖项

| `--with-select_module`, `--without-select_module`   | 启用或禁用构建一个允许服务器使用 `select()` 方法的模块。如果平台似乎不支持更合适的方法,例如 `kqueue`、`epoll` 或 `/dev/poll`,则该模块会自动构建。                                                                                                                                                                                                                                                                                                                                                                      |
|-----------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `--with-poll_module`, `--without-poll_module`       | 启用或禁用构建一个允许服务器使用 `poll()` 方法的模块。如果平台似乎不支持更合适的方法,例如 `kqueue`、`epoll` 或 `/dev/poll`,则该模块会自动构建。                                                                                                                                                                                                                                                                                                                                                                        |
| `--with-threads`                                    | 启用使用 [线程池](https://cn.angie.software//angie/docs/configuration/modules/core.md#thread-pool) (`aio threads` 模式)。                                                                                                                                                                                                                                                                                                                                                     |
| `--with-file-aio`                                   | 启用在 FreeBSD 和 Linux 上使用 [异步文件 I/O](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#aio) (AIO) (`aio on` 模式)。                                                                                                                                                                                                                                                                                                                              |
| `--with-debug`                                      | 启用 [调试日志](https://cn.angie.software//angie/docs/troubleshooting.md#debug-logging)。                                                                                                                                                                                                                                                                                                                                                                                  |
| `--without-http-cache`                              | 禁用 HTTP 缓存。                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `--with-pcre`, `--with-pcre=`path                   | 启用使用 PCRE 库。<br/><br/>可选参数设置 PCRE 库源代码的路径。需要从 [PCRE](http://www.pcre.org/) 站点下载并解压库分发包。其余部分由 Angie 的 **./configure** 和 **make** 命令完成。<br/><br/>该库对于 `location` 指令中的正则表达式支持以及 [Rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#http-rewrite) 模块是 **必需的**。                                                                                                                                                                  |
| `--with-pcre-opt=`parameters                        | 设置 PCRE 的附加构建参数。                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `--with-pcre-jit`                                   | 使用 JIT 编译支持构建 PCRE 库([pcre_jit](https://cn.angie.software//angie/docs/configuration/modules/core.md#pcre-jit) 指令)。                                                                                                                                                                                                                                                                                                                                                  |
| `--without-pcre`                                    | 禁用使用 PCRE 库。                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| `--without-pcre2`                                   | 禁用使用 PCRE2 库而不是原始 PCRE 库。                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `--with-libatomic`, `--with-libatomic=`path         | 启用使用 **libatomic_ops** 库构建。可选参数设置库源代码的路径。                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `--with-openssl=`path                               | 启用静态构建并设置 OpenSSL 库源代码的路径。AWS-LC 可用作与 OpenSSL 兼容的库。                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `--with-openssl-opt=`parameters                     | 设置 OpenSSL 的附加构建参数。                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `--with-ntls`                                       | 在使用支持 NTLS 的 SSL 库构建时,启用 HTTP 模块([服务器端](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-ntls)、[客户端](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-ssl-ntls))和流模块([服务器端](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#s-ssl-ntls)、[客户端](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#s-proxy-ssl-ntls))中的 NTLS 支持。 |
| `--with-zlib=`path                                  | 设置 **zlib** 库源代码的路径。库分发包(版本 1.1.3 — 1.2.11)需要从 [zlib 站点](http://zlib.net/) 下载并解压。其余部分由 Angie 的 **./configure** 和 **make** 命令完成。<br/><br/>该库对于 [GZip](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#http-gzip) 模块是 **必需的**。                                                                                                                                                                                                          |
| `--with-zlib-opt=`parameters                        | 设置 **zlib** 的附加构建参数。                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `--with-zlib-asm=`cpu                               | 启用使用为以下处理器之一优化的汇编优化来构建 **zlib**:`pentium`、`pentiumpro`。                                                                                                                                                                                                                                                                                                                                                                                                             |

<a id="enabling-and-disabling-modules"></a>

### 启用和禁用模块

您可以禁用默认启用的模块,或启用默认可用但已禁用的模块。

<a id="http-1"></a>

#### HTTP

启用附加模块：

| `--with-http_acme_module`                                                    | 启用构建 [ACME](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#http-acme) 模块，该模块启用 ACME 协议。                                                                       |
|------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `--with-http_addition_module`                                                | 启用构建 [Addition](https://cn.angie.software//angie/docs/configuration/modules/http/http_addition.md#http-addition) 模块，该模块允许在响应前后添加文本。                                                          |
| `--with-http_auth_request_module`                                            | 启用构建 [Auth Request](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_request.md#http-auth-request) 模块，该模块提供基于子请求结果的客户端授权能力。                                        |
| `--with-http_dav_module`                                                     | 启用构建 [DAV](https://cn.angie.software//angie/docs/configuration/modules/http/http_dav.md#http-dav) 模块，该模块旨在通过 WebDAV 协议在服务器上自动化文件管理任务。                                                        |
| `--with-http_degradation_module`                                             | 启用构建降级模块，该模块允许为某些 `location` 块返回 HTTP 状态码 204 或 444。<br/><br/>此模块只能在 `sbrk(0)` 显示进程实际分配的内存量的情况下使用。换句话说，该模块默认在 FreeBSD 7.0 版本之前工作。从 7.0 版本开始,它只有在设置 `MALLOC_OPTIONS=Dm` 时才能工作。在 Linux 上它不起作用。 |
| `--with-http_flv_module`                                                     | 启用构建 [FLV](https://cn.angie.software//angie/docs/configuration/modules/http/http_flv.md#http-flv) 模块，该模块为 Flash Video (FLV) 文件提供服务器端伪流支持。                                                    |
| `--with-http_geoip_module`, `--with-http_geoip_module=dynamic`               | 启用构建 [GeoIP](https://cn.angie.software//angie/docs/configuration/modules/http/http_geoip.md#http-geoip) 模块，该模块创建的变量值基于客户端 IP 地址和现成的 [MaxMind](http://www.maxmind.com/) 数据库确定。                |
| `--with-http_gunzip_module`                                                  | 启用构建 [GunZIP](https://cn.angie.software//angie/docs/configuration/modules/http/http_gunzip.md#http-gunzip) 模块，该模块允许为不支持 `gzip` 压缩方法的客户端解压缩带有 `Content-Encoding: gzip` 的响应。                   |
| `--with-http_gzip_static_module`                                             | 启用构建 [Gzip Static](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip_static.md#http-gzip-static) 模块，该模块允许提供具有相同名称和 `.gz` 扩展名的预压缩文件，而不是常规文件。                         |
| `--with-http_image_filter_module`, `--with-http_image_filter_module=dynamic` | 启用构建 [Image Filter](https://cn.angie.software//angie/docs/configuration/modules/http/http_image_filter.md#http-image-filter) 模块，该模块允许转换 JPEG、GIF、PNG 和 WebP 格式的图像。                           |
| `--with-http_mp4_module`                                                     | 启用构建 [MP4](https://cn.angie.software//angie/docs/configuration/modules/http/http_mp4.md#http-mp4) 模块，该模块为 MP4 格式文件提供服务器端伪流支持。                                                                |
| `--with-http_perl_module`, `--with-http_perl_module=dynamic`                 | 启用构建 [Perl](https://cn.angie.software//angie/docs/configuration/modules/http/http_perl.md#http-perl) 模块。                                                                                     |
| `--with-perl_modules_path=`path                                              | 设置 Perl 模块文件所在的目录。                                                                                                                                                                           |
| `--with-perl=`path                                                           | 设置 Perl 可执行文件的名称。                                                                                                                                                                            |
| `--with-http_random_index_module`                                            | 启用构建 [Random Index](https://cn.angie.software//angie/docs/configuration/modules/http/http_random_index.md#http-random-index) 模块，该模块处理以斜杠 (`/`) 结尾的请求，并返回一个随机文件作为目录的索引文件。                     |
| `--with-http_realip_module`                                                  | 启用构建 [RealIP](https://cn.angie.software//angie/docs/configuration/modules/http/http_realip.md#http-realip) 模块，该模块允许将客户端地址更改为在指定头字段中传递的地址。                                                    |
| `--with-http_secure_link_module`                                             | 启用构建 [Secure Link](https://cn.angie.software//angie/docs/configuration/modules/http/http_secure_link.md#http-secure-link) 模块。                                                                |
| `--with-http_slice_module`                                                   | 启用构建 [Slice](https://cn.angie.software//angie/docs/configuration/modules/http/http_slice.md#http-slice) 模块，该模块允许将请求拆分为子请求，每个子请求返回响应的特定范围。该模块提供大型响应的高效缓存。                                     |
| `--with-http_ssl_module`                                                     | 为 HTTP 服务器启用 [SSL](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#http-ssl) 支持。<br/><br/>此模块 **需要** OpenSSL 库。                                                 |
| `--with-http_stub_status_module`                                             | 启用构建 [Stub Status](https://cn.angie.software//angie/docs/configuration/modules/http/http_stub_status.md#http-stub-status) 模块，该模块提供对基本服务器状态信息的访问。                                             |
| `--with-http_sub_module`                                                     | 启用构建 [Sub](https://cn.angie.software//angie/docs/configuration/modules/http/http_sub.md#http-sub) 模块，该模块允许将响应中一个指定的字符串修改为另一个。                                                                |
| `--with-http_upstream_probe_icmp` (PRO)                                      | 为 [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#u-upstream-probe) 指令启用 ICMP 回显探测。需要操作系统 ICMP 支持。                            |
| `--with-http_v2_module`                                                      | 启用 [HTTP/2](https://cn.angie.software//angie/docs/configuration/modules/http/http_v2.md#http-v2) 模块。                                                                                         |
| `--with-http_v3_module`                                                      | 启用 [HTTP/3](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#http-v3) 模块。                                                                                         |

#### NOTE
对于构建，**强烈建议** 使用支持 [QUIC](https://www.rfc-editor.org/rfc/rfc9000.html) 协议的 SSL 库：

BoringSSL

使用 [BoringSSL](https://boringssl.googlesource.com/boringssl) 构建：

```console
$ ./configure
   --with-debug
   --with-http_v3_module
   --with-cc-opt="-I../boringssl/include"
   --with-ld-opt="-L../boringssl/build/ssl
                  -L../boringssl/build/crypto"
```

LibreSSL

使用 [LibreSSL](https://www.libressl.org/) 构建：

```console
$ ./configure
   --with-debug --with-http_v3_module
   --with-cc-opt="-I../libressl/build/include"
   --with-ld-opt="-L../libressl/build/lib"
```

QuicTLS

使用 [QuicTLS](https://github.com/quictls/openssl) 构建：

```console
$ ./configure
      --with-debug
      --with-http_v3_module
      --with-cc-opt="-I../quictls/build/include"
      --with-ld-opt="-L../quictls/build/lib"
```

如果不使用这些库，将使用 [OpenSSL](https://openssl.org/) 库的兼容模式，在该模式下不支持 [早期数据](https://datatracker.ietf.org/doc/html/rfc8446#section-2.3) 发送，并且缺少其他功能，如会话重用。这样的构建将 **只能** 与使用相同模式的 OpenSSL 的客户端和服务器交互。

| `--with-http_xslt_module`, `--with-http_xslt_module=dynamic`   | 启用构建 [XSLT](https://cn.angie.software//angie/docs/configuration/modules/http/http_xslt.md#http-xslt) 模块，该模块允许使用 XSLT 样式表转换 XML 响应。<br/><br/>此模块 **需要** **libxml2** 和 **libxslt** 库。                                                            |
|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `--with-google_perftools_module`                               | 启用构建 [Google PerfTools](https://cn.angie.software//angie/docs/configuration/modules/google_perftools.md#google-perftools) 模块，该模块支持使用 [Google Performance Tools](https://github.com/gperftools/gperftools) 对 Angie 工作进程进行性能分析。该模块面向 Angie 开发人员。 |

禁用标准模块：

| `--without-http`                            | 禁用 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#http-core) 服务器。                                                                                                                                                                   |
|---------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `--without-http_access_module`              | 禁用构建 [Access](https://cn.angie.software//angie/docs/configuration/modules/http/http_access.md#http-access) 模块，该模块允许限制对特定客户端地址的访问。                                                                                                                                     |
| `--without-http_api_module`                 | 禁用构建 [API](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#http-api) 模块，该模块提供 RESTful HTTP 接口，用于访问有关 Web 服务器实例的基于 JSON 的信息。                                                                                                              |
| `--without-http_metric_module`              | 禁用构建 [Metric](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#http-metric) 模块。                                                                                                                                                        |
| `--without-http_auth_basic_module`          | 禁用构建 [Auth Basic](https://cn.angie.software//angie/docs/configuration/modules/http/http_auth_basic.md#http-auth-basic) 模块，该模块允许通过使用 HTTP 基本身份验证协议验证用户名和密码来限制对资源的访问。                                                                                                   |
| `--without-http_autoindex_module`           | 禁用构建 [AutoIndex](https://cn.angie.software//angie/docs/configuration/modules/http/http_autoindex.md#http-autoindex) 模块，该模块处理以斜杠字符 (`/`) 结尾的请求，并在 [Index](https://cn.angie.software//angie/docs/configuration/modules/http/http_index.md#http-index) 模块找不到索引文件时生成目录列表。 |
| `--without-http_browser_module`             | 禁用构建 [Browser](https://cn.angie.software//angie/docs/configuration/modules/http/http_browser.md#http-browser) 模块，该模块创建的变量值取决于 `User-Agent` 请求头字段的值。                                                                                                                   |
| `--without-http_charset_module`             | 禁用构建 [Charset](https://cn.angie.software//angie/docs/configuration/modules/http/http_charset.md#http-charset) 模块，该模块将指定的字符集添加到 `Content-Type` 响应头字段，并且可以将数据从一种字符集转换为另一种字符集。                                                                                           |
| `--without-http_empty_gif_module`           | 禁用构建 [模块](https://cn.angie.software//angie/docs/configuration/modules/http/http_empty_gif.md#http-empty-gif)，该模块发出单像素透明 GIF。                                                                                                                                          |
| `--without-http_fastcgi_module`             | 禁用构建 [FastCGI](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#http-fastcgi) 模块，该模块将请求传递给 FastCGI 服务器。                                                                                                                               |
| `--without-http_geo_module`                 | 禁用构建 [Geo](https://cn.angie.software//angie/docs/configuration/modules/http/http_geo.md#http-geo) 模块，该模块创建的变量值取决于客户端 IP 地址。                                                                                                                                           |
| `--without-http_gzip_module`                | 禁用构建 [模块](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#http-gzip)，该模块压缩 HTTP 服务器响应。<br/><br/>此模块 **需要** **zlib** 库。                                                                                                                  |
| `--without-http_grpc_module`                | 禁用构建 [gRPC](https://cn.angie.software//angie/docs/configuration/modules/http/http_grpc.md#http-grpc) 模块，该模块将请求传递给 gRPC 服务器。                                                                                                                                           |
| `--without-http_limit_conn_module`          | 禁用构建 [Limit Conn](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_conn.md#http-limit-conn) 模块，该模块限制每个键的连接数，例如，来自单个 IP 地址的连接数。                                                                                                             |
| `--without-http_limit_req_module`           | 禁用构建 [Limit Req](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_req.md#http-limit-req) 模块，该模块限制每个键的请求处理速率，例如，来自单个 IP 地址的请求处理速率。                                                                                                          |
| `--without-http_map_module`                 | 禁用构建 [Map](https://cn.angie.software//angie/docs/configuration/modules/http/http_map.md#http-map) 模块，该模块创建的变量值取决于其他变量的值。                                                                                                                                              |
| `--without-http_memcached_module`           | 禁用构建 [Memcached](https://cn.angie.software//angie/docs/configuration/modules/http/http_memcached.md#http-memcached) 模块，该模块从 memcached 服务器获取响应。                                                                                                                        |
| `--without-http_mirror_module`              | 禁用构建 [Mirror](https://cn.angie.software//angie/docs/configuration/modules/http/http_mirror.md#http-mirror) 模块，该模块通过创建后台镜像子请求来实现原始请求的镜像。                                                                                                                               |
| `--without-http_prometheus_module`          | 禁用构建 HTTP 服务器的 [Prometheus](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#http-prometheus) 模块。                                                                                                                                  |
| `--without-http_proxy_module`               | 禁用构建 HTTP 服务器的 [Proxy](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#http-proxy) 模块。                                                                                                                                                 |
| `--without-http_referer_module`             | 禁用构建 [Referer](https://cn.angie.software//angie/docs/configuration/modules/http/http_referer.md#http-referer) 模块，该模块可以阻止 `Referer` 头字段值无效的请求访问站点。                                                                                                                     |
| `--without-http_rewrite_module`             | 禁用构建 [Rewrite](https://cn.angie.software//angie/docs/configuration/modules/http/http_rewrite.md#http-rewrite) 模块，该模块允许 HTTP 服务器重定向请求并更改其 URI。<br/><br/>此模块 **需要** PCRE 库。                                                                                             |
| `--without-http_scgi_module`                | 禁用构建 [SCGI](https://cn.angie.software//angie/docs/configuration/modules/http/http_scgi.md#http-scgi) 模块，该模块将请求传递给 SCGI 服务器。                                                                                                                                           |
| `--without-http_split_clients_module`       | 禁用构建 [Split Clients](https://cn.angie.software//angie/docs/configuration/modules/http/http_split_clients.md#http-split-clients) 模块，该模块为 A/B 测试创建变量。                                                                                                                   |
| `--without-http_ssi_module`                 | 禁用构建 [SSI](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssi.md#http-ssi) 模块，该模块处理通过它的响应中的 SSI（服务器端包含）命令。                                                                                                                                     |
| `--without-http_upstream_hash_module`       | 禁用构建实现 [hash](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-hash) 负载均衡方法的模块。                                                                                                                                                    |
| `--without-http_upstream_ip_hash_module`    | 禁用构建实现 [ip_hash](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-ip-hash) 负载均衡方法的模块。                                                                                                                                              |
| `--without-http_upstream_keepalive_module`  | 禁用构建提供到上游服务器的 [连接缓存](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-keepalive) 的模块。                                                                                                                                              |
| `--without-http_upstream_least_conn_module` | 禁用构建实现 [least_conn](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-least-conn) 负载均衡方法的模块。                                                                                                                                        |
| `--without-http_upstream_random_module`     | 禁用构建实现 [random](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-random) 负载均衡方法的模块。                                                                                                                                                |
| `--without-http_upstream_sticky_module`     | 禁用构建实现 [会话持久性](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-sticky) 的模块，确保客户端会话中的所有请求都传递到上游中的同一服务器。                                                                                                                            |
| `--without-http_upstream_zone_module`       | 禁用构建允许在 [共享内存区域](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#u-zone) 中存储上游运行时状态的模块。                                                                                                                                             |
| `--without-http_userid_module`              | 禁用构建 [UserID](https://cn.angie.software//angie/docs/configuration/modules/http/http_userid.md#http-userid) 模块，该模块设置适合客户端标识的 cookie。                                                                                                                                   |
| `--without-http_uwsgi_module`               | 禁用构建 [uWSGI](https://cn.angie.software//angie/docs/configuration/modules/http/http_uwsgi.md#http-uwsgi) 模块，该模块将请求传递给 uWSGI 服务器。                                                                                                                                       |

<a id="stream-modules"></a>

#### Stream 模块

启用附加模块：

#### \* - `--with-stream`, `--with-stream=dynamic`<br/>  - 启用核心 [Stream](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#stream-core) 模块，<br/>    用于通用 TCP/UDP 代理和负载均衡。

| `--with-stream_acme_module`                                        | 启用构建 [ACME](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_acme.md#stream-acme) 模块，<br/>该模块启用 ACME 协议。                                                                                                                                                                                                                                            |
|--------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `--with-stream_geoip_module`, `--with-stream_geoip_module=dynamic` | 启用 [GeoIP](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_geoip.md#stream-geoip) 模块，<br/>该模块根据客户端 IP 地址和预编译的 [MaxMind](http://www.maxmind.com/)<br/>数据库创建变量。                                                                                                                                                                                      |
| `--with-stream_mqtt_preread_module`                                | 启用 [MQTT Preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#stream-mqtt-preread) 模块，该模块允许<br/>从 MQTT [3.1.1](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718028)<br/>和 [5.0](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901033)<br/>版本的 `CONNECT` 数据包中提取客户端 ID 和用户名。 |
| `--with-stream_rdp_preread_module`                                 | 启用 [RDP Preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#stream-rdp-preread) 模块，该模块允许<br/>从 RDP 会话中提取 cookie。                                                                                                                                                                                                               |
| `--with-stream_realip_module`                                      | 启用 [RealIP](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_realip.md#stream-realip) 模块，<br/>该模块将客户端地址更改为 PROXY 协议头中发送的地址。                                                                                                                                                                                                                         |
| `--with-stream_ssl_module`                                         | 为 Stream 服务器启用 [SSL](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#stream-ssl) 支持。<br/><br/>构建和运行此模块\*\*需要\*\* OpenSSL 库。                                                                                                                                                                                                                 |
| `--with-stream_ssl_preread_module`                                 | 启用 [SSL Preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#stream-ssl-preread) 模块，该模块允许<br/>在不终止 SSL/TLS 的情况下从 [ClientHello](https://datatracker.ietf.org/doc/html/rfc5246#section-7.4.1.2)<br/>消息中提取信息。                                                                                                                      |
| `--with-stream_upstream_probe_icmp` (PRO)                          | 为 [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#s-u-upstream-probe) 指令启用 ICMP 回显探测。需要操作系统 ICMP 支持。                                                                                                                                                                                                      |

禁用标准模块：

#### \* - `--without-stream_access_module`<br/>  - 禁用 [Access](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_access.md#stream-access) 模块，<br/>    该模块允许限制对特定客户端地址的访问。

| `--without-stream_geo_module`                 | 禁用 [Geo](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_geo.md#stream-geo) 模块，<br/>该模块根据客户端 IP 地址创建具有不同值的变量。                           |
|-----------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `--without-stream_limit_conn_module`          | 禁用 [Limit Conn](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_limit_conn.md#stream-limit-conn) 模块，<br/>该模块限制每个键的连接数，例如来自单个 IP 地址的连接数。 |
| `--without-stream_map_module`                 | 禁用 [Map](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_map.md#stream-map) 模块，<br/>该模块根据其他变量的值创建变量。                                    |
| `--without-stream_return_module`              | 禁用 [Return](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_return.md#stream-return) 模块，<br/>该模块向客户端发送指定的值，然后关闭连接。                      |
| `--without-stream_set_module`                 | 禁用 [Set](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_set.md#stream-set) 模块，<br/>该模块为变量设置值。                                          |
| `--without-stream_split_clients_module`       | 禁用 [Split Clients](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_split_clients.md#stream-split-clients) 模块，<br/>该模块为 A/B 测试创建变量。      |
| `--without-stream_upstream_hash_module`       | 禁用实现 [hash](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-hash) 负载均衡方法的模块。                                            |
| `--without-stream_upstream_least_conn_module` | 禁用实现 [least_conn](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-least-conn) 负载均衡方法的模块。                                |
| `--without-stream_upstream_random_module`     | 禁用实现 [random](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-random) 负载均衡方法的模块。                                        |
| `--without-stream_upstream_zone_module`       | 禁用在 [共享内存区](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-zone) 中存储上游运行时状态的模块。                                        |

<a id="mail"></a>

#### Mail

启用附加模块：

#### \* - `--with-mail`, `--with-mail=dynamic`<br/>  - 启用核心 [Mail](https://cn.angie.software//angie/docs/configuration/modules/mail/index.md#mail-core) 模块，<br/>    该模块支持 POP3、IMAP4 和 SMTP。

| `--with-mail_ssl_module`   | 为 Mail 服务器启用 [SSL](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_ssl.md#mail-ssl) 支持。<br/><br/>构建和运行此模块\*\*需要\*\* OpenSSL 库。   |
|----------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------|

禁用标准模块：

#### \* - `--without-mail_imap_module`<br/>  - 在 Mail 服务器中禁用 [IMAP](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_imap.md#mail-imap) 协议。

| `--without-mail_pop3_module`   | 在 Mail 服务器中禁用 [POP3](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_pop3.md#mail-pop3) 协议。   |
|--------------------------------|---------------------------------------------------------------------------------------------------------------------|
| `--without-mail_smtp_module`   | 在 Mail 服务器中禁用 [SMTP](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_smtp.md#mail-smtp) 协议。   |

<a id="other-options"></a>

#### 其他选项

#### \* - `--with-cpp_test_module`<br/>  - 启用 CPP Test 模块。它主要用于开发和测试目的，<br/>    不适用于生产环境。

| `--add-module=`path         | 启用在指定路径构建外部模块。                                                                                                                                                                            |
|-----------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `--add-dynamic-module=`path | 启用在指定路径构建外部动态模块。                                                                                                                                                                          |
| `--with-compat`             | 启用动态模块兼容模式。启用后，Angie 可以加载和使用<br/>为相同 Angie 版本构建的动态模块，即使这些模块是使用不同选项构建的。<br/>Angie PRO 只能加载为 Angie PRO 构建的模块；<br/>由于模块签名不同，Angie (OSS) 模块会被拒绝。                                              |
| `--with-cc=`path            | 设置构建期间使用的编译器。                                                                                                                                                                             |
| `--with-cpp=`path           | 设置构建期间使用的预处理器。                                                                                                                                                                            |
| `--with-cc-opt=`parameters  | 设置将添加到 `CFLAGS` 变量的附加参数。<br/>在 FreeBSD 下使用系统 PCRE 库时，应指定<br/>`--with-cc-opt="-I /usr/local/include"`。<br/>如果需要增加 `select()` 支持的文件数，<br/>也可以在此处指定，例如 `--with-cc-opt="-D FD_SETSIZE=2048"`。 |
| `--with-ld-opt=`parameters  | 设置链接期间使用的附加参数。在 FreeBSD 下使用系统 PCRE 库时，<br/>应指定 `--with-ld-opt="-L /usr/local/lib"`。                                                                                                       |
| `--with-cpu-opt=`cpu        | 启用针对以下处理器之一优化的构建：<br/>`pentium`、`pentiumpro`、`pentium3`、`pentium4`、<br/>`athlon`、`opteron`、`sparc32`、`sparc64`、<br/>`ppc64`。                                                              |

<a id="examples-2"></a>

### 示例

**简单的启用 HTTPS 的构建**。此基本配置使用 SSL/TLS 启用 HTTPS 支持，
包含必要的依赖项（用于正则表达式的 PCRE、用于压缩的 **zlib**
以及用于 SSL/TLS 的 OpenSSL）：

```console
$ ./configure \
    --sbin-path=/usr/sbin/angie \
    --conf-path=/etc/angie/angie.conf \
    --pid-path=/run/angie.pid \
    --with-http_ssl_module \
    --with-pcre=../pcre2-10.40 \
    --with-zlib=../zlib-1.3 \
    --with-openssl=../openssl-3.0.8
```

**性能优化构建**。此配置针对性能进行了优化，包括 HTTP/2 支持、
**gzip** 静态压缩、PCRE 的 JIT 以及异步 I/O；
还启用了线程池以高效处理高负载：

```console
$ ./configure \
    --sbin-path=/usr/sbin/angie \
    --conf-path=/etc/angie/angie.conf \
    --pid-path=/run/angie.pid \
    --with-http_ssl_module \
    --with-http_v2_module \
    --with-http_gzip_static_module \
    --with-pcre=../pcre2-10.40 \
    --with-pcre-jit \
    --with-zlib=../zlib-1.3 \
    --with-threads \
    --with-file-aio
```

**具有 TCP/UDP 代理的负载均衡器**。此配置为 HTTP 和非 HTTP 服务设置负载均衡器：

```console
$ ./configure \
    --sbin-path=/usr/sbin/angie \
    --conf-path=/etc/angie/angie.conf \
    --pid-path=/run/angie.pid \
    --with-stream \
    --with-stream_ssl_module \
    --with-pcre=../pcre2-10.40 \
    --with-zlib=../zlib-1.3
```

**专用构建**。此配置包括 HTTPS、HTTP/2、压缩、增强的安全性和性能，
以及用于 Brotli 压缩和缓存管理的附加模块，针对 HTTP 和 TCP/UDP 代理进行了优化：

```console
$ ./configure \
    --prefix=/usr/local/angie \                        # Angie 的安装目录
    --sbin-path=/usr/sbin/angie \                      # Angie 二进制文件的路径
    --conf-path=/etc/angie/angie.conf \                # 主配置文件的路径
    --pid-path=/run/angie.pid \                        # PID 文件的路径
    --lock-path=/var/lock/angie.lock \                 # 锁文件的路径
    --error-log-path=/var/log/angie/error.log \        # 错误日志文件的路径
    --http-log-path=/var/log/angie/access.log \        # 访问日志文件的路径
    --with-http_ssl_module \                           # 启用 SSL 模块以支持 HTTPS
    --with-http_v2_module \                            # 启用 HTTP/2 支持以提升性能
    --with-http_realip_module \                        # 允许 Angie 正确处理 X-Real-IP 和 X-Forwarded-For 头
    --with-http_gzip_static_module \                   # 提供预压缩的 .gz 文件以减少 CPU 负载
    --with-http_stub_status_module \                   # 提供状态页面
    --with-threads \                                   # 启用线程池以在高负载下提升性能
    --with-file-aio \                                  # 启用异步 I/O
    --with-stream \                                    # 启用 TCP/UDP 代理功能
    --with-stream_ssl_module \                         # 为 TCP/UDP 代理添加 SSL/TLS 支持
    --with-pcre=../pcre2-10.40 \                       # 指定 PCRE 库的路径以支持正则表达式
    --with-pcre-jit \                                  # 为 PCRE 启用即时编译
    --with-zlib=../zlib-1.3 \                          # 指定 zlib 库的路径以支持压缩
    --with-openssl=../openssl-3.0.8 \                  # 指定 OpenSSL 库的路径以支持 SSL/TLS
    --with-openssl-opt="enable-ec_nistp_64_gcc_128" \  # 为 64 位 NIST 曲线优化 OpenSSL
    --add-module=../ngx_brotli \                       # 添加第三方 ngx_brotli 模块以支持 Brotli 压缩
    --add-dynamic-module=../ngx_cache_purge            # 添加第三方 ngx_cache_purge 模块以进行缓存管理
```


# https://cn.angie.software/angie/docs/configuration/ssl.md

<!-- review: finished -->

<a id="ssl-config"></a>

# SSL配置

要配置HTTPS服务器，必须在 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 块的监听套接字上启用 [ssl](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#listen) 参数，并且需要指定服务器证书和私钥文件的位置：

```nginx
server {
    listen              443 ssl;
    server_name         www.example.com;
    ssl_certificate     www.example.com.crt;
    ssl_certificate_key www.example.com.key;
    ssl_protocols       TLSv1.2 TLSv1.3;
    ssl_ciphers         HIGH:!aNULL:!MD5;
#...
}
```

服务器证书是一个公共实体。它会发送给每个连接到服务器的客户端。私钥是一个安全实体，应存储在访问受限的文件中；但它必须对Angie的主进程可读。私钥也可以与证书存储在同一个文件中。

```nginx
ssl_certificate     www.example.com.cert;
ssl_certificate_key www.example.com.cert;
```

在这种情况下，文件的访问权限也应受到限制。即使证书和密钥存储在一个文件中，只有证书会发送给客户端。

指令 [ssl_protocols](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-protocols) 和 [ssl_ciphers](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-ciphers) 可用于限制连接，仅包含SSL/TLS的强版本和密码。默认情况下，Angie使用：

```nginx
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
```

因此，通常不需要显式配置它们。

<a id="https-optimization"></a>

## HTTPS服务器优化

SSL操作消耗额外的CPU资源。在多处理器系统上，应运行多个 [worker processes](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-processes)，数量不能少于可用的CPU核心数。最耗CPU的操作是SSL握手。减少每个客户端的这些操作数量有两种方法：第一种是启用 [keepalive](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#keepalive-timeout) 连接，通过一个连接发送多个请求，第二种是重用SSL会话参数，以避免并行和后续连接的SSL握手。会话存储在一个由 [ssl_session_cache](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-session-cache) 指令配置的共享SSL会话缓存中。1MB的缓存大约包含4000个会话。默认缓存超时为5分钟。可以使用 [ssl_session_timeout](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-session-timeout) 指令增加。以下是一个针对具有10MB共享会话缓存的多核系统优化的配置示例：

```nginx
worker_processes auto;

http {
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;

    server {
        listen              443 ssl;
        server_name         www.example.com;
        keepalive_timeout   70;

        ssl_certificate     www.example.com.crt;
        ssl_certificate_key www.example.com.key;
        ssl_protocols       TLSv1.2 TLSv1.3;
        ssl_ciphers         HIGH:!aNULL:!MD5;
    #...
```

<a id="certificate-chaining"></a>

## SSL证书链

某些浏览器可能会对由知名证书颁发机构签署的证书提出警告，而其他浏览器可能不会。这是因为颁发机构使用了一个中间证书来签署服务器证书，而该中间证书并不在某个特定浏览器分发的知名受信任证书机构的证书库中。在这种情况下，颁发机构提供了一组链式证书，这些证书应与签署的服务器证书串联在一起。服务器证书必须在组合文件中位于链式证书之前：

```console
$ cat www.example.com.crt bundle.crt > www.example.com.chained.crt
```

生成的文件应与 [ssl_certificate](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-certificate) 指令一起使用：

```nginx
server {
    listen              443 ssl;
    server_name         www.example.com;
    ssl_certificate     www.example.com.chained.crt;
    ssl_certificate_key www.example.com.key;
#...
}
```

如果服务器证书和捆绑证书的顺序连接错误，Angie将无法启动并显示错误信息：

> SSL_CTX_use_PrivateKey_file(" ... /www.example.com.key") failed
> : (SSL: error:0B080074:x509 certificate routines:
>   X509_check_private_key:key values mismatch)

因为Angie尝试使用捆绑证书的第一个证书而不是服务器证书来使用私钥。

浏览器通常会存储它们收到的由受信任机构签署的中间证书，因此实际使用的浏览器可能已经拥有所需的中间证书，并且可能不会对未发送链式捆绑的证书提出警告。为了确保服务器发送完整的证书链，可以使用 **openssl** 命令行工具，例如：

```console
$ openssl s_client -connect www.godaddy.com:443

Certificate chain
 0 s:/C=US/ST=Arizona/L=Scottsdale/1.3.6.1.4.1.311.60.2.1.3=US
     /1.3.6.1.4.1.311.60.2.1.2=AZ/O=GoDaddy.com, Inc
     /OU=MIS Department/CN=www.GoDaddy.com
     /serialNumber=0796928-7/2.5.4.15=V1.0, Clause 5.(b)
   i:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc.
     /OU=http://certificates.godaddy.com/repository
     /CN=Go Daddy Secure Certification Authority
     /serialNumber=07969287
 1 s:/C=US/ST=Arizona/L=Scottsdale/O=GoDaddy.com, Inc.
     /OU=http://certificates.godaddy.com/repository
     /CN=Go Daddy Secure Certification Authority
     /serialNumber=07969287
   i:/C=US/O=The Go Daddy Group, Inc.
     /OU=Go Daddy Class 2 Certification Authority
 2 s:/C=US/O=The Go Daddy Group, Inc.
     /OU=Go Daddy Class 2 Certification Authority
   i:/L=ValiCert Validation Network/O=ValiCert, Inc.
     /OU=ValiCert Class 2 Policy Validation Authority
     /CN=http://www.valicert.com//emailAddress=info@valicert.com
```

在这个例子中，www.GoDaddy.com服务器证书#0的主题（"s"）由一个颁发者（"i"）签署，该颁发者本身是证书#1的主题，该证书由一个颁发者签署，该颁发者本身是证书#2的主题，该证书由知名颁发者ValiCert, Inc.签署，其证书存储在浏览器的内置证书库中。

如果没有添加证书捆绑，只有服务器证书#0将会显示。

<a id="compact-server"></a>

## 单个HTTP/HTTPS服务器

可以配置一个同时处理HTTP和HTTPS请求的单个服务器：

```nginx
server {
    listen              80;
    listen              443 ssl;
    server_name         www.example.com;
    ssl_certificate     www.example.com.crt;
    ssl_certificate_key www.example.com.key;
#...
}
```

<a id="name-based-https-servers"></a>

## 基于名称的HTTPS服务器

配置两个或多个在单个IP地址上监听的HTTPS服务器时，会出现常见问题：

```nginx
server {
    listen          443 ssl;
    server_name     www.example.com;
    ssl_certificate www.example.com.crt;
#...
}

server {
    listen          443 ssl;
    server_name     www.example.org;
    ssl_certificate www.example.org.crt;
#...
}
```

使用此配置，浏览器会接收到默认服务器的证书，即 www.example.com ，无论请求的服务器名称是什么。这是由SSL协议行为造成的。SSL连接在浏览器发送HTTP请求之前建立，而Angie并不知道请求的服务器名称。因此，它只能提供默认服务器的证书。

<a id="https-separate-ips"></a>

解决此问题的最古老且最稳健的方法是为每个HTTPS服务器分配一个独立的IP地址：

```nginx
server {
    listen          192.168.1.1:443 ssl;
    server_name     www.example.com;
    ssl_certificate www.example.com.crt;
#...
}

server {
    listen          192.168.1.2:443 ssl;
    server_name     www.example.org;
    ssl_certificate www.example.org.crt;
#...
}
```

<a id="an-ssl-certificate-with-multiple-names"></a>

## 具有多个名称的SSL证书

还有其他方法可以在多个HTTPS服务器之间共享一个IP地址。然而，它们都有各自的缺点。一种方法是使用在 `SubjectAltName` 证书字段中包含多个名称的证书，例如 `www.example.com` 和 `www.example.org` 。但是，`SubjectAltName` 字段的长度是有限的。

另一种方法是使用通配符名称的证书，例如 `*.example.org`。通配符证书保护指定域的所有子域，但仅限于一个级别。该证书匹配 `www.example.org`，但不匹配 `example.org` 和 `www.sub.example.org`。这两种方法也可以结合使用。证书可以在 `SubjectAltName` 字段中包含精确名称和通配符名称，例如 `example.org` 和 `*.example.org`。

最好将具有多个名称的证书文件及其私钥文件放在 `http` 配置级别，以便在所有服务器中继承它们的单一内存副本：

```nginx
ssl_certificate     common.crt;
ssl_certificate_key common.key;

server {
    listen          443 ssl;
    server_name     www.example.com;
#...
}

server {
    listen          443 ssl;
    server_name     www.example.org;
#...
}
```

<a id="sni"></a>

## 服务器名称指示

在单个IP地址上运行多个HTTPS服务器的更通用的解决方案是TLS服务器名称指示扩展（SNI，[RFC 6066](https://datatracker.ietf.org/doc/html/rfc6066.html)），该扩展允许浏览器在SSL握手期间传递请求的服务器名称，因此，服务器将知道它应该使用哪个证书进行连接。SNI目前被大多数现代浏览器支持，但一些旧的或特殊的客户端可能不会使用。

如果Angie是使用SNI支持构建的，则在使用 `-V` 开关运行时，Angie将显示此信息：

```console
$ angie -V
...
TLS SNI support enabled
...
```

然而，如果启用SNI的Angie动态链接到没有SNI支持的OpenSSL库，Angie将显示警告：

> Angie was built with SNI support, however, now it is linked
> dynamically to an OpenSSL library which has no tlsext support,
> therefore SNI is not available


# https://cn.angie.software/angie/docs/configuration/modules/stream.md

<a id="stream-core"></a>

# 流模块

核心流模块实现了处理 TCP 和 UDP 连接的基本功能：包括定义服务器块、流量路由、配置代理、SSL/TLS 支持，以及管理流式服务（如数据库、DNS 和其他基于 TCP 和 UDP 运行的协议）的连接。

本节中的其他模块扩展了此功能，允许您灵活地配置和优化流服务器以适应各种场景和需求。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，
此模块默认不会被构建；
应使用
`‑‑with‑stream`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用它。
在来自 [我们仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中，
该模块已包含在构建中。

<a id="configuration-example-55"></a>

## 配置示例

```nginx
worker_processes auto;

error_log /var/log/angie/error.log info;

events {
    worker_connections  1024;
}

stream {
    upstream backend {
        hash $remote_addr consistent;

        server backend1.example.com:12345 weight=5;
        server 127.0.0.1:12345            max_fails=3 fail_timeout=30s;
        server unix:/tmp/backend3;
    }

    upstream dns {
       server 192.168.0.1:53535;
       server dns.example.com:53;
    }

    server {
        listen 12345;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass backend;
    }

    server {
        listen 127.0.0.1:53 udp reuseport;
        proxy_timeout 20s;
        proxy_pass dns;
    }

    server {
        listen [::1]:12345;
        proxy_pass unix:/tmp/stream.socket;
    }
}
```

<a id="directives-64"></a>

## 指令

<a id="index-0"></a>

<a id="s-listen"></a>

### listen

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `listen` address[:port] [`ssl`] [`udp`] [`proxy_protocol`] [`setfib=`number] [`fastopen=`number] [`backlog=`number] [`rcvbuf=`size] [`sndbuf=`size] [`accept_filter=`filter] [`deferred`] [`bind`] [`ipv6only=``on` | `off`] [`reuseport`] [`so_keepalive=`on|off|[`keepidle`]:[`keepintvl`]:[`keepcnt`]];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                                                                                                                                                                                                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                                                                                                                                                                                                                                                                                                       |

设置服务器将接受连接的套接字的 address 和 port。可以只指定 port，这样 Angie 将监听所有可用的 IPv4（以及 IPv6，如果已启用）接口。地址也可以是主机名，例如：

```nginx
listen 127.0.0.1:12345;
listen *:12345;
listen 12345;     # 与 *:12345 相同
listen localhost:12345;
```

IPv6 地址用方括号指定：

```nginx
listen [::1]:12345;
listen [::]:12345;
```

UNIX 域套接字使用 `unix:` 前缀指定：

```nginx
listen unix:/var/run/angie.sock;
```

端口范围通过用连字符分隔的第一个和最后一个端口来指定：

```nginx
listen 127.0.0.1:12345-12399;
listen 12345-12399;
```

#### NOTE
不同的服务器必须监听不同的 address:port 对。

| `ssl`            | 允许指定在此端口上接受的所有连接应在 SSL 模式下工作。                            |
|------------------|----------------------------------------------------------|
| `udp`            | 配置监听套接字以处理数据报。为了在同一会话中处理来自相同地址和端口的数据包，还应指定 reuseport 参数。 |
| `proxy_protocol` | 允许指定在此端口上接受的所有连接应使用 PROXY 协议。                            |

`listen` 指令可以有几个与套接字相关的系统调用特定的附加参数。

| `setfib=`number        | 为监听套接字设置关联的路由表 FIB（`SO_SETFIB` 选项）。目前仅在 FreeBSD 上有效。                                                                                                                                                                                                                                                                                                                      |
|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `fastopen=`number      | 为监听套接字启用"TCP Fast Open"，并 [限制](https://datatracker.ietf.org/doc/html/rfc7413#section-5.1) 尚未完成三次握手的连接队列的最大长度。<br/><br/>#### WARNING<br/>除非服务器能够处理多次接收 [相同的带数据的 SYN 数据包](https://datatracker.ietf.org/doc/html/rfc7413#section-6.1)，否则不要启用此功能。                                                                                                                             |
| `backlog=`number       | 设置 `listen()` 调用中的 `backlog` 参数，该参数限制待处理连接队列的最大长度。默认情况下，在 FreeBSD、DragonFly BSD 和 macOS 上，`backlog` 设置为 `-1`，在其他平台上设置为 511。                                                                                                                                                                                                                                               |
| `rcvbuf=`size          | 设置监听套接字的接收缓冲区大小（`SO_RCVBUF` 选项）。                                                                                                                                                                                                                                                                                                                                          |
| `sndbuf=`size          | 设置监听套接字的发送缓冲区大小（`SO_SNDBUF` 选项）。                                                                                                                                                                                                                                                                                                                                          |
| `accept_filter=`filter | 设置监听套接字的接受过滤器名称（`SO_ACCEPTFILTER` 选项），该过滤器在将传入连接传递给 `accept()` 之前对其进行过滤。这仅在 FreeBSD 和 NetBSD 5.0+ 上有效。可接受的值为 `dataready` 和 `httpready`。                                                                                                                                                                                                                                   |
| `deferred`             | 指示在 Linux 上使用延迟 `accept()` （`TCP_DEFER_ACCEPT` 套接字选项）。                                                                                                                                                                                                                                                                                                                    |
| `bind`                 | 此参数指示为给定的 address:port 对进行单独的 `bind()` 调用。事实上，如果有多个具有相同 port 但不同地址的 `listen` 指令，并且其中一个 `listen` 指令监听给定端口的所有地址（\*:port），Angie 将只 `bind()` 到 \*:port。应该注意的是，在这种情况下将进行 `getsockname()` 系统调用以确定接受连接的地址。如果使用了 `setfib`、`fastopen`、`backlog`、`rcvbuf`、`sndbuf`、`accept_filter`、`deferred`、`ipv6only`、`reuseport` 或 `so_keepalive` 参数，则对于给定的 address:port 对将始终进行单独的 `bind()` 调用。 |
| `ipv6only=on` | `off`  | 此参数（通过 `IPV6_V6ONLY` 套接字选项）确定监听通配符地址 [::] 的 IPv6 套接字是仅接受 IPv6 连接还是同时接受 IPv6 和 IPv4 连接。此参数默认开启。它只能在启动时设置一次。                                                                                                                                                                                                                                                                |
| `reuseport`            | 此参数指示为每个工作进程创建单独的监听套接字（在 Linux 3.9+ 和 DragonFly BSD 上使用 `SO_REUSEPORT` 套接字选项，或在 FreeBSD 12+ 上使用 `SO_REUSEPORT_LB`），允许内核在工作进程之间分配传入连接。目前仅在 Linux 3.9+、DragonFly BSD 和 FreeBSD 12+ 上有效。<br/><br/>#### WARNING<br/>不当使用此选项可能会带来安全隐患。                                                                                                                                         |
| `multipath`            | 启用通过 多路径 TCP<br/><https://en.wikipedia.org/wiki/Multipath_TCP>\`_\_（MPTCP）协议接受连接，从 5.6 版本开始在 Linux 内核中支持。<br/>此参数与 :samp:\`udp **不兼容**。                                                                                                                                                                                                                                   |

`so_keepalive=on` | `off` | [`keepidle`]:[`keepintvl`]:[`keepcnt`]

配置监听套接字的"TCP keepalive"行为。

| `''`   | 如果省略此参数，则套接字将使用操作系统的设置   |
|--------|--------------------------|
| `on`   | 为套接字开启 SO_KEEPALIVE 选项   |
| `off`  | 为套接字关闭 SO_KEEPALIVE 选项   |

某些操作系统支持使用 `TCP_KEEPIDLE`、`TCP_KEEPINTVL` 和
`TCP_KEEPCNT` 套接字选项在每个套接字的基础上设置 TCP keepalive 参数。在这
些系统上（目前包括 Linux 2.4+、NetBSD 5+ 和 FreeBSD 9.0-STABLE），可以使用
keepidle、keepintvl 和 keepcnt 参数进行配置。可以省略一个或两个参数，在这
种情况下，相应套接字选项的系统默认设置将生效。

例如，

```nginx
so_keepalive=30m::10
```

将空闲超时（`TCP_KEEPIDLE`）设置为 30 分钟，将探测间隔（`TCP_KEEPINTVL`）保留为系统默认值，并将探测次数（`TCP_KEEPCNT`）设置为 10 次探测。

<a id="index-1"></a>

<a id="s-preread-buffer-size"></a>

### preread_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `preread_buffer_size` size;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `preread_buffer_size 16k;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                |

指定 [预读](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions) 缓冲区的大小。

<a id="index-2"></a>

<a id="s-preread-timeout"></a>

### preread_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `preread_timeout` timeout;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `preread_timeout 30s;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server               |

指定 [预读](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions) 阶段的超时时间。

<a id="index-3"></a>

<a id="s-proxy-protocol-timeout"></a>

### proxy_protocol_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_protocol_timeout` timeout;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `proxy_protocol_timeout 30s;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                      |

指定读取 PROXY 协议头完成的超时时间。如果在此时间内未传输完整个头部，则连接将被关闭。

<a id="index-4"></a>

<a id="s-resolver"></a>

### resolver

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `resolver` address ... [`valid=`time] [`ipv4=``on` | `off`] [`ipv6=``on` | `off`] [`status_zone=`zone];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server, upstream                                                                                  |

配置用于将上游服务器名称解析为地址的域名服务器，例如：

```nginx
resolver 127.0.0.53 [::1]:5353;
```

地址可以指定为域名或 IP 地址，并可选端口。如果未指定端口，则使用端口 53。域名服务器以轮询方式查询。

#### NOTE
建议使用本地可信解析器，例如 `127.0.0.53` (systemd-resolved)，而非
公共解析器（如 `8.8.8.8`）。公共解析器会将 DNS 查询暴露给第三方，
并增加缓存投毒攻击的风险。

#### NOTE
该指令值会被嵌套块继承，
并可在其中根据需要覆盖。
在单个块内，该指令只能指定一次。
如果重复指定，则最后的定义生效。

默认情况下，Angie 使用响应的 TTL 值缓存答案。如果
未指定 `resolver` 指令且不执行动态 DNS 查询
（例如，在 [Proxy](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#stream-proxy) 中使用固定名称而不使用
变量时），则不需要指定解析器：名称将在启动时
使用系统解析器进行解析。可选的 `valid` 参数允许
覆盖此行为：

| `valid`   |  *可选* 参数允许覆盖响应缓存的有效期   |
|-----------|------------------------|
```nginx
resolver 127.0.0.53 [::1]:5353 valid=30s;
```

默认情况下，Angie 在解析时会同时查找 IPv4 和 IPv6 地址。

| `ipv4=off`   | 禁用 IPv4 地址查找   |
|--------------|----------------|
| `ipv6=off`   | 禁用 IPv6 地址查找   |

<a id="s-resolver-status"></a>

| `status_zone`   |  *可选* 参数;<br/>在指定区域中启用 DNS 服务器请求和响应指标的收集<br/>([/status/resolvers/<zone>](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-resolvers))   |
|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

<a id="index-5"></a>

<a id="s-resolver-timeout"></a>

### resolver_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `resolver_timeout` time;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `resolver_timeout 30s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream、server、upstream     |

设置名称解析的超时时间,例如:

```nginx
resolver_timeout 5s;
```

<a id="index-6"></a>

<a id="s-error-log-user-tag"></a>

### error_log_user_tag

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `error_log_user_tag` value;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | —                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream、server                 |

向错误日志记录添加会话特定的标签。value 是一个 [复杂值](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax),
可以使用变量。该指令可以多次指定以添加多个标签。
标签可以在 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 中使用 `filter=tag:` 进行匹配。

<a id="index-7"></a>

<a id="s-server"></a>

### server

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server` { ... }   |
|--------------------------------------------------------------------------------------|--------------------|
| 默认值                                                                                  | —                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream             |

设置服务器的配置。

<a id="index-8"></a>

<a id="s-server-name"></a>

### server_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server_name` name ...;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `server_name "";`         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                    |

设置虚拟服务器的名称。

#### WARNING
在 `stream` 模块中,:samp:server_name 指令基于服务器名称指示
([SNI](https://cn.angie.software//angie/docs/configuration/ssl.md#sni)),仅适用于 TLS 连接。要使用它,
必须在相应的 `server` 块中 [配置 TLS 终止](https://cn.angie.software//angie/docs/configuration/ssl.md#ssl-config) 或 [启用 TLS
预读](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#stream-ssl-preread)。

配置示例:

```nginx
server {
    listen 443 ssl;
    server_name example.com www.example.com;
    ssl_certificate /etc/angie/cert.pem;
    ssl_certificate_key /etc/angie/key.pem;
}
```

第一个名称成为主服务器名称。

服务器名称可以包含星号 (`*`)
来替换名称的第一部分或最后一部分:

```nginx
server {
    server_name example.com *.example.com www.example.*;
}
```

这些名称称为通配符名称。

您还可以在服务器名称中使用正则表达式,方法是在名称前加上
波浪号 (`~`):

```none
server {
    server_name www.example.com ~^www\d+\.example\.com$;
}
```

正则表达式可以包含捕获,可在其他指令中使用:

```nginx
server {
    server_name ~^(www\.)?(.+)$;

    proxy_pass www.$2:12345;
}
```

正则表达式中的命名捕获会创建变量,
可在其他指令中使用:

```nginx
server {
    server_name ~^(www\.)?(?<domain>.+)$;

    proxy_pass www.$domain:12345;
}
```

如果指令的参数设置为 `$hostname`,则会插入机器的主机名。

按名称搜索虚拟服务器时,如果名称匹配多个
指定的变体(例如,通配符名称和正则表达式
都匹配),将按以下优先级顺序选择第一个匹配的变体:

- 精确名称
- 以星号开头的最长通配符名称,例如
  `*.example.com`
- 以星号结尾的最长通配符名称,例如 `mail.*`
- 第一个匹配的正则表达式(按配置文件中出现的顺序)

<a id="index-9"></a>

<a id="s-server-names-hash-bucket-size"></a>

### server_names_hash_bucket_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server_names_hash_bucket_size` size;      |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | `server_names_hash_bucket_size 32|64|128;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                                     |

设置服务器名称哈希表的桶大小。默认值取决于
处理器缓存行的大小。

<a id="index-10"></a>

<a id="s-server-names-hash-max-size"></a>

### server_names_hash_max_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server_names_hash_max_size` size;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `server_names_hash_max_size 512;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                               |

设置服务器名称哈希表的最大大小。

<a id="index-11"></a>

<a id="s-status-zone"></a>

### status_zone

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `status_zone` zone | key `zone=`zone[:count];   |
|--------------------------------------------------------------------------------------|-------------------------------------------------|
| 默认值                                                                                  | —                                               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                                          |

分配共享内存区域以收集
[/status/stream/server_zones/<zone>](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-stream-server-zones) 的指标。

多个 `server` 上下文可以共享同一区域进行数据收集。

单值 zone 语法将当前上下文的所有指标聚合
在一个共享内存区域中:

```nginx
server {

    listen 80;
    server_name *.example.com;

    status_zone single;
    # ...
}
```

替代语法允许指定以下参数:

| key        | 包含变量的字符串,<br/>其值决定区域中连接的分组。<br/>所有在替换后产生相同值的连接<br/>会被分组在一起。<br/>如果替换产生空值,则不更新指标。   |
|------------|------------------------------------------------------------------------------------|
| zone       | 共享内存区域的名称。                                                                         |
| count (可选) | 用于收集指标的单独组的最大数量。<br/>如果新的 key 值超过此限制,<br/>它们将被分组到 zone 下。<br/><br/>默认值为 1。         |

在以下示例中,
所有具有相同 `$server_addr` 值的连接
被分组到 `host_zone` 中。
为每个唯一的 `$server_addr` 单独收集指标,
直到指标组数量达到 10。
之后,任何新的 `$server_addr` 值
将被添加到 `server_zone` 组:

```nginx
stream {

    upstream backend {
        server 192.168.0.1:3306;
        server 192.168.0.2:3306;
        # ...
    }

    server {

        listen 3306;
        proxy_pass backend;

        status_zone $server_addr zone=server_zone:10;
    }
}
```

生成的指标在 API 输出中按各个服务器拆分。

<a id="index-12"></a>

<a id="s-stream"></a>

### stream

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `stream` { ... }   |
|--------------------------------------------------------------------------------------|--------------------|
| 默认值                                                                                  | —                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main               |

提供配置文件上下文,在其中指定流服务器指令。

<a id="index-13"></a>

<a id="s-tcp-nodelay"></a>

### tcp_nodelay

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `tcp_nodelay` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `tcp_nodelay on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream、server                 |

启用或禁用 `TCP_NODELAY` 选项的使用。该选项对客户端连接和到代理服务器的连接都启用。

<a id="index-14"></a>

<a id="s-variables-hash-bucket-size"></a>

### variables_hash_bucket_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `variables_hash_bucket_size` size;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `variables_hash_bucket_size 64;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                               |

设置变量哈希表的桶大小。设置哈希表的详细信息在单独的 [文档](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes) 中提供。

<a id="index-15"></a>

<a id="s-variables-hash-max-size"></a>

### variables_hash_max_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `variables_hash_max_size` size;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `variables_hash_max_size 1024;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                            |

设置变量哈希表的最大大小。设置哈希表的详细信息在单独的 [文档](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes) 中提供。

<a id="stream-core-variables"></a>

## 内置变量

核心 stream 模块支持以下内置变量:

<a id="v-s-angie-version"></a>

### `$angie_version`

Angie 版本

<a id="v-s-binary-remote-addr"></a>

### `$binary_remote_addr`

二进制形式的客户端地址,IPv4 地址的值长度始终为 4 字节,IPv6 地址为 16 字节

<a id="v-s-bytes-received"></a>

### `$bytes_received`

从客户端接收的字节数

<a id="v-s-bytes-sent"></a>

### `$bytes_sent`

发送到客户端的字节数

<a id="v-s-connection"></a>

### `$connection`

连接序列号

<a id="v-s-hostname"></a>

### `$hostname`

主机名

<a id="v-s-msec"></a>

### `$msec`

当前时间(秒),精度为毫秒

<a id="v-s-nginx-version"></a>

### `$nginx_version`

nginx 版本

<a id="v-s-pid"></a>

### `$pid`

工作进程的 PID

<a id="v-s-protocol"></a>

### `$protocol`

用于与客户端通信的协议:`TCP` 或 `UDP`

<a id="v-s-proxy-protocol-addr"></a>

### `$proxy_protocol_addr`

来自 PROXY 协议头的客户端地址。
必须先通过在 [listen](#s-listen) 指令中设置 proxy_protocol 参数来启用 PROXY 协议。

<a id="v-s-proxy-protocol-port"></a>

### `$proxy_protocol_port`

来自 PROXY 协议头的客户端端口。
必须先通过在 [listen](#s-listen) 指令中设置 proxy_protocol 参数来启用 PROXY 协议。

<a id="v-s-proxy-protocol-server-addr"></a>

### `$proxy_protocol_server_addr`

来自 PROXY 协议头的服务器地址。
必须先通过在 [listen](#s-listen) 指令中设置 proxy_protocol 参数来启用 PROXY 协议。

<a id="v-s-proxy-protocol-server-port"></a>

### `$proxy_protocol_server_port`

来自 PROXY 协议头的服务器端口。
必须先通过在 [listen](#s-listen) 指令中设置 proxy_protocol 参数来启用 PROXY 协议。

<a id="v-s-proxy-protocol-tlv"></a>

### `$proxy_protocol_tlv_<name>`

从 PROXY 协议头获取的 TLV。name 可以是 TLV 类型名称或其数值。在后一种情况下,该值以十六进制指定,并且必须以 0x 开头:

```none
$proxy_protocol_tlv_alpn
$proxy_protocol_tlv_0x01
```

SSL TLV 也可以通过 TLV 类型名称和其数值来访问,两者都必须以 `ssl_` 开头:

```none
$proxy_protocol_tlv_ssl_version
$proxy_protocol_tlv_ssl_0x21
```

支持以下 TLV 类型名称:

* `alpn (0x01)` - 连接上使用的上层协议
* `authority (0x02)` - 客户端传递的主机名值
* `unique_id (0x05)` - 唯一连接标识符
* `netns (0x30)` - 命名空间名称
* `ssl (0x20)` - 二进制格式的 SSL TLV 结构

支持以下 SSL TLV 类型名称:

* `ssl_version (0x21)` - 客户端连接中使用的 SSL 版本
* `ssl_cn (0x22)` - 证书通用名称
* `ssl_cipher (0x23)` - 使用的密码套件名称
* `ssl_sig_alg (0x24)` - 用于签署证书的算法
* `ssl_key_alg (0x25)` - 公钥算法

还支持以下特殊 SSL TLV 类型名称:

* `ssl_verify` - 客户端证书验证结果:如果客户端提供了证书并且验证成功则为 0,否则为非零值

必须先通过在 [listen](#s-listen) 指令中设置 proxy_protocol 参数来启用 PROXY 协议。

<a id="v-s-remote-addr"></a>

### `$remote_addr`

客户端地址

<a id="v-s-remote-port"></a>

### `$remote_port`

客户端端口

<a id="v-s-server-addr"></a>

### `$server_addr`

接受连接的服务器地址。
计算此变量的值通常需要一次系统调用。为了避免系统调用,:ref:s_listen 指令必须指定地址并使用 `bind` 参数。

<a id="v-s-server-port"></a>

### `$server_port`

接受连接的服务器端口

<a id="v-s-session-time"></a>

### `$session_time`

会话持续时间,以秒为单位,精度为毫秒

<a id="v-s-status"></a>

### `$status`

会话状态，可以是以下之一：

| `200`   | 会话成功完成                                                                                                                            |
|---------|-----------------------------------------------------------------------------------------------------------------------------------|
| `400`   | 无法解析客户端数据，例如 PROXY 协议头                                                                                                            |
| `403`   | 禁止访问，例如当访问受 [特定客户端地址](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_access.md#stream-access) 限制时      |
| `500`   | 内部服务器错误                                                                                                                           |
| `502`   | 错误网关，例如无法选择或访问上游服务器时                                                                                                              |
| `503`   | 服务不可用，例如当访问受 [连接数](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_limit_conn.md#stream-limit-conn) 限制时 |

<a id="v-s-time-iso8601"></a>

### `$time_iso8601`

ISO 8601 标准格式的本地时间

<a id="v-s-time-local"></a>

### `$time_local`

通用日志格式的本地时间


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_access.md

<!-- review: finished -->

<a id="stream-access"></a>

# Access

该模块允许限制某些客户端地址的访问。

<a id="configuration-example-56"></a>

## 配置示例

```nginx
server {
    ...
    deny  192.168.1.1;
    allow 192.168.1.0/24;
    allow 10.1.1.0/16;
    allow 2001:0db8::/32;
    deny  all;
}
```

规则按顺序检查，直到找到第一个匹配项。在此示例中，只有IPv4网络 `10.1.1.0/16` 和 `192.168.1.0/24` （不包括地址 `192.168.1.1`）以及IPv6网络 `2001:0db8::/32` 允许访问。

<a id="directives-65"></a>

## 指令

<a id="index-0"></a>

<a id="s-allow"></a>

### allow

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `allow` address | CIDR | `unix:` | `all`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | —                                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                              |

允许指定网络或地址的访问。如果指定了特殊值 `unix:`，则允许所有UNIX域套接字的访问。

<a id="index-1"></a>

<a id="s-deny"></a>

### deny

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `deny` address | CIDR | `unix:` | `all`;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | —                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                             |

拒绝指定网络或地址的访问。如果指定了特殊值 `unix:`，则拒绝所有UNIX域套接字的访问。


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_acme.md

<!-- review: finished -->

<a id="stream-acme"></a>

# ACME

允许使用 [ACME](https://datatracker.ietf.org/doc/html/rfc8555) 协议
为:samp:stream 上下文中定义的服务器自动获取证书。

在:ref:从源代码构建<sourcebuild> 时，
该模块默认不会被构建；必须使用
[构建参数](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure)
`--with-stream_acme_module`
（同时需要:option:!--with-http_acme_module ）
来启用它。
在来自:ref:我们的仓库<install-packages> 的软件包和镜像中，
该模块已包含在构建中。

#### NOTE
为了正确运行，`stream` 块
必须位于:samp:http 块之后。
这是因为stream模块使用在HTTP配置解析期间
创建的客户端定义。

<a id="configuration-example-57"></a>

## 配置示例

有关配置示例和设置说明，请参阅
[Stream 模块中的 ACME](https://cn.angie.software//angie/docs/configuration/acme.md#acme-config-stream) 部分。

<a id="directives-66"></a>

## 指令

<a id="index-0"></a>

<a id="s-acme"></a>

### acme

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `acme` name;   |
|--------------------------------------------------------------------------------------|----------------|
| 默认值                                                                                  | —              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server         |

对于在所有引用HTTP模块中给定\`name\`的:ref:ACME客户端<acme_client> 的
所有:ref:s_server 块中
通过:ref:s_server_name 指令指定的所有域名，
将获取单个证书；
如果:samp:server_name 配置发生变化，
证书将被更新以适应这些变化。

在每次Angie启动时，会为所有缺少有效证书的域名请求新证书。
可能的原因包括证书过期、
文件丢失或无法读取，
以及证书设置的变更。

#### NOTE
目前，通过正则表达式指定的域名
不受支持，将被跳过。

通配符域名仅在:samp:acme_client 中的
`challenge=dns` 模式下支持。

可以多次指定此指令
以加载不同类型的证书，例如RSA和ECDSA：

```nginx
server {

    listen 12345 ssl;
    server_name example.com www.example.com;

    ssl_certificate $acme_cert_rsa;
    ssl_certificate_key $acme_cert_key_rsa;

    ssl_certificate $acme_cert_ecdsa;
    ssl_certificate_key $acme_cert_key_ecdsa;

    acme rsa;
    acme ecdsa;
}
```

<a id="stream-acme-variables"></a>

## 内嵌变量

<a id="v-s-acme-cert-name"></a>

### `$acme_cert_<name>`

具有此\`name\`的客户端获取的最后一个证书文件（如果有）的内容。

<a id="v-s-acme-cert-key-name"></a>

### `$acme_cert_key_<name>`

具有此\`name\`的客户端使用的证书密钥文件的内容。

#### NOTE
证书文件仅在ACME客户端至少获取了一个证书后才可用，
而密钥文件在启动后立即可用。


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_geo.md

<!-- review: finished -->

<a id="stream-geo"></a>

# Geo

该模块根据客户端 IP 地址创建具有不同值的变量。

<a id="configuration-example-58"></a>

## 配置示例

```nginx
geo $geo {
    default        0;

    127.0.0.1      2;
    192.168.1.0/24 1;
    10.1.0.0/16    1;

    ::1            2;
    2001:0db8::/32 1;
}
```

<a id="directives-67"></a>

## 指令

<a id="index-0"></a>

<a id="s-geo"></a>

### geo

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geo` [$address] $variable { ... }   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认                                                                                   | —                                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                               |

描述指定变量的值如何依赖于客户端 IP 地址。默认情况下,地址取自 [$remote_addr](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-remote-addr) 变量,但也可以取自其他变量,例如:

```nginx
geo $arg_remote_addr $geo {
    ...;
}
```

#### NOTE
因为变量仅在使用时才被评估,所以即使存在大量声明的 `geo` 变量,也不会对连接处理造成额外开销。

如果变量的值不是一个有效的 IP 地址,则使用 "255.255.255.255" 地址。

地址可以指定为 CIDR 表示法中的前缀(包括单个地址)或作为范围。

还支持以下特殊参数:

| `delete`   | 删除指定的网络                                                                                                     |
|------------|-------------------------------------------------------------------------------------------------------------|
| `default`  | 当客户端地址不匹配任何指定地址时,赋给变量的值。当地址以 CIDR 表示法指定时,可以用 "`0.0.0.0/0`" 和 "`:/0`" 代替 `default`。当未指定 `default` 时,默认值为空字符串 |
| `include`  | 包含一个包含地址和值的文件。可以有多个包含                                                                                       |
| `ranges`   | 指示地址以范围形式指定。此参数应放在首位。为了加快 geo 基础的加载,地址应按升序排列                                                                |
| `volatile` | 指示该变量不可缓存                                                                                                   |

示例:

```nginx
geo $country {
    default        ZZ;
    include        conf/geo.conf;
    delete         127.0.0.0/16;

    127.0.0.0/24   US;
    127.0.0.1/32   RU;
    10.1.0.0/16    RU;
    192.168.1.0/24 UK;
}
```

`conf/geo.conf` 文件可能包含以下行:

```console
10.2.0.0/16    RU;
192.168.2.0/24 RU;
```

使用最具体匹配的值。例如,对于 `127.0.0.1` 地址,将选择值 `RU`,而不是 `US`。

使用范围的示例:

```nginx
geo $country {
    ranges;
    default                   ZZ;
    127.0.0.0-127.0.0.0       US;
    127.0.0.1-127.0.0.1       RU;
    127.0.0.2-127.0.0.255     US;
    10.1.0.0-10.1.255.255     RU;
    192.168.1.0-192.168.1.255 UK;
}
```


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_geoip.md

<!-- review: finished -->

<a id="stream-geoip"></a>

# GeoIP

使用预编译的 [MaxMind](http://www.maxmind.com/) 数据库，根据客户端 IP 地址创建变量。

当使用支持 IPv6 的数据库时，IPv4 地址会被查找为 IPv4 映射的 IPv6 地址。

在 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，需要使用 `‑‑with‑stream_geoip_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用此模块。

#### NOTE
此模块需要 [MaxMind GeoIP](http://www.maxmind.com/app/c) 库。

<a id="configuration-example-59"></a>

## 配置示例

```nginx
stream {
    geoip_country         GeoIP.dat;
    geoip_city            GeoLiteCity.dat;

    map $geoip_city_continent_code $nearest_server {
        default        example.com;
        EU          eu.example.com;
        NA          na.example.com;
        AS          as.example.com;
    }
#   ...
}
```

<a id="directives-68"></a>

## 指令

<a id="index-0"></a>

<a id="s-geoip-country"></a>

### geoip_country

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_country` file;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | —                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                  |

指定用于根据客户端 IP 地址确定国家的数据库。使用此数据库时可以使用以下变量：

| `$geoip_country_code`   | 两字母国家代码，例如，"RU"，"US"。                         |
|-------------------------|-----------------------------------------------|
| `$geoip_country_code3`  | 三字母国家代码，例如，"RUS"，"USA"。                       |
| `$geoip_country_name`   | 国家名称，例如，"Russian Federation"，"United States"。 |

<a id="index-1"></a>

<a id="s-geoip-city"></a>

### geoip_city

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_city` file;   |
|--------------------------------------------------------------------------------------|----------------------|
| 默认值                                                                                  | —                    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream               |

指定用于根据客户端 IP 地址确定国家、地区和城市的数据库。使用此数据库时可以使用以下变量：

| `$geoip_city_continent_code`   | 两字母洲代码，例如，"EU"，"NA"。                                                                                                                |
|--------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
| `$geoip_city_country_code`     | 两字母国家代码，例如，"RU"，"US"。                                                                                                               |
| `$geoip_city_country_code3`    | 三字母国家代码，例如，"RUS"，"USA"。                                                                                                             |
| `$geoip_city_country_name`     | 国家名称，例如，"Russian Federation"，"United States"。                                                                                       |
| `$geoip_dma_code`              | 美国的 DMA 区域代码（也称为"地铁代码"），根据 Google AdWords API 中的 [地理定位](https://developers.google.com/adwords/api/docs/appendix/cities-DMAregions)。 |
| `$geoip_latitude`              | 纬度。                                                                                                                                 |
| `$geoip_longitude`             | 经度。                                                                                                                                 |
| `$geoip_region`                | 两个字符的国家地区代码（地区、领土、州、省、联邦土地等），例如，"48"，"DC"。                                                                                          |
| `$geoip_region_name`           | 国家地区名称（地区、领土、州、省、联邦土地等），例如，"Moscow City"，"District of Columbia"。                                                                    |
| `$geoip_city`                  | 城市名称，例如，"Moscow"，"Washington"。                                                                                                      |
| `$geoip_postal_code`           | 邮政编码。                                                                                                                               |

<a id="index-2"></a>

<a id="s-geoip-org"></a>

### geoip_org

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `geoip_org` file;   |
|--------------------------------------------------------------------------------------|---------------------|
| 默认值                                                                                  | —                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream              |

指定用于根据客户端 IP 地址确定组织的数据库。使用此数据库时可以使用以下变量：

| `$geoip_org`   | 组织名称，例如，"The University of Melbourne"。   |
|----------------|------------------------------------------|


# https://cn.angie.software/angie/docs/installation/external-modules/stream_js.md

<!-- review: finished -->

<a id="stream-js"></a>

# JS

该模块用于在 njs 中实现处理程序——njs 是 JavaScript 语言的一个子集。

在我们的仓库中,该模块以 [动态方式](https://cn.angie.software//angie/docs/installation/index.md#install-dynamicmodules) 构建,并作为名为 `angie-module-njs` 或 `angie-pro-module-njs` 的独立软件包提供。

#### NOTE
还提供了名为 `...-njs-light` 的轻量级版本软件包;但是,它不能与常规版本同时使用。

<a id="configuration-example-100"></a>

## 配置示例

```nginx
stream {
    js_import stream.js;

    js_set $bar stream.bar;
    js_set $req_line stream.req_line;

    server {
        listen 12345;

        js_preread stream.preread;
        return     $req_line;
    }

    server {
        listen 12346;

        js_access  stream.access;
        proxy_pass 127.0.0.1:8000;
        js_filter  stream.header_inject;
    }
}

http {
    server {
        listen 8000;
        location / {
            return 200 $http_foo\n;
        }
    }
}
```

`stream.js` 文件:

```javascript
var line = '';

function bar(s) {
    var v = s.variables;
    s.log("hello from bar() handler!");
    return "bar-var" + v.remote_port + "; pid=" + v.pid;
}

function preread(s) {
    s.on('upload', function (data, flags) {
        var n = data.indexOf('\n');
        if (n != -1) {
            line = data.substr(0, n);
            s.done();
        }
    });
}

function req_line(s) {
    return line;
}

// Read HTTP request line.
// Collect bytes in 'req' until
// request line is read.
// Inject HTTP header into a client's request

var my_header =  'Foo: foo';
function header_inject(s) {
    var req = '';
    s.on('upload', function(data, flags) {
        req += data;
        var n = req.search('\n');
        if (n != -1) {
            var rest = req.substr(n + 1);
            req = req.substr(0, n + 1);
            s.send(req + my_header + '\r\n' + rest, flags);
            s.off('upload');
        }
    });
}

function access(s) {
    if (s.remoteAddress.match('^192.*')) {
        s.deny();
        return;
    }

    s.allow();
}

export default {bar, preread, req_line, header_inject, access};
```

<a id="directives-88"></a>

## 指令

<a id="index-0"></a>

<a id="s-js-access"></a>

### js_access

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_access` function | module.function;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | —                                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                            |

设置一个 njs 函数,该函数将在 [访问阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions) 被调用。可以引用模块函数。

该函数在流会话第一次到达 [访问阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions) 时被调用一次。该函数使用以下参数调用:

| `s`   | [流会话](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-stream-session) 对象   |
|-------|-----------------------------------------------------------------------------------------------------|

在此阶段,可以执行初始化或使用 [s.on()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#s-on) 方法为每个传入的数据块注册回调,直到调用以下方法之一: [s.done()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-s-done)、[s.decline()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-s-decline)、[s.allow()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-s-allow)。一旦调用其中一个方法,流会话处理就会切换到 [下一阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions),并且所有当前的 [s.on()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#s-on) 回调都会被丢弃。

<a id="index-1"></a>

<a id="s-js-context-reuse"></a>

### js_context_reuse

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_context_reuse` number;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `js_context_reuse 128;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server               |

设置 QuickJS 引擎可重用的 JS 上下文的最大数量。每个上下文用于单个流会话。完成的上下文会被放入可重用上下文池中。如果池已满,则销毁该上下文。

<a id="index-2"></a>

<a id="s-js-engine"></a>

### js_engine

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_engine` `njs` | `qjs`;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `js_engine njs;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server               |

设置用于 njs 脚本的 JavaScript 引擎。`njs` 参数设置 njs 引擎,这也是默认使用的引擎。`qjs` 参数设置 QuickJS 引擎。

<a id="index-3"></a>

<a id="s-js-fetch-buffer-size"></a>

### js_fetch_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_buffer_size` size;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `js_fetch_buffer_size 16k;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                 |

设置用于 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 读取和写入的缓冲区大小。

<a id="index-4"></a>

<a id="s-js-fetch-ciphers"></a>

### js_fetch_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_ciphers` ciphers;          |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `js_fetch_ciphers HIGH:!aNULL:!MD5;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                       |

指定用于 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) HTTPS 连接的启用加密套件。加密套件以 OpenSSL 库理解的格式指定。

加密套件列表取决于安装的 OpenSSL 版本。
可以使用 `openssl ciphers` 命令查看完整列表。

<a id="index-5"></a>

<a id="s-js-fetch-max-response-buffer-size"></a>

### js_fetch_max_response_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_max_response_buffer_size` size;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `js_fetch_max_response_buffer_size 1m;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                              |

设置使用 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 接收的响应的最大大小。

<a id="index-6"></a>

<a id="s-js-fetch-protocols"></a>

### js_fetch_protocols

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_protocols` [`TLSv1`] [`TLSv1.1`] [`TLSv1.2`] [`TLSv1.3`];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------|
| 默认值                                                                                  | `js_fetch_protocols TLSv1 TLSv1.1 TLSv1.2;`                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                                        |

启用用于 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) HTTPS 连接的指定协议。

<a id="index-7"></a>

<a id="s-js-fetch-timeout"></a>

### js_fetch_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_timeout` time;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `js_fetch_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server             |

定义 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 读取和写入的超时时间。超时仅在两次连续的读/写操作之间设置,而不是针对整个响应。如果在此时间内没有数据传输,连接将被关闭。

<a id="index-8"></a>

<a id="s-js-fetch-trusted-certificate"></a>

### js_fetch_trusted_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_trusted_certificate` file;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                         |

指定一个包含 PEM 格式受信任 CA 证书的文件,用于验证 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 的 HTTPS 证书。

<a id="index-9"></a>

<a id="s-js-fetch-verify"></a>

### js_fetch_verify

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_verify` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `js_fetch_verify on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                    |

启用或禁用使用 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 对 HTTPS 服务器证书的验证。

<a id="index-10"></a>

<a id="s-js-fetch-verify-depth"></a>

### js_fetch_verify_depth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_verify_depth` number;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `js_fetch_verify_depth 100;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                    |

设置使用 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 在 HTTPS 服务器证书链中的验证深度。

<a id="index-11"></a>

<a id="s-js-fetch-keepalive"></a>

### js_fetch_keepalive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_keepalive` connections;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `js_fetch_keepalive 0;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                      |

激活到目标服务器的连接缓存。当该值大于 `0` 时,为 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 启用保持活动连接。

connections 参数设置每个工作进程缓存中保留的到目标服务器的空闲保持活动连接的最大数量。当超过此数量时,最近最少使用的连接将被关闭。

示例:

```nginx
server {
    listen 12345;
    js_fetch_keepalive 32;
    js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
    js_preread main.fetch_handler;
}
```

<a id="index-12"></a>

<a id="s-js-fetch-keepalive-requests"></a>

### js_fetch_keepalive_requests

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_keepalive_requests` number;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `js_fetch_keepalive_requests 1000;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                          |

设置通过一个与 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 的保持活动连接可以处理的最大请求数。达到最大请求数后,连接将被关闭。

定期关闭连接对于释放每个连接的内存分配是必要的。因此,使用过高的最大请求数可能导致过度的内存使用,不建议这样做。

<a id="index-13"></a>

<a id="s-js-fetch-keepalive-time"></a>

### js_fetch_keepalive_time

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_keepalive_time` time;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `js_fetch_keepalive_time 1h;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                    |

限制通过一个与 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 的保持活动连接可以处理请求的最长时间。达到此时间后,连接将在后续请求处理完成后关闭。

<a id="index-14"></a>

<a id="s-js-fetch-keepalive-timeout"></a>

### js_fetch_keepalive_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_fetch_keepalive_timeout` time;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认值                                                                                  | `js_fetch_keepalive_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                       |

设置与 [Fetch API](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 到目标服务器的空闲保持活动连接保持打开的超时时间。

<a id="index-15"></a>

<a id="s-js-filter"></a>

### js_filter

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_filter` function | module.function;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | —                                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                            |

设置数据过滤器。可以引用模块函数。

过滤器函数在流会话到达 [内容阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions) 时被调用一次。过滤器函数使用以下参数调用:

| `s`   | [流会话](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-stream-session) 对象   |
|-------|-----------------------------------------------------------------------------------------------------|

在此阶段,可以执行初始化或使用 [s.on()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#s-on) 方法为每个传入的数据块注册回调。可以使用 [s.off()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#s-off) 方法注销回调并停止过滤。

#### NOTE
由于 js_filter 处理程序立即返回其结果,因此它仅支持同步操作。因此,不支持异步操作,如 [ngx.fetch()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 或 [setTimeout()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-timers)。

<a id="index-16"></a>

<a id="s-js-import"></a>

### js_import

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_import` module.js | export_name from module.js;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------|
| 默认值                                                                                  | —                                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                        |

导入一个在 njs 中实现位置和变量处理程序的模块。export_name 用作访问模块函数的命名空间。如果未指定 export_name,则模块名称将用作命名空间。

```nginx
js_import stream.js;
```

这里,模块名称 stream 在访问导出时用作命名空间。如果导入的模块导出 foo(),则使用 stream.foo 来访问它。

可以指定多个 js_import 指令。

<a id="index-17"></a>

<a id="s-js-path"></a>

### js_path

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_path` path;   |
|--------------------------------------------------------------------------------------|-------------------|
| 默认值                                                                                  | —                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server    |

为 njs 模块设置附加路径。

<a id="index-18"></a>

<a id="s-js-periodic"></a>

### js_periodic

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_periodic` module.function [`interval=`\\ time] [`jitter=`\\ number] [`worker_affinity=`\\ mask];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                                                                                                 |

指定定期运行的内容处理程序。该处理程序接收会话对象作为其第一个参数,它还可以访问全局对象,如 `ngx`。

可选的 `interval` 参数设置两次连续运行之间的间隔,默认为 5 秒。

可选的 `jitter` 参数设置位置内容处理程序将被随机延迟的时间,默认情况下没有延迟。

默认情况下,:samp:js_handler 在工作进程 0 上执行。可选的 `worker_affinity` 参数允许指定应在其中执行位置内容处理程序的特定工作进程。每个工作进程集由允许的工作进程的位掩码表示。`all` 掩码允许处理程序在所有工作进程中执行。

示例:

```nginx
example.conf:

location @periodics {
    # 在工作进程 0 中以 1 分钟间隔运行
    js_periodic main.handler interval=60s;

    # 在所有工作进程中以 1 分钟间隔运行
    js_periodic main.handler interval=60s worker_affinity=all;

    # 在工作进程 1 和 3 中以 1 分钟间隔运行
    js_periodic main.handler interval=60s worker_affinity=0101;

    resolver 10.0.0.1;
    js_fetch_trusted_certificate /path/to/ISRG_Root_X1.pem;
}
```

```javascript
example.js:

async function handler(s) {
    let reply = await ngx.fetch('https://example.com/');
    let body = await reply.text();

    ngx.log(ngx.INFO, body);
}
```

<a id="index-19"></a>

<a id="s-js-preload-object"></a>

### js_preload_object

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_preload_object` name.json | name from file.json;   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------|
| 默认值                                                                                  | —                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                         |

在配置时预加载不可变对象。name 用作全局变量的名称,通过该变量可以在 njs 代码中访问该对象。如果未指定 name,则将使用文件名。

```nginx
js_preload_object map.json;
```

这里,\`map\` 在访问预加载对象时用作名称。

可以指定多个 js_preload_object 指令。

<a id="index-20"></a>

<a id="s-js-preread"></a>

### js_preread

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_preread` function | module.function;   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | —                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                             |

设置将在 [预读阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions) 调用的 njs 函数。可以引用模块函数。

该函数在流会话首次到达 [预读阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions) 时被调用一次。该函数使用以下参数调用:

| `s`   | [流会话](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-stream-session) 对象   |
|-------|-----------------------------------------------------------------------------------------------------|

在此阶段,可以执行初始化或使用 [s.on()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#s-on) 方法为每个传入的数据块注册回调,直到调用以下方法之一:[s.done()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-s-done)、[s.decline()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-s-decline)、[s.allow()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-s-allow)。当调用这些方法之一时,流会话切换到 [下一阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions),并且所有当前的 [s.on()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#s-on) 回调都将被丢弃。

#### NOTE
由于 js_preread 处理程序立即返回其结果,因此它仅支持同步操作。因此,不支持异步操作,如 [ngx.fetch()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 或 [setTimeout()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-timers)。然而,在 [预读阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions) 的 [s.on()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#s-on) 回调中支持异步操作。

<a id="index-21"></a>

<a id="s-js-set"></a>

### js_set

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_set` $variable function | module.function [`nocache`];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------|
| 默认值                                                                                  | —                                                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                               |

为指定的变量设置一个 njs 函数。可以引用模块函数。

当变量在给定请求中首次被引用时,该函数会被调用。确切的时刻取决于引用变量的 [阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions)。这可以用于执行一些与变量求值无关的逻辑。例如,如果变量仅在 [log_format](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_log.md#s-log-format) 指令中被引用,其处理程序将不会执行,直到日志阶段。此处理程序可用于在请求被释放之前进行一些清理工作。

从 njs 0.8.6 开始,当提供可选参数 `nocache` 时,处理程序在每次被引用时都会被调用。由于 rewrite 模块当前的限制,当 `nocache` 变量被 set 指令引用时,其处理程序应始终返回固定长度的值。

#### NOTE
由于 js_set 处理程序会立即返回其结果,因此它仅支持同步操作。因此,不支持异步操作,如 [ngx.fetch()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#ngx-fetch) 或 [setTimeout()](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-timers)。

<a id="index-22"></a>

<a id="s-js-shared-dict-zone"></a>

### js_shared_dict_zone

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_shared_dict_zone` `zone=`name:size [`timeout=`time] [`type=``string` | `number`] [`evict`] [`state=`file];   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                                                                                                           |

设置共享内存区域的名称和大小,该区域保存在工作进程之间共享的键值字典。

| `type`    | 可选参数,允许将值类型重新定义为 `number`,默认情况下共享字典使用 `string` 作为键和值   |
|-----------|--------------------------------------------------------|
| `timeout` | 可选参数,设置从区域中删除所有共享字典条目的时间                               |
| `evict`   | 可选参数,当区域存储耗尽时删除最旧的键值对                                  |
| `state`   | 可选参数,指定一个以 JSON 格式保存共享字典状态的文件,使其在 nginx 重启后保持持久化       |

示例:

```nginx
example.conf:
    # 创建一个 1Mb 的字符串值字典,
    # 在 60 秒不活动后删除键值对:
    js_shared_dict_zone zone=foo:1M timeout=60s;

    # 创建一个 512Kb 的字符串值字典,
    # 当区域耗尽时强制删除最旧的键值对:
    js_shared_dict_zone zone=bar:512K timeout=30s evict;

    # 创建一个 32Kb 的数字值永久字典:
    js_shared_dict_zone zone=num:32k type=number;

    # 创建一个 1Mb 的字符串值字典并具有持久化状态:
    js_shared_dict_zone zone=persistent:1M state=/tmp/dict.json;
```

```javascript
example.js:
    function get(r) {
        r.return(200, ngx.shared.foo.get(r.args.key));
    }

    function set(r) {
        r.return(200, ngx.shared.foo.set(r.args.key, r.args.value));
    }

    function delete(r) {
        r.return(200, ngx.shared.bar.delete(r.args.key));
    }

    function increment(r) {
        r.return(200, ngx.shared.num.incr(r.args.key, 2));
    }
```

<a id="index-23"></a>

<a id="s-js-var"></a>

### js_var

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `js_var` $variable [value];   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | —                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                |

声明一个 [可写](https://cn.angie.software//angie/docs/configuration/njs-reference.md#s-variables) 变量。值可以包含文本、变量及其组合。

<a id="session-object-properties"></a>

## 会话对象属性

每个 stream njs 处理程序接收一个参数,即 [stream 会话](https://cn.angie.software//angie/docs/configuration/njs-reference.md#njs-stream-session) 对象。


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_limit_conn.md

<!-- review: finished -->

<a id="stream-limit-conn"></a>

# Limit Conn

该模块用于限制每个定义的键的连接数量，特别是来自单个 IP 地址的连接数量。

<a id="configuration-example-60"></a>

## 配置示例

```nginx
stream {
    limit_conn_zone $binary_remote_addr zone=addr:10m;

    ...

    server {

        ...

        limit_conn           addr 1;
        limit_conn_log_level error;
    }
}
```

<a id="directives-69"></a>

## 指令

<a id="index-0"></a>

<a id="s-limit-conn"></a>

### limit_conn

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_conn` zone number;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认                                                                                   | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server              |

设置共享内存区域和给定键值的最大允许连接数。当超过此限制时，服务器将关闭连接。例如，指令

```nginx
limit_conn_zone $binary_remote_addr zone=addr:10m;

server {
    ...
    limit_conn addr 1;
}
```

仅允许每个 IP 地址同时有一个连接。

当指定多个 `limit_conn` 指令时，任何配置的限制将适用。

如果当前级别没有定义 `limit_conn` 指令，则这些指令将从前一个配置级别继承。

<a id="index-1"></a>

<a id="s-limit-conn-dry-run"></a>

### limit_conn_dry_run

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_conn_dry_run` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------------|
| 默认                                                                                   | `limit_conn_dry_run off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                       |

启用干运行模式。在此模式下，连接数量没有限制，但是在 [共享内存区域](#s-limit-conn-zone) 中，过量连接的数量仍然会正常计算。

<a id="index-2"></a>

<a id="s-limit-conn-log-level"></a>

### limit_conn_log_level

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_conn_log_level` `info` | `notice` | `warn` | `error`;   |
|--------------------------------------------------------------------------------------|----------------------------------------------------------------|
| 默认                                                                                   | `limit_conn_log_level error;`                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                                 |

设置服务器限制连接数量时所需的日志记录级别。

<a id="index-3"></a>

<a id="s-limit-conn-zone"></a>

### limit_conn_zone

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `limit_conn_zone` key zone = name:size;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认                                                                                   | —                                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                                    |

设置共享内存区域的参数，该区域将保存各种键的状态。特别是，状态包括当前连接数。键可以包含文本、变量及其组合。具有空键值的连接不被计算。

使用示例：

```nginx
limit_conn_zone $binary_remote_addr zone=addr:10m;
```

这里，客户端 IP 地址由 `$binary_remote_addr` 变量设置。

对于 IPv4 地址，`$binary_remote_addr` 的大小为 4 字节，对于 IPv6 地址则为 16 字节。在 32 位平台上，存储的状态始终占用 32 或 64 字节，在 64 位平台上占用 64 字节。

一个兆字节的区域可以保存大约 32000 个 32 字节的状态或大约 16000 个 64 字节的状态。如果区域存储耗尽，服务器将关闭连接。

<a id="built-in-variables-19"></a>

## 内置变量

<a id="v-s-limit-conn-status"></a>

### `$limit_conn_status`

保存限制连接数量的结果：`PASSED`,
`REJECTED` 或 `REJECTED_DRY_RUN`


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_log.md

<!-- review: finished -->

<a id="stream-log"></a>

# Log

该模块以指定格式写入请求日志。

<a id="configuration-example-61"></a>

## 配置示例

```nginx
log_format basic '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time';

access_log /spool/logs/angie-access.log basic buffer=32k;
```

<a id="directives-70"></a>

## 指令

<a id="index-0"></a>

<a id="s-access-log"></a>

### access_log

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `access_log` path [format [`buffer=`size] [gzip[=level]] [`flush=`time] [`if=`condition]];<br/><br/>`access_log` `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| 默认                                                                                   | `access_log off;`                                                                                                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                                                                                            |

设置缓冲日志写入的路径、格式和配置。可以在同一配置级别上指定多个日志。通过在第一个参数中指定 `"syslog:"` 前缀，可以配置记录到 [syslog](https://cn.angie.software//angie/docs/configuration/processing.md#syslog-logging)。特殊值 `off` 取消当前级别上的所有 `access_log` 指令。

如果使用了 `buffer` 或 `gzip` 参数，则日志写入将被缓冲。

#### WARNING
缓冲区大小不得超过对磁盘文件的原子写入大小。对于 FreeBSD，该大小是无限制的。

启用缓冲时，数据将写入文件：

* 如果下一行日志不适合缓冲区；
* 如果缓冲的数据比 `flush` 参数指定的时间间隔更旧；
* 当工作进程 [重新打开日志文件](https://cn.angie.software//angie/docs/configuration/runtime.md#log-rotation) 或关闭时。

如果使用了 `gzip` 参数，则缓冲区将在写入文件之前进行压缩。压缩级别可以设置在 `1` （最快，压缩较少）到 `9` （最慢，压缩效果最好）之间。默认情况下，使用 `64K` 字节的缓冲区大小和压缩级别 `1`。数据以原子块压缩，日志文件可以在任何时候通过 `"zcat"` 工具解压或读取。

示例：

```nginx
access_log /path/to/log.gz basic gzip flush=5m;
```

#### NOTE
为了支持 gzip 压缩，Angie 必须使用 zlib 库构建。

文件路径可以包含变量，但这类日志有一些限制：

* 使用工作进程凭据的 [user](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 应该具有在此类日志目录中创建文件的权限；
* 缓冲不起作用；
* 每次日志写入时都会打开文件，写入后立即关闭。然而，由于可以将频繁使用的文件的描述符存储在缓存中，因此在日志轮转期间，可能会在 [open_log_file_cache](https://cn.angie.software//angie/docs/configuration/modules/http/http_log.md#open-log-file-cache) 指令的 `valid` 参数指定的时间内继续写入旧文件。

`if` 参数启用条件日志记录。如果条件评估为 `"0"` 或空字符串，则不会记录该会话。

<a id="index-1"></a>

<a id="s-log-format"></a>

### log_format

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `log_format` name [`escape=``default` | `json` | `none`] string ...;   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------|
| 默认                                                                                   | —                                                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                                                                 |

指定日志格式，例如：

```nginx
log_format proxy '$remote_addr [$time_local] '
                 '$protocol $status $bytes_sent $bytes_received '
                 '$session_time "$upstream_addr" '
                 '"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
```

`escape` 参数允许在变量中设置 `json` 或 `default` 字符转义；默认使用 `default`。`none` 值禁用字符转义。

使用 `default` 时，字符 """、"\\" 以及值小于 32 或大于 126 的字符将被转义为 "\\xXX"。如果未找到变量值，则将记录一个连字符 "-"。

使用 `json` 时，所有在 JSON 字符串中不允许的字符都将被转义：字符 """ 和 "\\" 被转义为 "\\"" 和 "\\\\"，值小于 32 的字符被转义为 "\\n"、"\\r"、"\\t"、"\\b"、"\\f" 或 "\\u00XX"。

<a id="index-2"></a>

<a id="s-open-log-file-cache"></a>

### open_log_file_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `open_log_file_cache` `max=`N [`inactive=`time] [`min_uses=`N] [`valid=`time];<br/><br/>`open_log_file_cache` `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------|
| 默认                                                                                   | `open_log_file_cache off;`                                                                                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                                                                                         |

定义一个缓存，用于存储名称包含变量的频繁使用日志的文件描述符。该指令具有以下参数：

| `max`      | 设置缓存中描述符的最大数量；当缓存溢出时，关闭最近最少使用（LRU）的描述符。                |
|------------|--------------------------------------------------------|
| `inactive` | 设置缓存描述符在此时间内未被访问后关闭的时间；默认为 10 秒。                       |
| `min_uses` | 设置在 `inactive` 参数定义的时间内文件使用的最小次数，以便让描述符保持在缓存中打开；默认为 1。 |
| `valid`    | 设置检查文件是否仍然以相同名称存在的时间；默认为 60 秒。                         |
| `off`      | 禁用缓存。                                                  |

用法示例：

```nginx
open_log_file_cache max=1000 inactive=20s valid=1m min_uses=2;
```


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_map.md

<!-- review: finished -->

<a id="stream-map"></a>

# Map

创建的变量，其值依赖于其他变量的值。

<a id="configuration-example-62"></a>

## 配置示例

```nginx
map $remote_addr $limit {
    127.0.0.1    "";
    default      $binary_remote_addr;
}

limit_conn_zone $limit zone=addr:10m;
limit_conn addr 1;
```

<a id="directives-71"></a>

## 指令

<a id="index-0"></a>

<a id="s-map"></a>

### map

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `map` string $variable { ... };   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                            |

创建一个新变量。其值依赖于第一个参数，该参数以包含变量的字符串形式指定，例如：

```nginx
set $var1 "foo";
set $var2 "bar";

map $var1$var2 $new_variable {
    default "foobar_value";
}
```

在这里，变量 `$new_variable` 的值将由两个变量 `$var1` 和 `$var2` 组成，或者如果这些变量未定义，则使用默认值。

#### NOTE
由于变量仅在使用时才会被求值，即使声明了大量的"map"变量也不会对请求处理增加额外的成本。

`map` 块内的参数指定源值与结果值之间的映射关系。

源值以字符串或正则表达式的形式指定。

字符串匹配时不区分大小写。

正则表达式应以 `~` 符号开头以进行区分大小写的匹配，或以 `~*` 符号开头以进行不区分大小写的匹配。正则表达式可以包含命名和位置捕获，后者可以与结果变量一起在其他指令中使用。

如果源值与下面描述的特殊参数之一匹配，则应以 `\` 符号作为前缀。

结果值可以包含文本、变量及其组合。

还支持以下特殊参数：

| `default` value   | 如果源值与指定的变体都不匹配，则设置结果值。当未指定 default 时，默认结果值将为空字符串。   |
|-------------------|-----------------------------------------------------|
| `hostnames`       | 指示源值可以是带有前缀或后缀掩码的主机名。此参数应在值列表之前指定。                  |

例如，

```nginx
*.example.com 1;
example.*     1;
```

以下两条记录

```nginx
example.com   1;
*.example.com 1;
```

可以合并为：

```nginx
.example.com  1;
```

| `include` file   | 包含一个文件，其中包含值。可以有多个包含。   |
|------------------|-------------------------|
| `volatile`       | 指示变量不可缓存。               |

如果源值与多个指定的变体匹配，例如掩码和正则表达式都匹配，则将选择第一个匹配的变体，优先级顺序如下：

1. 没有掩码的字符串值
2. 带前缀掩码的最长字符串值，例如 `*.example.com`
3. 带后缀掩码的最长字符串值，例如 `mail.*`
4. 第一个匹配的正则表达式（按在配置文件中的出现顺序）
5. 默认值（`default`）

<a id="index-1"></a>

<a id="s-map-hash-bucket-size"></a>

### map_hash_bucket_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `map_hash_bucket_size` size;      |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | `map_hash_bucket_size 32|64|128;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                            |

设置 [map](#s-map) 变量哈希表的桶大小。默认值取决于处理器的缓存行大小。有关设置哈希表的详细信息，请参见 [单独](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes)。

<a id="index-2"></a>

<a id="s-map-hash-max-size"></a>

### map_hash_max_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `map_hash_max_size` size;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `map_hash_max_size 2048;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                      |

设置 [map](#s-map) 变量哈希表的最大大小。有关设置哈希表的详细信息，请参见 [单独](https://cn.angie.software//angie/docs/configuration/configfile.md#configure-hashes)。


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_mqtt_preread.md

<!-- review: finished -->

<a id="stream-mqtt-preread"></a>

# MQTT Preread

启用从消息队列遥测传输（MQTT）版本的 `CONNECT` 数据包中提取客户端 ID 和用户名
[3.1.1](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718028)
和
[5.0](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901033)。

当从源代码 [构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，
该模块必须通过 `--with-stream_mqtt_preread_module`
[构建参数](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用。
在来自 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中，
该模块已包含在构建中。

<a id="configuration-example-63"></a>

## 配置示例

<a id="choosing-a-server-in-a-group-by-client-id"></a>

### 通过客户端 ID 选择组中的服务器：

```nginx
stream {

    mqtt_preread on;

    upstream mqtt {
        hash $mqtt_preread_clientid;
        # ...
    }
}
```

<a id="directives-72"></a>

## 指令

<a id="index-0"></a>

<a id="s-mqtt-preread"></a>

### mqtt_preread

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `mqtt_preread` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认                                                                                   | `mqtt_preread off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                 |

控制在 [预读阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions) 从 `CONNECT` 数据包中提取信息。
如果参数启用（`on`），
将在指定的上下文中填充下面列出的变量。

<a id="built-in-variables-20"></a>

## 内置变量

有关值语义的详细描述，
请参阅 MQTT 协议规范版本
[3.1.1](http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718031)
和 [5.0](https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html#_Toc3901033)。

<a id="v-mqtt-preread-clientid"></a>

### `$mqtt_preread_clientid`

唯一客户端标识符。

<a id="v-mqtt-preread-username"></a>

### `$mqtt_preread_username`

可选用户名。


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_pass.md

<!-- review: finished -->

<a id="stream-pass"></a>

# Pass

允许将已接受的连接直接传递到在 [HTTP](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-http)、[Stream](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream) 或 [Mail](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-mail) 模块中配置的任何监听套接字。

该模块允许基于 SNI 执行选择性的 SSL 终止。

<a id="configuration-example-64"></a>

## 配置示例

在 `stream` 模块处理 SSL/TLS 终止后，连接被转发到 `http` 模块：

```nginx
stream {

    server {

        listen 8000 default_server;
        ssl_preread on;
        # ...
    }

    server {

        listen 8000;
        server_name foo.example.com;
        pass 127.0.0.1:8001; # to HTTP
    }

    server {

        listen 8000;
        server_name bar.example.com;
        # ...
    }
}

http {

    server {

        listen 8001 ssl;
        # ...

        location / {

            root html;
        }
    }
}
```

<a id="directives-73"></a>

## 指令

<a id="index-0"></a>

<a id="s-pass"></a>

### pass

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `pass` address;   |
|------------------------------------------------------------------------------------------|-------------------|
| 默认                                                                                       | —                 |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server            |

该指令设置客户端连接应传递到的服务器地址。address 可以作为 IP 地址和端口给出：

```nginx
pass 127.0.0.1:12345;
```

或者作为 UNIX 域套接字的路径：

```nginx
pass unix:/tmp/stream.socket;
```

此外，address 也可以用变量设置：

```nginx
pass $upstream;
```


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_proxy.md

<!-- review: finished -->

<a id="stream-proxy"></a>

# Proxy

允许通过 TCP、UDP 和 UNIX 域套接字代理数据流。

<a id="configuration-example-65"></a>

## 配置示例

```nginx
server {
    listen 127.0.0.1:12345;
    proxy_pass 127.0.0.1:8080;
}

server {
    listen 12345;
    proxy_connect_timeout 1s;
    proxy_timeout 1m;
    proxy_pass example.com:12345;
}

server {
    listen 53 udp reuseport;
    proxy_timeout 20s;
    proxy_pass dns.example.com:53;
}

server {
    listen [::1]:12345;
    proxy_pass unix:/tmp/stream.socket;
}
```

<a id="directives-74"></a>

## 指令

<a id="index-0"></a>

<a id="s-proxy-bind"></a>

### proxy_bind

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_bind` address [`transparent`] | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------------|
| 默认值                                                                                  | —                                               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                  |

使到代理服务器的出站连接源自指定的本地 IP 地址。参数值可以包含变量。特殊值 `off` 取消从上一级配置继承的 proxy_bind 指令的效果,允许系统自动分配本地 IP 地址。

`transparent` 参数允许到代理服务器的出站连接源自非本地 IP 地址,例如,来自客户端的真实 IP 地址:

```nginx
proxy_bind $remote_addr transparent;
```

要使此参数生效,
Angie 工作进程通常需要以
[超级用户](https://cn.angie.software//angie/docs/configuration/modules/core.md#user) 权限运行。
在 Linux 上,这不是必需的:
如果指定了 `transparent` 参数,
工作进程会从主进程继承 CAP_NET_RAW 能力。

#### NOTE
还应配置内核路由表
以拦截来自代理服务器的网络流量。

<a id="index-1"></a>

<a id="s-proxy-buffer-size"></a>

### proxy_buffer_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_buffer_size` size;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `proxy_buffer_size 16k;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server              |

设置用于从代理服务器读取数据的缓冲区大小。同时设置用于从客户端读取数据的缓冲区大小。

<a id="index-2"></a>

<a id="s-proxy-connect-timeout"></a>

### proxy_connect_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_connect_timeout` time;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `proxy_connect_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                  |

定义与代理服务器建立连接的超时时间。

<a id="index-3"></a>

<a id="s-proxy-connection-drop"></a>

### proxy_connection_drop

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_connection_drop` time | `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | `proxy_connection_drop off;`                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                 |

在代理服务器从组中移除或被 [重新解析](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#reresolve) 进程或 [API 命令](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config-methods) `DELETE` 标记为永久不可用后,启用终止到该代理服务器的所有会话。

当处理客户端或代理服务器的下一个读取或写入事件时,会话将被终止。

设置 time 启用会话终止 [超时](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax);
设置为 `on` 时,会话立即断开。

<a id="index-4"></a>

<a id="s-proxy-download-rate"></a>

### proxy_download_rate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_download_rate` rate;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `proxy_download_rate 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                |

限制从代理服务器读取数据的速度。`rate` 以每秒字节数指定。

| `0`   | 禁用速率限制   |
|-------|----------|

#### NOTE
限制是针对每个连接设置的,因此如果 Angie 同时打开两个到代理服务器的连接,总速率将是指定限制的两倍。

参数值可以包含变量。在需要根据特定条件限制速率的情况下,这可能很有用:

```nginx
map $slow $rate {
    1     4k;
    2     8k;
}

proxy_download_rate $rate;
```

<a id="index-5"></a>

<a id="s-proxy-half-close"></a>

### proxy_half_close

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_half_close` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `proxy_half_close off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                     |

启用或禁用独立关闭 TCP 连接的每个方向("TCP 半关闭")。如果启用,TCP 代理将保持到两端都关闭连接为止。

<a id="index-6"></a>

<a id="s-proxy-next-upstream"></a>

### proxy_next_upstream

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_next_upstream` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `proxy_next_upstream on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                        |

当无法与代理服务器建立连接时,确定是否将客户端连接传递给 [上游池](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 中的下一个服务器。

将连接传递给下一个服务器可以通过 [尝试次数](#s-proxy-next-upstream-tries) 和 [时间](#s-proxy-next-upstream-timeout) 进行限制。

<a id="index-7"></a>

<a id="s-proxy-next-upstream-timeout"></a>

### proxy_next_upstream_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_next_upstream_timeout` time;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `proxy_next_upstream_timeout 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                        |

限制将连接传递给 [下一个](#s-proxy-next-upstream) 服务器的允许时间。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-8"></a>

<a id="s-proxy-next-upstream-tries"></a>

### proxy_next_upstream_tries

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_next_upstream_tries` number;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `proxy_next_upstream_tries 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                        |

限制将连接传递给 [下一个](#s-proxy-next-upstream) 服务器的可能尝试次数。

| `0`   | 关闭此限制   |
|-------|---------|

<a id="index-9"></a>

<a id="s-proxy-pass"></a>

### proxy_pass

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_pass` address;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | —                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                  |

设置代理服务器的地址。`address` 可以指定为域名或 IP 地址,以及端口:

```nginx
proxy_pass localhost:12345;
```

或作为 UNIX 域套接字路径:

```nginx
proxy_pass unix:/tmp/stream.socket;
```

如果域名解析为多个地址,所有地址将以轮询方式使用。此外,地址可以指定为 [服务器组](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream)。

地址也可以使用变量指定:

```nginx
proxy_pass $upstream;
```

在这种情况下,在描述的 [服务器组](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 中搜索服务器名称,如果未找到,则使用 [resolver](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-resolver) 确定。

<a id="index-10"></a>

<a id="s-proxy-protocol"></a>

### proxy_protocol

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_protocol` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `proxy_protocol off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                   |

为到代理服务器的连接启用 [PROXY 协议](http://www.haproxy.org/download/1.8/doc/proxy-protocol.txt)。

<a id="index-11"></a>

<a id="s-proxy-protocol-version"></a>

### proxy_protocol_version

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_protocol_version` `1` | `2`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `proxy_protocol_version 1;`           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                        |

设置用于到代理服务器的连接的 PROXY 协议版本。该设置在启用 [proxy_protocol](#s-proxy-protocol) 时生效。版本 2 允许发送由 [proxy_protocol_tlv](#s-proxy-protocol-tlv) 指令配置的 TLV。

<a id="index-12"></a>

<a id="s-proxy-protocol-tlv"></a>

### proxy_protocol_tlv

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_protocol_tlv` name value;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | —                                  |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                     |

向发送到代理服务器的 PROXY 协议 v2 头添加 TLV。value 可以包含变量。name 可以是 TLV 类型名称或其数字值;在后一种情况下,值以十六进制指定,必须以 0x 开头。对于 SSL TLV,使用 `ssl_` 前缀;特殊的 `ssl_verify` 名称设置 SSL TLV 的验证字段。该指令仅在 [proxy_protocol_version](#s-proxy-protocol-version) 设置为 `2` 时使用。

<a id="index-13"></a>

<a id="s-proxy-requests"></a>

### proxy_requests

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_requests` number;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `proxy_requests 0;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server             |

设置客户端数据报的数量,达到该数量时,客户端与现有 UDP 流会话之间的绑定将被断开。在接收到指定数量的数据报后,来自同一客户端的下一个数据报将启动新会话。当所有客户端数据报都传输到代理服务器并接收到预期的 [响应数量](#s-proxy-responses) 时,或者当达到 [超时](#s-proxy-timeout) 时,会话终止。

<a id="index-14"></a>

<a id="s-proxy-responses"></a>

### proxy_responses

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_responses` number;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server              |

当使用 [UDP](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#stream-protocol) 协议时,设置期望从代理服务器响应客户端数据报的数据报数量。该数字作为会话终止的提示。默认情况下,数据报的数量不受限制。

如果指定为零值,则不期望响应。但是,如果收到响应且会话仍未结束,则将处理该响应。

<a id="index-15"></a>

<a id="s-proxy-socket-keepalive"></a>

### proxy_socket_keepalive

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_socket_keepalive` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------------|
| 默认值                                                                                  | `proxy_socket_keepalive off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                           |

为到代理服务器的出站连接配置"TCP keepalive"行为。

| `off`   | 默认情况下,套接字使用操作系统的设置。        |
|---------|----------------------------|
| `on`    | 为套接字启用 SO_KEEPALIVE 套接字选项。 |

<a id="index-16"></a>

<a id="s-proxy-ssl"></a>

### proxy_ssl

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `proxy_ssl off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server              |

为到代理服务器的连接启用 SSL/TLS 协议。

<a id="index-17"></a>

<a id="s-proxy-ssl-certificate"></a>

### proxy_ssl_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_certificate` file [file];   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                         |

指定一个包含 PEM 格式证书的文件,用于向代理服务器进行身份验证。文件名中可以使用变量。

当启用 [proxy_ssl_ntls](#s-proxy-ssl-ntls) 时,该指令接受两个参数而不是一个:

```nginx
server {
    proxy_ssl_ntls  on;

    proxy_ssl_certificate      sign.crt enc.crt;
    proxy_ssl_certificate_key  sign.key enc.key;

    proxy_ssl_ciphers "ECC-SM2-WITH-SM4-SM3:ECDHE-SM2-WITH-SM4-SM3:RSA";

    proxy_pass backend:12345;
}
```

<a id="index-18"></a>

<a id="s-proxy-ssl-certificate-key"></a>

### proxy_ssl_certificate_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_certificate_key` file [file];   |
|--------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                  | —                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                             |

指定一个包含 PEM 格式私钥的文件,用于向代理服务器进行身份验证。文件名中可以使用变量。

当启用 [proxy_ssl_ntls](#s-proxy-ssl-ntls) 时,该指令接受两个参数而不是一个:

```nginx
server {
    proxy_ssl_ntls  on;

    proxy_ssl_certificate      sign.crt enc.crt;
    proxy_ssl_certificate_key  sign.key enc.key;

    proxy_ssl_ciphers "ECC-SM2-WITH-SM4-SM3:ECDHE-SM2-WITH-SM4-SM3:RSA";

    proxy_pass backend:12345;
}
```

<a id="index-19"></a>

<a id="s-proxy-ssl-ciphers"></a>

### proxy_ssl_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_ciphers` ciphers;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `proxy_ssl_ciphers DEFAULT;`   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                 |

指定向代理服务器发送请求时启用的加密套件。加密套件以 OpenSSL 库理解的格式指定。

加密套件列表取决于安装的 OpenSSL 版本。
可以使用 `openssl ciphers` 命令查看完整列表。

#### WARNING
当使用 OpenSSL 时,:samp:proxy_ssl_ciphers 指令\*不\*配置 TLS 1.3 的加密套件。要使用 OpenSSL 配置 TLS 1.3 加密套件,请使用
[proxy_ssl_conf_command](#s-proxy-ssl-conf-command) 指令,该指令是为高级 SSL 配置添加的。

- 在 LibreSSL 中,TLS 1.3 加密套件\*可以\*使用
  `proxy_ssl_ciphers` 配置。
- 在 BoringSSL 中,无法配置 TLS 1.3 加密套件。

<a id="index-20"></a>

<a id="s-proxy-ssl-conf-command"></a>

### proxy_ssl_conf_command

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_conf_command` name value;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | —                                      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                         |

在与代理服务器建立连接时设置任意 OpenSSL 配置 [命令](https://docs.openssl.org/master/man3/SSL_CONF_cmd/)。

#### NOTE
当使用 OpenSSL 1.0.2 或更高版本时支持该指令。
要使用 OpenSSL 配置 TLS 1.3 加密套件,请使用 `ciphersuites` 命令。

可以在同一级别指定多个 proxy_ssl_conf_command 指令。当且仅当当前级别没有定义 proxy_ssl_conf_command 指令时,这些指令才从上一级配置继承。

#### WARNING
请注意,直接配置 OpenSSL 可能会导致意外行为。

<a id="index-21"></a>

<a id="s-proxy-ssl-crl"></a>

### proxy_ssl_crl

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_crl` file;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | —                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server          |

指定一个包含 PEM 格式吊销证书(CRL)的文件,用于 [验证](#s-proxy-ssl-verify) 代理服务器的证书。

<a id="index-22"></a>

<a id="s-proxy-ssl-name"></a>

### proxy_ssl_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_name` name;                |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `proxy_ssl_name` 来自 `proxy_pass` 的主机; |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                        |

允许覆盖用于 [验证](#s-proxy-ssl-verify) 代理服务器证书的服务器名称,以及在与代理服务器建立连接时 [通过 SNI 传递](#s-proxy-ssl-server-name) 的服务器名称。服务器名称也可以使用变量指定。

默认情况下,使用 [proxy_pass](#s-proxy-pass) 指令指定的地址中的主机名。

<a id="index-23"></a>

<a id="s-proxy-ssl-ntls"></a>

### proxy_ssl_ntls

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_ntls` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `proxy_ssl_ntls off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                   |

当使用 [TongSuo](https://github.com/Tongsuo-Project/Tongsuo) TLS 库时,启用客户端对 NTLS 的支持。

```nginx
server {
    proxy_ssl_ntls  on;

    proxy_ssl_certificate      sign.crt enc.crt;
    proxy_ssl_certificate_key  sign.key enc.key;

    proxy_ssl_ciphers "ECC-SM2-WITH-SM4-SM3:ECDHE-SM2-WITH-SM4-SM3:RSA";

    proxy_pass backend:12345;
}
```

#### NOTE
Angie 必须使用 `--with-ntls` 配置参数构建,并使用相应的支持 NTLS 的 SSL 库

```default
./configure --with-openssl=../Tongsuo-8.3.0 \
            --with-openssl-opt=enable-ntls  \
            --with-ntls
```

<a id="index-24"></a>

<a id="s-proxy-ssl-password-file"></a>

### proxy_ssl_password_file

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_password_file` file;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                    |

指定一个包含 [私钥](#s-proxy-ssl-certificate-key) 密码短语的文件,每个密码短语单独占一行。加载密钥时依次尝试这些密码短语。

<a id="index-25"></a>

<a id="s-proxy-ssl-protocols"></a>

### proxy_ssl_protocols

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_protocols` [`SSLv2`] [`SSLv3`] [`TLSv1`] [`TLSv1.1`] [`TLSv1.2`] [`TLSv1.3`];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------|
| 默认值                                                                                  | `proxy_ssl_protocols TLSv1.2 TLSv1.3;`                                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                                                             |

#### Versionchanged
在 1.2.0 版本发生变更: `TLSv1.3` 参数已添加到默认设置中。

为向代理服务器发送请求启用指定的协议。

<a id="index-26"></a>

<a id="s-proxy-ssl-server-name"></a>

### proxy_ssl_server_name

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_server_name` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | `proxy_ssl_server_name off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                          |

启用或禁用在与代理服务器建立连接时,通过
[服务器名称指示](http://en.wikipedia.org/wiki/Server_Name_Indication)
TLS 扩展
(SNI,
[RFC 6066](https://datatracker.ietf.org/doc/html/rfc6066.html))
传递由 [proxy_ssl_name](#s-proxy-ssl-name) 指令指定的服务器名称。

<a id="index-27"></a>

<a id="s-proxy-ssl-session-reuse"></a>

### proxy_ssl_session_reuse

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_session_reuse` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------------------|
| 默认值                                                                                  | `proxy_ssl_session_reuse on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                            |

决定在与代理服务器工作时是否可以重用 SSL 会话。如果日志中出现 "SSL3_GET_FINISHED:digest check failed" 错误,请尝试禁用会话重用。

<a id="index-28"></a>

<a id="s-proxy-ssl-trusted-certificate"></a>

### proxy_ssl_trusted_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_trusted_certificate` file;   |
|--------------------------------------------------------------------------------------|-----------------------------------------|
| 默认值                                                                                  | —                                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                          |

指定一个包含 PEM 格式受信任 CA 证书的文件,用于 [验证](#s-proxy-ssl-verify) 代理服务器的证书。

<a id="index-29"></a>

<a id="s-proxy-ssl-verify"></a>

### proxy_ssl_verify

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_verify` `on` | `off`;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `proxy_ssl_verify off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                     |

启用或禁用对代理服务器证书的验证。

<a id="index-30"></a>

<a id="s-proxy-ssl-verify-depth"></a>

### proxy_ssl_verify_depth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_ssl_verify_depth` number;   |
|--------------------------------------------------------------------------------------|------------------------------------|
| 默认值                                                                                  | `proxy_ssl_verify_depth 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                     |

设置代理服务器证书链中的验证深度。

<a id="index-31"></a>

<a id="s-proxy-timeout"></a>

### proxy_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_timeout` time;   |
|--------------------------------------------------------------------------------------|-------------------------|
| 默认值                                                                                  | `proxy_timeout 10m;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server          |

设置客户端或代理服务器连接上两次连续读或写操作之间的超时时间。如果在此时间内没有数据传输,连接将被关闭。

<a id="index-32"></a>

<a id="s-proxy-upload-rate"></a>

### proxy_upload_rate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `proxy_upload_rate` rate;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | `proxy_upload_rate 0;`      |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server              |

限制从客户端读取数据的速度。速率以每秒字节数指定。

| `0`   | 禁用速率限制   |
|-------|----------|

#### NOTE
该限制是针对每个连接设置的,因此如果客户端同时打开两个连接,总速率将是指定限制的两倍。

参数值可以包含变量。这在需要根据特定条件限制速率的情况下可能很有用:

```nginx
map $slow $rate {
    1     4k;
    2     8k;
}

proxy_upload_rate $rate;
```


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_rdp_preread.md

<!-- review: finished -->

<a id="stream-rdp-preread"></a>

# RDP Preread

在使用 RDP 协议时，此模块允许在做出负载均衡决策之前提取用于会话识别和管理的 Cookie。

当从源代码 [构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，需要通过 `‑‑with‑stream_rdp_preread_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 来启用此模块。在 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 中的包和镜像中，该模块已包含在构建中。

<a id="configuration-example-66"></a>

## 配置示例

<a id="binding-to-the-cookie-issuing-server"></a>

### 绑定到发放 Cookie 的服务器

这使用了 [sticky](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-sticky) 指令的 `learn` 模式：

```nginx
stream {

    rdp_preread on;

    upstream rdp {

        server 127.0.0.1:3390 sid=a;
        server 127.0.0.1:3391 sid=b;

        sticky learn lookup=$rdp_cookie create=$rdp_cookie zone=sessions:1m;
    }
}
```

<a id="directives-75"></a>

## 指令

<a id="index-0"></a>

<a id="s-rdp-preread"></a>

### rdp_preread

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `rdp_preread` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `rdp_preread off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                |

控制在 [预读阶段](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions) 从 RDP 协议 Cookie 中提取信息。
如果设置为 `on`，将在指定的上下文中填充下面列出的变量。

<a id="built-in-variables-21"></a>

## 内置变量

Cookie 值的语义取决于 RDP 协议版本。

<a id="v-rdp-cookie"></a>

### `$rdp_cookie`

整个 Cookie 值。

<a id="id5"></a>

### `$rdp_cookie_<name>`

具有指定名称的 Cookie 字段的值。


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_realip.md

<!-- review: finished -->

<a id="stream-realip"></a>

# RealIP

允许将客户端地址和端口更改为在 PROXY 协议头中传递的地址和端口。必须通过在 [listen](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-listen) 指令中设置 `proxy_protocol` 参数来预先启用 PROXY 协议。

当从源代码 [构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，默认情况下不会构建此模块；应使用 `‑‑with‑stream_realip_module` [构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 来启用它。

在 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 中的包和镜像中，该模块已包含在构建中。

<a id="configuration-example-67"></a>

## 配置示例

```nginx
listen 12345 proxy_protocol;

set_real_ip_from  192.168.1.0/24;
set_real_ip_from  192.168.2.1;
set_real_ip_from  2001:0db8::/32;
```

<a id="directives-76"></a>

## 指令

<a id="index-0"></a>

<a id="s-set-real-ip-from"></a>

### set_real_ip_from

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `set_real_ip_from` address | CIDR | `unix:`;   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | —                                              |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                 |

定义已知发送正确替换地址的可信地址。如果指定了特殊值 `unix:`，则所有 UNIX 域套接字将被信任。

<a id="built-in-variables-22"></a>

## 内置变量

<a id="v-s-realip-remote-addr"></a>

### `$realip_remote_addr`

保留原始客户端地址

<a id="v-s-realip-remote-port"></a>

### `$realip_remote_port`

保留原始客户端端口


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_return.md

<!-- review: finished -->

<a id="stream-return"></a>

# Return

该模块允许向客户端发送指定的值，然后关闭连接。

<a id="configuration-example-68"></a>

## 配置示例

```nginx
server {
    listen 12345;
    return $time_iso8601;
}
```

<a id="directives-77"></a>

## 指令

<a id="index-0"></a>

<a id="s-return"></a>

### return

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `return` value;   |
|--------------------------------------------------------------------------------------|-------------------|
| 默认值                                                                                  | —                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server            |

指定要发送给客户端的值。该值可以包含文本、变量及其组合。


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_set.md

<!-- review: finished -->

<a id="stream-set"></a>

# Set

该模块允许为变量设置一个值。

<a id="configuration-example-69"></a>

## 配置示例

```nginx
server {
    listen 12345;
    set    $true 1;
}
```

<a id="directives-78"></a>

## 指令

<a id="index-0"></a>

<a id="s-set"></a>

### set

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `set` $variable value;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认值                                                                                  | —                        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                   |

为指定的变量设置一个值。该值可以包含文本、变量及其组合。


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_split_clients.md

<!-- review: finished -->

<a id="stream-split-clients"></a>

# Split Clients

该模块生成用于 A/B 测试、金丝雀发布或其他需要将一定比例的客户端路由到一个服务器或配置的场景，同时将剩余部分引导到其他地方。

<a id="configuration-example-70"></a>

## 配置示例

```nginx
stream {
    # ...
    split_clients "${remote_addr}AAA" $upstream {
                  0.5%                feature_test1;
                  2.0%                feature_test2;
                  *                   production;
    }

    server {
        # ...
        proxy_pass $upstream;
    }
}
```

<a id="directives-79"></a>

## 指令

<a id="index-0"></a>

<a id="s-split-clients"></a>

### split_clients

| [Syntax](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `split_clients` string $variable { ... }   |
|------------------------------------------------------------------------------------------|--------------------------------------------|
| 默认值                                                                                      | —                                          |
| [Context](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                                     |

通过对 string 进行哈希来创建一个 $variable；
string 中的变量被替换，
结果被哈希，
然后哈希值用于选择 $variable 的字符串值。

哈希函数使用
[MurmurHash2](https://en.wikipedia.org/wiki/MurmurHash#MurmurHash2)
（32 位），
其整个值范围
（0 到 4294967295）
按出现顺序映射到桶；
百分比决定了桶的大小。
通配符 (`*`) 可以出现在最后；
不属于其他桶的哈希值会被映射到其分配的值。

示例：

```nginx
split_clients "${remote_addr}AAA" $variant {
               0.5%               .one;
               2.0%               .two;
               *                  "";
}
```

这里，在 `$*remote_addr*AAA` 字符串中替换变量后，
哈希值分布如下：

- 值为 0 到 21474835（0.5%）产生 `.one`
- 值为 21474836 到 107374180（2%）产生 `.two`
- 值为 107374181 到 4294967295（所有其他值）产生 `""`
  （一个空字符串）


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_ssl.md

<!-- review: finished -->

<a id="stream-ssl"></a>

# SSL

为流代理服务器提供使用 SSL/TLS 协议所需的支持。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时,
此模块默认不会被构建;
应该使用
`--with-stream_ssl_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 来启用它。

在来自 [我们仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的软件包和镜像中,
此模块已包含在构建中。

#### NOTE
此模块需要 OpenSSL 库。

<a id="configuration-example-71"></a>

## 配置示例

为了降低处理器负载,建议

* 将 [工作进程](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-processes) 数量设置为等于处理器数量,
* 启用 [共享](#s-ssl-session-cache) 会话缓存,
* 禁用 [内置](#s-ssl-session-cache) 会话缓存,
* 并可能增加会话 [生存时间](#s-ssl-session-timeout) (默认为 5 分钟):

```nginx
worker_processes auto;

stream {

    #...

    server {
        listen              12345 ssl;

        ssl_protocols       TLSv1.2 TLSv1.3;
        ssl_ciphers         AES128-SHA:AES256-SHA:RC4-SHA:DES-CBC3-SHA:RC4-MD5;
        ssl_certificate     /usr/local/angie/conf/cert.pem;
        ssl_certificate_key /usr/local/angie/conf/cert.key;
        ssl_session_cache   shared:SSL:10m;
        ssl_session_timeout 10m;

    #    ...
    }
```

<a id="directives-80"></a>

## 指令

<a id="index-0"></a>

<a id="s-ssl-alpn"></a>

### ssl_alpn

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_alpn` protocol ...;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | —                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server             |

指定支持的 [ALPN](https://datatracker.ietf.org/doc/html/rfc7301) 协议列表。如果客户端使用 ALPN,则必须 [协商](#v-s-ssl-alpn-protocol) 其中一个协议:

```nginx
map $ssl_alpn_protocol $proxy {
    h2                 127.0.0.1:8001;
    http/1.1           127.0.0.1:8002;
}

server {
    listen      12346;
    proxy_pass  $proxy;
    ssl_alpn    h2 http/1.1;
}
```

<a id="index-1"></a>

<a id="s-ssl-certificate"></a>

### ssl_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_certificate` file;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | —                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server            |

指定给定服务器的 PEM 格式证书文件。如果除了主证书外还需要指定中间证书,则应按以下顺序在同一文件中指定:主证书在前,然后是中间证书。PEM 格式的密钥也可以放在同一文件中。

此指令可以多次指定以加载不同类型的证书,例如 RSA 和 ECDSA:

```nginx
server {
    listen              12345 ssl;

    ssl_certificate     example.com.rsa.crt;
    ssl_certificate_key example.com.rsa.key;

    ssl_certificate     example.com.ecdsa.crt;
    ssl_certificate_key example.com.ecdsa.key;

#    ...
}
```

只有 OpenSSL 1.0.2 或更高版本支持不同证书的单独证书链。对于旧版本,只能使用一个证书链。

#### NOTE
使用 OpenSSL 1.0.2 或更高版本时,可以在文件名中使用变量:

```nginx
ssl_certificate     $ssl_server_name.crt;
ssl_certificate_key $ssl_server_name.key;
```

请注意,使用变量意味着每次 SSL 握手都会加载证书,这可能会对性能产生负面影响。

可以指定 `data:`$variable`` 值来代替 `file`,这将从变量加载证书而不使用中间文件。

请注意,不当使用此语法可能会带来安全隐患,例如将密钥数据写入 [错误日志](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log)。

<a id="index-2"></a>

<a id="s-ssl-certificate-compression"></a>

### ssl_certificate_compression

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_certificate_compression` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-----------------------------------------------|
| 默认值                                                                                  | `ssl_certificate_compression off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                |

启用 TLS 1.3 服务器证书 [压缩](https://datatracker.ietf.org/doc/html/rfc8879)。

#### NOTE
使用 OpenSSL 3.2 或更高版本时支持该指令;支持的压缩算法列表由库提供。

#### NOTE
使用 [BoringSSL](https://boringssl.googlesource.com/boringssl/) 时支持该指令;支持的压缩算法列表包括 `zlib`。

如果启用了 [ssl_stapling](#s-ssl-stapling),则证书压缩将被禁用。

<a id="index-3"></a>

<a id="s-ssl-certificate-key"></a>

### ssl_certificate_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_certificate_key` file;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | —                             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                |

指定给定服务器的 PEM 格式密钥文件。

#### NOTE
使用 OpenSSL 1.0.2 或更高版本时,可以在文件名中使用变量。

可以指定 `engine:`name`:id` 值来代替 `file`,这将从 OpenSSL 引擎 name 加载具有指定 id 的密钥。

可以指定 `store:scheme:id` 值来代替 `file`,这用于从具有指定 id 和 OpenSSL 提供程序注册的 URI scheme 加载密钥,例如 [pkcs11](https://datatracker.ietf.org/doc/html/rfc7512)。

可以指定 `data:`$variable`` 值来代替 `file`,这将从变量加载密钥而不使用中间文件。请注意,不当使用此语法可能会带来安全隐患,例如将密钥数据写入 [错误日志](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log)。

<a id="index-4"></a>

<a id="s-ssl-ciphers"></a>

### ssl_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ciphers` ciphers;          |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `ssl_ciphers HIGH:!aNULL:!MD5;` |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                  |

指定启用的密码套件。密码套件以 OpenSSL 库理解的格式指定,例如:

```nginx
ssl_ciphers ALL:!aNULL:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
```

密码套件列表取决于已安装的 OpenSSL 版本。
可以使用 `openssl ciphers` 命令查看完整列表。

#### WARNING
使用 OpenSSL 时,:samp:ssl_ciphers 指令  *不会* 配置 TLS
1.3 的密码套件。要使用 OpenSSL 配置 TLS 1.3 密码套件,请使用
[ssl_conf_command](#s-ssl-conf-command) 指令,该指令专门用于支持高级
SSL 配置。

- 在 LibreSSL 中,\*可以\* 使用 `ssl_ciphers` 配置 TLS 1.3 密码套件。
- 在 BoringSSL 中,根本无法配置 TLS 1.3 密码套件。

<a id="index-5"></a>

<a id="s-ssl-client-certificate"></a>

### ssl_client_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_client_certificate` file;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                   |

指定一个包含 PEM 格式受信任 CA 证书的文件,用于 [验证](#s-ssl-verify-client) 客户端证书,以及在启用 [ssl_stapling](#s-ssl-stapling) 时验证 OCSP 响应。

证书列表将发送给客户端。如果不希望这样,可以使用 [ssl_trusted_certificate](#s-ssl-trusted-certificate) 指令。

<a id="index-6"></a>

<a id="s-ssl-conf-command"></a>

### ssl_conf_command

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_conf_command` name value;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                   |

设置任意 OpenSSL 配置 [命令](https://docs.openssl.org/master/man3/SSL_CONF_cmd/)。

#### NOTE
使用 OpenSSL 1.0.2 或更高版本时支持该指令。
要使用 OpenSSL 配置 TLS 1.3 密码套件,请使用 `ciphersuites` 命令。

可以在同一级别指定多个 ssl_conf_command 指令:

```nginx
ssl_conf_command Options PrioritizeChaCha;
ssl_conf_command Ciphersuites TLS_CHACHA20_POLY1305_SHA256;
```

仅当当前级别没有定义 ssl_conf_command 指令时,才会从上一级配置继承这些指令。

#### WARNING
直接配置 OpenSSL 可能导致意外行为。

<a id="index-7"></a>

<a id="s-ssl-crl"></a>

### ssl_crl

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_crl` file;   |
|--------------------------------------------------------------------------------------|-------------------|
| 默认值                                                                                  | —                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server    |

指定一个包含 PEM 格式吊销证书 (CRL) 的文件,用于 [验证](#s-ssl-verify-client) 客户端证书。

<a id="index-8"></a>

<a id="s-ssl-dhparam"></a>

### ssl_dhparam

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_dhparam` file;   |
|--------------------------------------------------------------------------------------|-----------------------|
| 默认值                                                                                  | —                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server        |

指定用于 DHE 密码套件的 DH 参数文件。

#### WARNING
默认情况下不设置任何参数,因此不会使用 DHE 密码套件。

<a id="index-9"></a>

<a id="s-ssl-early-data"></a>

### ssl_early_data

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_early_data` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `ssl_early_data off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                   |

启用或禁用 TLS 1.3 [早期数据](https://datatracker.ietf.org/doc/html/rfc8446#section-2.3)。

#### NOTE
使用 OpenSSL 1.1.1 或更高版本或 [BoringSSL](https://boringssl.googlesource.com/boringssl/) 时支持该指令。

<a id="index-10"></a>

<a id="s-ssl-encrypted-hello-key"></a>

### ssl_encrypted_hello_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_encrypted_hello_key` file;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                    |

指定包含 PEM 格式 ECH 私钥和 ECHConfigList 的文件。
该指令可以多次指定。
需要支持加密客户端问候 (ECH) 的 OpenSSL 或 BoringSSL 构建;否则不支持。

<a id="index-11"></a>

<a id="s-ssl-ecdh-curve"></a>

### ssl_ecdh_curve

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ecdh_curve` curve;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | `ssl_ecdh_curve auto;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server            |

指定用于 ECDHE 密码套件的曲线。

#### NOTE
使用 OpenSSL 1.0.2 或更高版本时,可以指定多条曲线,例如:

```nginx
ssl_ecdh_curve prime256v1:secp384r1;
```

特殊值 `auto` 指示 Angie 在使用 OpenSSL 1.0.2 或更高版本时使用 OpenSSL 库内置的列表,或在旧版本中使用 prime256v1。

#### NOTE
使用 OpenSSL 1.0.2 或更高版本时,此指令设置服务器支持的曲线列表。因此,为了使 ECDSA 证书正常工作,重要的是在证书中包含使用的曲线。

<a id="index-12"></a>

<a id="s-ssl-handshake-timeout"></a>

### ssl_handshake_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_handshake_timeout` time;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `ssl_handshake_timeout 60s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                  |

指定 SSL 握手完成的超时时间。

<a id="index-13"></a>

<a id="s-ssl-ocsp"></a>

### ssl_ocsp

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ocsp` `on` | `off` | `leaf`;   |
|--------------------------------------------------------------------------------------|-------------------------------------|
| 默认值                                                                                  | `ssl_ocsp off;`                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                      |

启用客户端证书链的 OCSP 验证。`leaf` 参数仅启用客户端证书的验证。

要使 OCSP 验证正常工作,:ref:s_ssl_verify_client 指令应设置为 `on` 或 `optional`。

要解析 OCSP 响应器主机名,还应指定 [resolver](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-resolver) 指令。

示例:

```nginx
ssl_verify_client on;
ssl_ocsp          on;
resolver          127.0.0.53;
```

<a id="index-14"></a>

<a id="s-ssl-ocsp-cache"></a>

### ssl_ocsp_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ocsp_cache` `off` | [shared:name:size];   |
|--------------------------------------------------------------------------------------|------------------------------------------------|
| 默认值                                                                                  | `ssl_ocsp_cache off;`                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                 |

设置用于存储 OCSP 验证客户端证书状态的缓存的名称和大小。缓存在所有工作进程之间共享。具有相同名称的缓存可以在多个虚拟服务器中使用。

`off` 参数禁止使用缓存。

<a id="index-15"></a>

<a id="s-ssl-ocsp-responder"></a>

### ssl_ocsp_responder

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ocsp_responder` uri;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server              |

覆盖证书扩展 ["Authority Information Access"](https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.2.1) 中指定的 OCSP 响应器 URI,用于客户端证书的 [验证](#s-ssl-ocsp)。

仅支持 `http://` OCSP 响应器:

```nginx
ssl_ocsp_responder http://ocsp.example.com/;
```

<a id="index-16"></a>

<a id="s-ssl-ntls"></a>

### ssl_ntls

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_ntls` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------|
| 默认值                                                                                  | `ssl_ntls off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server             |

使用 [TongSuo](https://github.com/Tongsuo-Project/Tongsuo) 库启用服务器端 NTLS 支持。

```nginx
listen ... ssl;
ssl_ntls  on;
```

#### NOTE
Angie 必须使用 `--with-ntls` 构建选项进行构建,并链接到启用 NTLS 的 SSL 库

```default
./configure --with-openssl=../Tongsuo-8.3.0 \
            --with-openssl-opt=enable-ntls  \
            --with-ntls
```

<a id="index-17"></a>

<a id="s-ssl-password-file"></a>

### ssl_password_file

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_password_file` file;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server              |

指定包含 [密钥](#s-ssl-certificate-key) 密码短语的文件,其中每个密码短语单独占一行。加载密钥时依次尝试这些密码短语。

示例:

```nginx
stream {
    ssl_password_file /etc/keys/global.pass;
    ...

    server {
        listen 127.0.0.1:12345;
        ssl_certificate_key /etc/keys/first.key;
    }

    server {
        listen 127.0.0.1:12346;

        # 命名管道也可以用来代替文件
        ssl_password_file /etc/keys/fifo;
        ssl_certificate_key /etc/keys/second.key;
    }
}
```

<a id="index-18"></a>

<a id="s-ssl-prefer-server-ciphers"></a>

### ssl_prefer_server_ciphers

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_prefer_server_ciphers` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------|
| 默认值                                                                                  | `ssl_prefer_server_ciphers off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                              |

指定在使用 SSLv3 和 TLS 协议时,服务器密码套件应优先于客户端密码套件。

<a id="index-19"></a>

<a id="s-ssl-protocols"></a>

### ssl_protocols

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_protocols` [`SSLv2`] [`SSLv3`] [`TLSv1`] [`TLSv1.1`] [`TLSv1.2`] [`TLSv1.3`];   |
|--------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|
| 默认值                                                                                  | `ssl_protocols TLSv1.2 TLSv1.3;`                                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                                                       |

#### Versionchanged
在 1.2.0 版本发生变更: `TLSv1.3` 参数已添加到默认集合。

启用指定的协议。

#### NOTE
TLSv1.1 和 TLSv1.2 参数仅在使用 OpenSSL 1.0.1 或更高版本时有效。

TLSv1.3 参数仅在使用 OpenSSL 1.1.1 或更高版本时有效。

<a id="index-20"></a>

<a id="s-ssl-session-cache"></a>

### ssl_session_cache

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_cache` `off` | `none` | [builtin[:size]] [shared:name:size];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| 默认值                                                                                  | `ssl_session_cache none;`                                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                                              |

设置存储会话参数的缓存类型和大小。缓存可以是以下任意类型:

| `off`     | 严格禁止使用会话缓存:Angie 明确告知客户端会话不能被重用。                                                                                                                                               |
|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `none`    | 温和地禁止使用会话缓存:Angie 告知客户端会话可以被重用,但实际上不在缓存中存储会话参数。                                                                                                                                |
| `builtin` | OpenSSL 内置缓存;仅由一个工作进程使用。缓存大小以会话数指定。如果未给出大小,则等于 20480 个会话。使用内置缓存可能导致内存碎片。                                                                                                       |
| `shared`  | 在所有工作进程之间共享的缓存。缓存大小以字节为单位指定;一兆字节可以存储约 4000 个会话。每个共享缓存应具有任意名称。具有相同名称的缓存可以在多个服务器中使用。它还用于自动生成、存储和定期轮换 TLS 会话票证密钥,除非使用 [ssl_session_ticket_key](#s-ssl-session-ticket-key) 指令显式配置。 |

两种缓存类型可以同时使用,例如:

```nginx
ssl_session_cache builtin:1000 shared:SSL:10m;
```

但仅使用共享缓存而不使用内置缓存应该更高效。

<a id="index-21"></a>

<a id="s-ssl-session-ticket-key"></a>

### ssl_session_ticket_key

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_ticket_key` file;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                   |

设置包含用于加密和解密 TLS 会话票证的密钥的文件。如果必须在多个服务器之间共享相同的密钥,则此指令是必需的。默认情况下,使用随机生成的密钥。

如果指定了多个密钥,则仅使用第一个密钥来加密 TLS 会话票证。这允许配置密钥轮换,例如:

```nginx
ssl_session_ticket_key current.key;
ssl_session_ticket_key previous.key;
```

该文件必须包含 80 或 48 字节的随机数据,可以使用以下命令创建:

```console
openssl rand 80 > ticket.key
```

根据文件大小,将使用 AES256(用于 80 字节密钥)或 AES128(用于 48 字节密钥)进行加密。

<a id="index-22"></a>

<a id="s-ssl-session-tickets"></a>

### ssl_session_tickets

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_tickets` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `ssl_session_tickets on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                        |

启用或禁用通过 [TLS 会话票证](https://datatracker.ietf.org/doc/html/rfc5077) 进行会话恢复。

<a id="index-23"></a>

<a id="s-ssl-session-timeout"></a>

### ssl_session_timeout

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_session_timeout` time;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `ssl_session_timeout 5m;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                |

指定客户端可以重用会话参数的时间。

<a id="index-24"></a>

<a id="s-ssl-stapling"></a>

### ssl_stapling

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_stapling` `on` | `off`;   |
|--------------------------------------------------------------------------------------|--------------------------------|
| 默认值                                                                                  | `ssl_stapling off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                   |

启用或禁用服务器 [装订 OCSP 响应](https://datatracker.ietf.org/doc/html/rfc6066#section-8)。
示例:

```nginx
ssl_stapling on;
resolver 127.0.0.53;
```

要使 OCSP 装订正常工作,应该知道服务器证书颁发者的证书。
如果 [ssl_certificate](#s-ssl-certificate) 文件不包含中间证书,
则服务器证书颁发者的证书应该存在于 [ssl_trusted_certificate](#s-ssl-trusted-certificate) 文件中。

#### WARNING
为了解析 OCSP 响应器主机名,还应该指定 [resolver](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-resolver) 指令。

<a id="index-25"></a>

<a id="s-ssl-stapling-file"></a>

### ssl_stapling_file

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_stapling_file` file;   |
|--------------------------------------------------------------------------------------|-----------------------------|
| 默认值                                                                                  | —                           |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                |

设置后,装订的 OCSP 响应将从指定的文件中获取,
而不是查询服务器证书中指定的 OCSP 响应器。

该文件应该是 DER 格式,由 `openssl ocsp` 命令生成。

<a id="index-26"></a>

<a id="s-ssl-stapling-responder"></a>

### ssl_stapling_responder

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_stapling_responder` uri;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | —                               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                    |

覆盖证书扩展 ["Authority Information Access"](https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.2.1) 中指定的 OCSP 响应器的 URI。

仅支持 `http://` OCSP 响应器:

```nginx
ssl_stapling_responder http://ocsp.example.com/;
```

<a id="index-27"></a>

<a id="s-ssl-stapling-verify"></a>

### ssl_stapling_verify

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_stapling_verify` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | `ssl_stapling_verify off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | http, server                          |

启用或禁用服务器对 OCSP 响应的验证。

要使验证正常工作,应该使用 [ssl_trusted_certificate](#s-ssl-trusted-certificate) 指令将服务器证书颁发者的证书、根证书和所有中间证书配置为受信任的证书。

<a id="index-28"></a>

<a id="s-ssl-trusted-certificate"></a>

### ssl_trusted_certificate

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_trusted_certificate` file;   |
|--------------------------------------------------------------------------------------|-----------------------------------|
| 默认值                                                                                  | —                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                    |

指定一个包含 PEM 格式受信任 CA 证书的文件,用于 [验证](#s-ssl-verify-client) 客户端证书。

与 [ssl_client_certificate](#s-ssl-client-certificate) 设置的证书集不同,这些证书列表不会发送给客户端。

<a id="index-29"></a>

<a id="s-ssl-verify-client"></a>

### ssl_verify_client

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_verify_client` `on` | `off` | `optional` | `optional_no_ca`;   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------|
| 默认值                                                                                  | `ssl_verify_client off;`                                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                                                      |

启用客户端证书验证。验证结果存储在 [$ssl_client_verify](#v-s-ssl-client-verify) 变量中。如果在客户端证书验证期间发生错误,或者客户端未提供所需的证书,则连接将被关闭。

| `optional`       | 请求客户端证书,如果证书存在则进行验证。                                     |
|------------------|----------------------------------------------------------|
| `optional_no_ca` | 请求客户端证书,但不要求其由受信任的 CA 证书签名。这适用于由 Angie 外部的服务执行实际证书验证的情况。 |

<a id="index-30"></a>

<a id="s-ssl-verify-depth"></a>

### ssl_verify_depth

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_verify_depth` number;   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | `ssl_verify_depth 1;`        |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server               |

设置客户端证书链中的验证深度。

<a id="built-in-variables-23"></a>

## 内置变量

`stream_ssl` 模块支持以下变量:

<a id="v-s-ssl-alpn-protocol"></a>

### `$ssl_alpn_protocol`

返回在 SSL 握手期间通过 ALPN 选择的协议,否则返回空字符串。

<a id="v-s-ssl-cipher"></a>

### `$ssl_cipher`

返回已建立的 SSL 连接所使用的加密套件名称。

<a id="v-s-ssl-ciphers"></a>

### `$ssl_ciphers`

返回客户端支持的加密套件列表。已知的加密套件以名称列出,未知的以十六进制显示,例如:

> AES128-SHA:AES256-SHA:0x00ff

#### NOTE
仅在使用 OpenSSL 1.0.2 或更高版本时完全支持该变量。对于旧版本,该变量仅适用于新会话,并且仅列出已知的加密套件。

<a id="v-s-ssl-client-cert"></a>

### `$ssl_client_cert`

返回已建立的 SSL 连接的客户端证书(PEM 格式),除第一行外的每一行都以制表符开头。

<a id="v-s-ssl-client-fingerprint"></a>

### `$ssl_client_fingerprint`

返回已建立的 SSL 连接的客户端证书的 SHA1 指纹。

<a id="v-s-ssl-client-i-dn"></a>

### `$ssl_client_i_dn`

根据 [RFC 2253](https://datatracker.ietf.org/doc/html/rfc2253) 返回已建立的 SSL 连接的客户端证书的"颁发者 DN"字符串。

<a id="v-s-ssl-client-raw-cert"></a>

### `$ssl_client_raw_cert`

返回已建立的 SSL 连接的客户端证书(PEM 格式)。

<a id="v-s-ssl-client-s-dn"></a>

### `$ssl_client_s_dn`

根据 [RFC 2253](https://datatracker.ietf.org/doc/html/rfc2253) 返回已建立的 SSL 连接的客户端证书的"主题 DN"字符串。

<a id="v-s-ssl-client-serial"></a>

### `$ssl_client_serial`

返回已建立的 SSL 连接的客户端证书的序列号。

<a id="v-s-ssl-client-sigalg"></a>

### `$ssl_client_sigalg`

返回已建立的 SSL 连接的客户端证书的 [签名算法](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-16)。

#### NOTE
仅在使用 OpenSSL 3.5 或更高版本时支持该变量。对于旧版本,该变量值将为空字符串。

#### NOTE
该变量仅适用于新会话。

<a id="v-s-ssl-client-v-end"></a>

### `$ssl_client_v_end`

返回客户端证书的结束日期。

<a id="v-s-ssl-client-v-remain"></a>

### `$ssl_client_v_remain`

返回客户端证书到期前的剩余天数。

<a id="v-s-ssl-client-v-start"></a>

### `$ssl_client_v_start`

返回客户端证书的起始日期。

<a id="v-s-ssl-client-verify"></a>

### `$ssl_client_verify`

返回客户端证书验证的结果:`SUCCESS`、`FAILED:reason`,如果证书不存在则返回 `NONE`。

<a id="v-s-ssl-curve"></a>

### `$ssl_curve`

返回 SSL 握手密钥交换过程中协商使用的曲线。已知的曲线以名称列出,未知的以十六进制显示,例如:

> prime256v1

#### NOTE
仅在使用 OpenSSL 3.0 或更高版本时支持该变量。对于旧版本,该变量值将为空字符串。

<a id="v-s-ssl-curves"></a>

### `$ssl_curves`

返回客户端支持的曲线列表。已知的曲线以名称列出,未知的以十六进制显示,例如:

> 0x001d:prime256v1:secp521r1:secp384r1

#### NOTE
仅在使用 OpenSSL 1.0.2 或更高版本时支持该变量。对于旧版本,该变量值将为空字符串。

该变量仅适用于新会话。

<a id="v-s-ssl-early-data"></a>

### `$ssl_early_data`

如果使用了 TLS 1.3 [早期数据](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#ssl-early-data) 且握手未完成,则返回 "1",否则返回 ""。

<a id="v-s-ssl-encrypted-hello"></a>

### `$ssl_encrypted_hello`

如果使用了加密客户端问候(ECH),则返回 "1",否则返回 ""。

<a id="v-s-ssl-protocol"></a>

### `$ssl_protocol`

返回已建立的 SSL 连接的协议。

<a id="v-s-ssl-server-cert-type"></a>

### `$ssl_server_cert_type`

根据服务器证书和密钥的类型,取值为 `RSA`、`DSA`、`ECDSA`、`ED448`、
`ED25519`、`SM2`、`RSA-PSS` 或 `unknown`。

<a id="v-s-ssl-server-name"></a>

### `$ssl_server_name`

返回通过 [SNI](http://en.wikipedia.org/wiki/Server_Name_Indication) 请求的服务器名称。

<a id="v-s-ssl-session-id"></a>

### `$ssl_session_id`

返回已建立的 SSL 连接的会话标识符。

<a id="v-s-ssl-session-reused"></a>

### `$ssl_session_reused`

如果 SSL 会话被重用则返回 "r",否则返回 "."。

<a id="v-s-ssl-sigalg"></a>

### `$ssl_sigalg`

返回已建立的 SSL 连接的服务器证书的 [签名算法](https://www.iana.org/assignments/tls-parameters/tls-parameters.xhtml#tls-parameters-16)。

#### NOTE
仅在使用 OpenSSL 3.5 或更高版本时支持该变量。对于旧版本,该变量值将为空字符串。

#### NOTE
该变量仅适用于新会话。


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_ssl_preread.md

<!-- review: finished -->

<a id="stream-ssl-preread"></a>

# SSL Preread

启用从
[ClientHello](https://datatracker.ietf.org/doc/html/rfc5246#section-7.4.1.2)
消息中提取信息而不终止 TLS，
例如通过 [SNI](https://datatracker.ietf.org/doc/html/rfc6066#section-3)
请求的服务器名称或在
[ALPN](https://datatracker.ietf.org/doc/html/rfc7301)
中广告的协议。

当 [从源代码构建](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 时，
默认情况下不会构建此模块；
它应该通过
`‑‑with‑stream_ssl_preread_module`
[构建选项](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure) 启用。

在来自 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 的包和镜像中，
该模块已包含在构建中。

<a id="configuration-example-72"></a>

## 配置示例

<a id="selecting-an-upstream-by-server-name"></a>

### 通过服务器名称选择上游

```nginx
map $ssl_preread_server_name $name {
    backend.example.com      backend;
    default                  backend2;
}

upstream backend {
    server 192.168.0.1:12345;
    server 192.168.0.2:12345;
}

upstream backend2 {
    server 192.168.0.3:12345;
    server 192.168.0.4:12345;
}

server {
    listen      12346;
    proxy_pass  $name;
    ssl_preread on;
}
```

<a id="selecting-a-server-by-protocol"></a>

### 通过协议选择服务器

```nginx
map $ssl_preread_alpn_protocols $proxy {
    ~\bh2\b           127.0.0.1:8001;
    ~\bhttp/1.1\b     127.0.0.1:8002;
    ~\bxmpp-client\b  127.0.0.1:8003;
}

server {
    listen      9000;
    proxy_pass  $proxy;
    ssl_preread on;
}
```

<a id="selecting-a-server-by-ssl-protocol-version"></a>

### 通过 SSL 协议版本选择服务器

```nginx
map $ssl_preread_protocol $upstream {
    ""        ssh.example.com:22;
    "TLSv1.2" new.example.com:443;
    default   tls.example.com:443;
}

# ssh 和 https 在同一端口
server {
    listen      192.168.0.1:443;
    proxy_pass  $upstream;
    ssl_preread on;
}
```

<a id="directives-81"></a>

## 指令

<a id="index-0"></a>

<a id="s-ssl-preread"></a>

### ssl_preread

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `ssl_preread` `on` | `off`;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认                                                                                   | `ssl_preread off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream, server                |

在 [预读取](https://cn.angie.software//angie/docs/configuration/processing.md#stream-sessions) 阶段启用从 ClientHello 消息中提取信息。

<a id="built-in-variables-24"></a>

## 内置变量

<a id="v-ssl-preread-protocol"></a>

### `$ssl_preread_protocol`

客户端支持的最高 SSL 协议版本。

<a id="v-ssl-preread-server-name"></a>

### `$ssl_preread_server_name`

通过 SNI 请求的服务器名称。

<a id="v-ssl-preread-alpn-protocols"></a>

### `$ssl_preread_alpn_protocols`

客户端通过 ALPN 广告的协议列表。
这些值用逗号分隔。


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_upstream.md

<!-- review: finished -->

<a id="stream-upstream"></a>

# Upstream

提供用于描述服务器组的上下文,可在 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#s-proxy-pass) 指令中使用。

<a id="configuration-example-73"></a>

## 配置示例

```nginx
upstream backend {
    hash $remote_addr consistent;
    zone backend 1m;

    server backend1.example.com:1935  weight=5;
    server unix:/tmp/backend3;
    server backend3.example.com       service=_example._tcp resolve;

    server backup1.example.com:1935   backup;
    server backup2.example.com:1935   backup;
}

resolver 127.0.0.53 status_zone=resolver;

server {
    listen 1936;
    proxy_pass backend;
}
```

<a id="directives-82"></a>

## 指令

<a id="index-0"></a>

<a id="s-u-upstream"></a>

### upstream

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `upstream` name { ... }   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | —                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | stream                    |

描述一个服务器组。服务器可以监听不同的端口。此外,监听 TCP 和 UNIX 域套接字的服务器可以混合使用。

示例:

```nginx
upstream backend {
    server backend1.example.com:1935 weight=5;
    server 127.0.0.1:1935            max_fails=3 fail_timeout=30s;
    server unix:/tmp/backend2;
    server backend3.example.com:1935 resolve;

    server backup1.example.com:1935  backup;
}
```

<a id="s-round-robin"></a>

默认情况下,连接使用加权轮询均衡方法在服务器之间分配。在上面的示例中,每 7 个连接将按如下方式分配:5 个连接到 backend1.example.com:1935,第二个和第三个服务器各 1 个连接。

如果在与服务器通信期间发生错误,连接将传递给下一个服务器,依此类推,直到尝试所有正常工作的服务器。如果与所有服务器的通信都失败,连接将被关闭。

<a id="index-1"></a>

<a id="s-u-server"></a>

### server

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `server` address [parameters];   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | —                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                         |

定义服务器的地址和其他参数。地址可以指定为域名或带有必需端口的 IP 地址,或者指定为 `unix:` 前缀后的 UNIX 域套接字路径。解析为多个 IP 地址的域名会一次定义多个服务器。

可以定义以下参数:

| `weight=`number    | 设置服务器的权重;默认为 1。                                                                |
|--------------------|--------------------------------------------------------------------------------|
| `max_conns=`number | 限制到代理服务器的最大同时活动连接数。默认值为 `0`,表示没有限制。如果服务器组不在 [共享内存](#s-u-zone) 中,则该限制对每个工作进程生效。 |

<a id="s-max-fails"></a>

`max_fails=`number — 设置在 [fail_timeout](#s-fail-timeout) 设置的持续时间内
与服务器通信的失败尝试次数,
达到该次数后将服务器视为不可用;
然后在相同的持续时间后重试。

这里,失败尝试是指与服务器建立连接时的错误或超时。

#### NOTE
如果组中的 `server` 指令解析为多个服务器,
其 `max_fails` 设置将单独应用于每个服务器。

如果在解析所有 `server` 指令后,upstream 只包含一个服务器,
则 `max_fails` 设置无效并将被忽略。

| `max_fails=1`   | 默认尝试次数。   |
|-----------------|-----------|
| `max_fails=0`   | 禁用尝试次数统计。 |

<a id="s-fail-timeout"></a>

`fail_timeout=`time — 设置时间段,在此期间应发生指定次数的
与服务器通信失败尝试([max_fails](#s-max-fails))才将服务器视为不可用。
然后服务器在相同的时间段内保持不可用状态,
之后才会重试。

默认情况下,此值设置为 10 秒。

#### NOTE
如果组中的 `server` 指令解析为多个服务器,
其 `fail_timeout` 设置将单独应用于每个服务器。

如果在解析所有 `server` 指令后,upstream 只包含一个服务器,
则 `fail_timeout` 设置无效并将被忽略。

| `backup`      | 将服务器标记为备份服务器。当主服务器不可用时,它将接收请求。                                                       |
|---------------|--------------------------------------------------------------------------------------|
| `down`        | 将服务器标记为永久不可用。                                                                        |
| `drain` (PRO) | 将服务器标记为排空状态;这意味着<br/>它只接收来自之前通过 [sticky](#s-u-sticky) 绑定的会话的请求。<br/>否则其行为类似于 `down`。 |

#### WARNING
`backup` 参数不能与 [hash](#s-u-hash) 和 [random](#s-u-random) 负载均衡方法一起使用。

`down` 和 `drain` 参数互斥。

<a id="s-reresolve"></a>

| `resolve`      | 启用监控与域名对应的 IP 地址列表的变化,<br/>无需重新加载配置即可更新。<br/>该组必须位于<br/>[共享内存区域](#s-u-zone) 中;<br/>还必须定义 [resolver](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#s-resolver)。                                                                                                                                                                                                                                                                                                                                     |
|----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `service=`name | 启用解析 DNS SRV 记录并设置服务名称。<br/>要使此参数生效,还必须指定 resolve 参数,<br/>且不在主机名中指定服务器端口。<br/><br/>如果服务名称中没有点,<br/>则根据 RFC 标准形成名称:<br/>服务名称前加 `_` 前缀,<br/>然后在点后添加 `_tcp`。<br/>因此,服务名称 `http` 将变成 `_http._tcp`。<br/><br/>Angie 通过组合规范化的服务名称和主机名来解析 SRV 记录,<br/>并通过 DNS 获取该组合的服务器列表,<br/>以及它们的优先级和权重。<br/><br/>- 最高优先级的 SRV 记录<br/>  (共享最小优先级值的记录)<br/>  解析为主服务器,<br/>  其他记录成为备份服务器。<br/>  如果 `server` 设置了 `backup`,<br/>  最高优先级的 SRV 记录解析为备份服务器,<br/>  其他记录被忽略。<br/>- 权重类似于 `server` 指令的 `weight` 参数。<br/>  如果指令和 SRV 记录都设置了权重,<br/>  则使用指令设置的权重。 |

此示例将查找 `_http._tcp.backend.example.com` 记录:

```nginx
server backend.example.com service=http resolve;
```

| `sid=`id   | 设置组中的服务器 ID。如果未指定该参数,<br/>ID 将设置为 IP 地址和端口或 UNIX 域套接字路径的<br/>十六进制 MD5 哈希值。   |
|------------|------------------------------------------------------------------------------|

<a id="s-slow-start"></a>

| `slow_start=`time   | 设置服务器在恢复服务时，<br/>使用 [轮询](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#round-robin) 或 [least_conn](#s-u-least-conn)<br/>负载均衡方法恢复其权重的 [时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)。<br/><br/>如果设置了该参数，<br/>并且服务器在根据 [max_fails](#s-max-fails) 和 [upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#s-u-upstream-probe) 判定失败后再次被认为健康，<br/>服务器将在指定的时间段内逐渐恢复其指定的权重。<br/><br/>如果未设置该参数，<br/>在类似情况下，<br/>服务器将立即以其指定的权重开始工作。   |
|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

#### NOTE
如果 upstream 中只指定了一个 `server`，
`slow_start` 将不起作用并被忽略。

<a id="index-2"></a>

<a id="s-u-state"></a>

### state (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `state` file;   |
|--------------------------------------------------------------------------------------|-----------------|
| 默认值                                                                                  | —               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream        |

指定持久化存储上游服务器列表的 file。
从 [我们的软件包](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 安装时，
会创建一个具有适当权限的专用目录
`/var/lib/angie/state/` （FreeBSD 上为 `/var/db/angie/state/`）
用于存储此类文件，
因此您只需在配置中添加文件名：

```nginx
upstream backend {

    zone backend 1m;
    state /var/lib/angie/state/<文件名>;
}
```

这里的服务器列表格式类似于 `server`。
每当通过配置 API 在
[/config/stream/upstreams/](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-config-stream-upstreams-servers) 部分
修改服务器时，文件内容都会更改。
该文件在 Angie 启动或配置重载时读取。

#### WARNING
要在 `upstream` 块中使用 `state` 指令，
其中不应有 `server` 指令，
但需要共享内存区（[zone](#s-u-zone)）。

<a id="index-3"></a>

<a id="s-u-zone"></a>

### zone

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `zone` name [size];   |
|--------------------------------------------------------------------------------------|-----------------------|
| 默认值                                                                                  | —                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream              |

定义共享内存区的名称和大小，该内存区存储组的配置和运行时状态，在工作进程之间共享。多个组可以使用同一个区。在这种情况下，只需指定一次大小即可。

#### NOTE
只有在配置的 `size` 不变时，重载才会保留区域内容。
任何大小变更——增大或减小——都会导致区域被重新创建为空。

<a id="index-4"></a>

<a id="s-u-backup-switch"></a>

### backup_switch (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `backup_switch` `permanent`[=time];   |
|--------------------------------------------------------------------------------------|---------------------------------------|
| 默认值                                                                                  | —                                     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                              |

该指令启用从  *活动* 组而不是主组开始服务器选择的能力，
即从之前成功找到服务器的组开始。
如果在活动组中无法为下一个请求找到服务器，
并且搜索移至备份组，
该备份组将成为活动组，
后续请求将首先定向到该组中的服务器。

如果定义了 `permanent` 参数但没有 [时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax) 值，
该组在选择后保持活动状态，
不会自动重新检查优先级较低的组。
如果指定了 time，
组的活动状态在指定的时间间隔后过期，
负载均衡器将再次检查优先级较低的组，
如果服务器正常工作则返回到这些组。

示例：

```nginx
upstream media_backend {
    server primary1.example.com:1935;
    server primary2.example.com:1935;

    server reserve1.example.com:1935 backup;
    server reserve2.example.com:1935 backup;

    backup_switch permanent=2m;
}
```

如果负载均衡器从主服务器切换到备份组，
所有后续请求将由该备份组处理 2 分钟。
2 分钟过期后，负载均衡器重新检查主服务器，
如果它们正常工作，则再次使其成为活动组。

<a id="index-5"></a>

<a id="s-u-feedback"></a>

### feedback (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `feedback` variable [`inverse`] [`factor=`number] [`account=`condition_variable];   |
|--------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                                                                            |

为 `upstream` 启用基于反馈的负载均衡机制。
它通过将每个代理服务器的权重乘以平均反馈值来动态调整负载均衡决策，
该值根据 variable 值随时间变化，
并受可选条件约束。

可以指定以下参数：

| variable   | 从中获取反馈值的变量。<br/>它应该表示性能或健康指标；<br/>假定由服务器提供。<br/><br/>该值在服务器的每个响应中进行评估，<br/>并根据 `inverse` 和 `factor` 设置<br/>纳入移动平均值。                                                                                                                                                                                                                                                                                                                      |
|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `inverse`  | 如果设置了该参数，反馈值将被反向解释：<br/>较低的值表示更好的性能。                                                                                                                                                                                                                                                                                                                                                                                                     |
| `factor`   | 计算平均值时反馈值的加权因子。<br/>有效值为 0 到 99 的整数。<br/>默认值为 `90`。<br/><br/>平均值使用 [指数平滑](https://en.wikipedia.org/wiki/Exponential_smoothing) 公式计算。<br/><br/>因子越大，新值对平均值的影响越小；<br/>如果指定 `90`，将取 90% 的先前值<br/>和仅 10% 的新值。                                                                                                                                                                                                                                |
| `account`  | 指定一个条件变量，<br/>用于控制如何在计算中统计连接。<br/>仅当条件变量<br/>不等于 `""` 或 `"0"` 时，<br/>才使用反馈值更新平均值。<br/><br/>#### NOTE<br/>默认情况下，来自 [探测](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#s-u-upstream-probe) 的流量<br/>不包含在计算中；<br/>将 [$upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#v-upstream-probe) 变量<br/>与 `account` 结合使用可以包含它们<br/>或甚至排除其他所有内容。 |

示例：

```nginx
upstream backend {

    zone backend 1m;

    feedback $feedback_value factor=80 account=$condition_value;

    server backend1.example.com:1935  weight=1;
    server backend2.example.com:1935  weight=2;
}

map $protocol $feedback_value {
    "TCP"                      100;
    "UDP"                      75;
    default                    10;
}

map $upstream_probe $condition_value {
    "high_priority" "1";
    "low_priority"  "0";
    default         "1";
}
```

此配置根据各个会话中使用的协议
按反馈级别对服务器进行分类，
并在 [$upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#v-upstream-probe) 上添加条件，
仅统计 `high_priority` 探测
或常规客户端会话。

<a id="index-6"></a>

<a id="s-u-hash"></a>

### hash

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `hash` key [`consistent`];   |
|--------------------------------------------------------------------------------------|------------------------------|
| 默认值                                                                                  | —                            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                     |

为组指定负载均衡方法，其中客户端-服务器映射使用哈希键值确定。键可以包含文本、变量及其组合。请注意，从组中添加或删除任何服务器可能会导致大多数键重新映射到不同的服务器。该方法与 Perl [Cache::Memcached](https://metacpan.org/pod/Cache::Memcached) 库兼容。

使用示例：

```nginx
hash $remote_addr;
```

当使用解析为多个 IP 地址的域名时
（例如，使用 `resolve` 参数），
服务器不会对接收到的地址进行排序，因此它们的顺序可能在
不同服务器之间有所不同，这会影响客户端分布。
为确保一致的分布，
请使用 `consistent` 参数。

如果指定了 `consistent` 参数，将使用 ketama 一致性哈希方法代替上述方法。该方法确保当从组中添加或删除服务器时，只有最少数量的键会重新映射到其他服务器。将该方法用于缓存服务器可提供更高的缓存命中率。该方法与 Perl [Cache::Memcached::Fast](https://metacpan.org/pod/Cache::Memcached::Fast) 库兼容，其中 `ketama_points` 参数设置为 160。

<a id="index-7"></a>

<a id="s-u-least-conn"></a>

### least_conn

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `least_conn`;   |
|--------------------------------------------------------------------------------------|-----------------|
| 默认值                                                                                  | —               |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream        |

为组指定负载均衡方法，其中连接传递给活动连接数最少的服务器，同时考虑服务器权重。如果有多个合适的服务器，则按照它们的权重以循环（轮询）方式选择它们。

<a id="index-8"></a>

<a id="s-u-least-time"></a>

### least_time (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `least_time` `connect` | `first_byte` | `last_byte` [`factor=`number] [`account=`condition_variable];   |
|--------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                                                                                                |

为组指定负载均衡方法，将连接传递给活动服务器的概率与其平均响应时间成反比；响应时间越低，服务器将接收到的连接就越多。

| `connect`    | 该指令考虑建立连接的平均时间。      |
|--------------|----------------------|
| `first_byte` | 该指令使用接收响应第一个字节的平均时间。 |
| `last_byte`  | 该指令使用接收完整响应的平均时间。    |

| `factor`   | 执行与 [response_time_factor (PRO)](#s-u-response-time-factor) 相同的功能，<br/>如果指定了该参数，则会覆盖它。                                                                                                                                                                                                                                                                                                                                           |
|------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `account`  | 指定一个条件变量，<br/>用于控制在计算中考虑哪些连接。<br/>仅当连接的条件变量<br/>不等于 `""` 或 `"0"` 时，<br/>才会更新平均值。<br/><br/>#### NOTE<br/>默认情况下，[探测](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#s-u-upstream-probe)<br/>不包含在计算中；<br/>将 [$upstream_probe](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#v-upstream-probe) 变量<br/>与 `account` 结合使用可以包含它们，<br/>甚至排除其他所有内容。 |

当前值在 API 的 [upstream 指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-stream-upstreams) 中，
以服务器的 `health` 对象中的 `connect_time`、`first_byte_time`
和 `last_byte_time` 形式呈现。

<a id="index-9"></a>

<a id="s-u-random"></a>

### random

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `random` [`two`];   |
|--------------------------------------------------------------------------------------|---------------------|
| 默认值                                                                                  | —                   |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream            |

为组指定负载均衡方法，将连接传递给随机选择的服务器，同时考虑服务器权重。

如果指定了可选的 `two` 参数，Angie 会随机选择两个服务器，然后使用指定的方法选择一个服务器。默认方法是 [least_conn](#s-u-least-conn)，它将连接传递给活动连接数最少的服务器。

<a id="index-10"></a>

<a id="s-u-response-time-factor"></a>

### response_time_factor (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `response_time_factor` number;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `response_time_factor 90;`       |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                         |

为 [least_time (PRO)](#s-u-least-time) 负载均衡方法指定在使用
[指数加权移动平均](https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average) 公式计算平均响应时间时，
**先前** 值的平滑因子。

指定的 number 越大，新值对平均值的影响就越小；如果
指定为 `90`，将采用 90% 的先前值，仅采用 10% 的
新值。有效值范围为 0 到 99（含）。

当前计算结果在 API 的 [upstream 指标](https://cn.angie.software//angie/docs/configuration/modules/http/http_api.md#api-status-stream-upstreams) 中，以服务器的 `health` 对象中的 `connect_time` （建立连接的时间）、`first_byte_time` （接收响应第一个字节的时间）和 `last_byte_time` （接收完整响应的时间）形式呈现。

#### NOTE
计算中仅考虑成功的响应；
什么构成不成功的响应
由 [proxy_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#s-proxy-next-upstream) 指令确定。

<a id="index-11"></a>

<a id="s-u-sticky"></a>

### sticky

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sticky route` value...;<br/><br/>`sticky learn` `zone=`zone `create=`$create_var1... `lookup=`$lookup_var1... [`connect`] [`norefresh`] [`timeout=`time];<br/><br/>`sticky learn` `lookup=`$lookup_var1... `remote_action=`uri `remote_result=`$remote_var [`remote_uri=`uri];   |
|--------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                                                                                                                                                                                 |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                                                                                                                                                                                                                                                                          |

根据第一个参数中指定的模式，
配置客户端与上游服务器之间的粘性会话。
要逐步将带有 `sticky` 的服务器退出轮换，
可以在 [server](#s-u-server) 块中使用 `drain` 选项（PRO）。

#### WARNING
`sticky` 指令必须出现在所有负载均衡方法指令之后，
否则将无法工作。

`route` 模式

此模式使用预定义的路由标识符，
这些标识符可以嵌入到 Angie 可访问的连接属性中。
它的灵活性较低，因为它依赖于预定义的值，
但如果已经在使用此类标识符，则更适合。

在这里，建立连接时，上游服务器
可以为客户端分配一个路由，并以双方
都知道的方式返回其标识符。
路由标识符
应使用 [server](#s-u-server) 指令的
[sid](#s-reresolve) 参数的值。
请注意，如果指定了 [sticky_secret](#s-u-sticky-secret) 指令，
该参数会被额外哈希处理。

希望使用此路由的客户端的后续连接
必须包含服务器颁发的标识符，并以这样的方式
使其最终出现在 Angie 变量中。

指令参数指定可能包含变量的字符串，
用于路由。要选择传入连接定向到的服务器，
使用第一个非空值；
然后将其与 [server](#s-u-server) 指令的
[sid](#s-reresolve) 参数进行比较。
如果服务器选择失败
或所选服务器无法接受连接，
将根据配置的负载均衡方法
选择另一台服务器。

这里 Angie 在 `$route` 变量中查找路由标识符，
该变量根据 [$ssl_preread_server_name](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#v-ssl-preread-server-name)
接收其值（注意必须启用 [ssl_preread](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#s-ssl-preread)）：

```nginx
stream {

    map $ssl_preread_server_name $route {

        a.example.com            a;
        b.example.com            b;
        default                  "";
    }

    upstream backend {

        server 127.0.0.1:8081 sid=a;
        server 127.0.0.1:8082 sid=b;

        sticky route $route;
    }

    server {

        listen 127.0.0.1:8080;

        ssl_preread on;

        proxy_pass backend;
    }
}
```

`learn` 模式（PRO）

在此模式下，使用动态生成的密钥
将客户端绑定到特定的上游服务器；
此模式更加灵活，
因为它动态分配服务器，
将会话存储在共享内存区域中，
并支持多种传递会话标识符的方式。

在这里，会话是基于
来自上游服务器的连接属性创建的。
`create` 和 `lookup` 参数列出了
指定如何创建新会话和查找现有会话的变量。
这两个参数都可以多次使用。

会话标识符是使用 `create` 指定的
第一个非空变量的值；
例如，这可以是
[上游服务器名称](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-server-name)。

会话存储在共享内存区域中；
其名称和大小由 `zone` 参数指定。
如果会话在 `timeout` 指定的 [时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax) 内
未被访问，则会被删除。
默认值为 1 小时。

默认情况下，Angie 通过在每次使用会话时
更新最后访问时间戳来延长会话生命周期。
`norefresh` 参数改变了这种行为：
会话严格按超时时间过期，即使正在使用中。

希望使用会话的客户端的后续连接
必须包含其标识符。
`lookup` 参数使用指定的变量列表
在连接中搜索会话标识符，
在第一个非空变量处停止。
如果未找到任何内容，则该请求被视为新请求。
找到的标识符的值
与共享内存中的会话进行匹配。
如果服务器选择失败
或所选服务器无法处理连接，
将根据配置的负载均衡方法
选择另一台服务器。

`connect` 参数允许在与上游服务器
建立连接后立即创建会话。
如果没有它，会话仅在连接处理完成后创建。
（对于 UDP 连接，会话在服务器选择后立即创建。）

在示例中，Angie 使用 [$rdp_cookie](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#v-rdp-cookie) 变量
创建和查找会话：

```nginx
stream {

    upstream backend {

        server 127.0.0.1:3390;
        server 127.0.0.1:3391;

        sticky learn lookup=$rdp_cookie create=$rdp_cookie zone=sessions:1m;
    }

    server {

        listen 127.0.0.1:3389;

        rdp_preread on;

        proxy_pass backend;
    }
}
```

带 `remote_action` 的 `learn` 模式（PRO 1.10.0+）

`remote_action` 和 `remote_result` 参数
允许使用远程会话存储（PRO）
动态分配和管理会话标识符。

与带 `zone` 的 `learn` 模式不同，
此模式不在本地缓存会话，
而是为每个连接查询远程存储。

`remote_action` 参数必须指向
[client](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#client) 上下文中的 `location`。
`remote_uri` 参数指定客户端 HTTP 请求
到指定 `location` 的 URI。
默认情况下，它是 `/`。
`remote_uri` 值可以包含变量。

此模式的一般操作原理如下：
如果在本地未找到会话标识符，
Angie 会向 `remote_action` 参数指定的
远程存储发送同步子请求。

当新连接到达时，Angie 执行以下操作：

- 首先，从 `lookup` 列表中的
  第一个非空变量中提取会话标识符。
  如果所有变量都为空，
  则使用正常的负载均衡算法，不使用粘性会话。
- 然后 Angie 向 `remote_action` 参数指定的
  远程存储发送同步 HTTP 子请求，该请求应以
  存储能理解的格式包含：
  - 来自 `lookup` 参数的  *会话* 标识符
    （在配置中，这是
    [$sticky_sessid](#v-s-sticky-sessid) 变量）；
  - 预选  *服务器* 的标识符：
    `server` 指令中 `sid=` 参数的值
    （如果指定），
    或服务器名称的 MD5 哈希
    （在配置中，这是
    [$sticky_sid](#v-s-sticky-sid) 变量）。

  `$sticky_sessid` 和 `$sticky_sid` 变量会自动
  以 `stream_` 前缀导出到 HTTP 上下文：
  `$stream_sticky_sessid`、`$stream_sticky_sid`。
  这允许直接在 HTTP 指令中使用它们，
  例如通过 [proxy_set_header](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#proxy-set-header) 使用 HTTP 头。
- 远程存储处理请求并返回 HTTP 响应：

  代码为 200、201 或 204 的响应确认所选服务器。
  远程存储可以同时
  在 HTTP 头或响应正文（PRO）中返回替代服务器标识符；
  可以通过 `remote_result` 提取它。

  当从存储接收到任何其他 HTTP 代码时
  （包括网络错误和超时）
  或不存在的服务器标识符，
  Angie 使用最初选择的服务器。

服务器标识符通过 `remote_result` 参数
从远程存储响应中提取：
它可以指定带有 `upstream_http_` 前缀的变量，
这些变量由 Angie 自动创建，用于访问
来自远程存储的 HTTP 响应头，
或使用 [$sent_body](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-sent-body) 来使用响应正文。
例如，此类响应中的 `X-Sid: server1` 头
在 `$upstream_http_x_sid` 变量中可访问，
其值为 `server1`。

下面是一个简化的配置示例。
远程存储在 `X-Sticky-Sid` 头中返回服务器标识符，
从而确认或覆盖 Angie 的选择：

```nginx
http {

    client {

        location @sticky_client1 {

            # 使用来自 stream upstream 的变量；
            # 它将这些变量以 stream_* 前缀添加到 HTTP 上下文
            proxy_set_header X-Sticky-Sessid $stream_sticky_sessid;
            proxy_set_header X-Sticky-Sid $stream_sticky_sid;
            proxy_set_header X-Sticky-Last $msec;
            proxy_pass http://127.0.0.1:8080;

            proxy_cache remote;
            proxy_cache_valid 200 1d;
            proxy_cache_key $scheme$proxy_host$request_uri$stream_sticky_sessid;
        }
    }
}

stream {

    upstream u {

        server 127.0.0.1:8081 sid=backend-01;
        server 127.0.0.1:8082 sid=backend-02;

        sticky learn lookup=$remote_addr            # stream 变量
        remote_action=@sticky_client1               # 来自 client 块的 location
        remote_result=$upstream_http_x_sticky_sid   # HTTP 变量
        remote_uri=/foo;                            # 默认为 /
    }

    server {

        listen 127.0.0.1:8080;
        proxy_pass u;
    }
}
```

这里，来自远程存储的响应如下：

```none
HTTP/1.1 200 OK
...
X-Sticky-Sid: backend-01
X-Session-Info: active
```

两个变量变为可用：

- `$upstream_http_x_sticky_sid`，
  值为 `backend-01`；
- `$upstream_http_x_session_info`，
  值为 `active`。

由于 `$upstream_http_x_sticky_sid` 变量
在 `remote_result` 参数中指定，
其值将被用于
选择具有 `sid=backend-01` 的服务器。

`sticky` 指令会考虑 [upstream](#s-u-upstream) 中服务器的状态：

- 标记为 `down` 或由于故障而暂时不可用的服务器
  将被排除在选择之外。
- 已达到最大连接数的服务器
  （使用 `max_conns` 时）将被暂时跳过。
- 带有 `drain` 选项的服务器（PRO）
  在 `sticky` 模式下当标识符匹配时
  可以被选择用于创建新会话。
- 如果先前不可用的服务器恢复，
  `sticky` 会自动恢复使用它。

`sticky` 的行为可以通过
[sticky_secret](#s-u-sticky-secret) 和 [sticky_strict](#s-u-sticky-strict) 指令进一步配置。
如果 `sticky` 无法选择服务器或服务器不可用，
请求将根据所选的负载均衡方法进行处理，
除非启用了 `sticky_strict` 指令。
在 `sticky_strict on;` 模式下，请求将被拒绝并返回错误。

在 `sticky` 指令的 `zone` 参数中
指定的共享内存区域
不能在不同的 `upstream` 组之间共享；
每个组必须使用自己的区域。

<a id="index-12"></a>

<a id="s-u-sticky-secret"></a>

### sticky_secret

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sticky_secret` string;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认值                                                                                  | —                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                  |

将 string 作为盐值添加到 MD5 哈希函数中，
用于 `route` 模式下的 [sticky](#s-u-sticky) 指令。
String 可以包含变量，例如 `$remote_addr`：

```nginx
upstream backend {
    server 127.0.0.1:8081 sid=a;
    server 127.0.0.1:8082 sid=b;

    sticky route $route;
    sticky_secret my_secret.$remote_addr;
}
```

盐值添加在哈希值之后；
要独立验证哈希机制：

```console
$ echo -n "<VALUE><SALT>" | md5sum
```

<a id="index-13"></a>

<a id="s-u-sticky-strict"></a>

### sticky_strict

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `sticky_strict` `on` | `off`;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认值                                                                                  | `sticky_strict off;`            |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | upstream                        |

启用时，如果所需的服务器不可用，
Angie 将向客户端返回连接错误，
而不是回退到另一个可用的服务器，
后者是未找到匹配服务器时的默认行为。

<a id="built-in-variables-25"></a>

## 内置变量

`stream_upstream` 模块支持以下内置变量:

<a id="v-s-sticky-sessid"></a>

### `$sticky_sessid`

与 [sticky](#s-u-sticky) 中的 `remote_action` 一起使用;
存储从 `lookup` 获取的初始会话标识符。

<a id="v-s-sticky-sid"></a>

### `$sticky_sid`

与 [sticky](#s-u-sticky) 中的 `remote_action` 一起使用;
存储先前与会话关联的服务器标识符。

`sticky_sid` 包含 [upstream](#s-u-upstream) 块中 `server` 指令的 `sid=` 参数的值(如果指定),
或者服务器名称的 MD5 哈希值。

<a id="v-s-upstream-addr"></a>

### `$upstream_addr`

存储上游服务器的 IP 地址和端口,或 UNIX 域套接字的路径。如果在代理过程中联系了多个服务器,它们的地址用逗号分隔,例如:

> 192.168.1.1:1935, 192.168.1.2:1935, unix:/tmp/sock

如果无法选择服务器,该变量保留 [服务器组](#s-u-upstream) 的名称。

<a id="v-s-upstream-bytes-received"></a>

### `$upstream_bytes_received`

从上游服务器接收的字节数。多个连接的值用逗号和冒号分隔,类似于 [$upstream_addr](#v-s-upstream-addr) 变量中的地址。

<a id="v-s-upstream-bytes-sent"></a>

### `$upstream_bytes_sent`

发送到上游服务器的字节数。多个连接的值用逗号和冒号分隔,类似于 [$upstream_addr](#v-s-upstream-addr) 变量中的地址。

<a id="v-s-upstream-connect-time"></a>

### `$upstream_connect_time`

连接到上游服务器的时间;时间以秒为单位保存,具有毫秒分辨率。多个连接的时间用逗号和冒号分隔,类似于 [$upstream_addr](#v-s-upstream-addr) 变量中的地址。

<a id="v-s-upstream-first-byte-time"></a>

### `$upstream_first_byte_time`

接收第一个数据字节的时间;时间以秒为单位保存,具有毫秒分辨率。多个连接的时间用逗号分隔,类似于 [$upstream_addr](#v-s-upstream-addr) 变量中的地址。

<a id="v-s-upstream-session-time"></a>

### `$upstream_session_time`

会话持续时间,以秒为单位,具有毫秒分辨率。多个连接的时间用逗号分隔,类似于 [$upstream_addr](#v-s-upstream-addr) 变量中的地址。

<a id="v-s-upstream-sticky-status"></a>

### `$upstream_sticky_status`

粘性连接的状态。

| `""`   | 连接路由到未启用 sticky 的服务器组。     |
|--------|----------------------------|
| `NEW`  | 连接不包含粘性信息。                 |
| `HIT`  | 包含粘性信息的连接路由到所需的服务器。        |
| `MISS` | 包含粘性信息的连接路由到由负载均衡算法选择的服务器。 |

多个连接的值用逗号和冒号分隔,
类似于 [$upstream_addr](#v-s-upstream-addr) 变量中的地址。


# https://cn.angie.software/angie/docs/configuration/modules/stream/stream_upstream_probe.md

<!-- review: finished -->

<a id="stream-upstream-probe"></a>

# Upstream Probe

该模块为 [stream_upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#stream-upstream) 实现了主动健康探测。

<a id="configuration-example-74"></a>

## 配置示例

```nginx
server {
    listen ...;

    # ...
    proxy_pass backend;
    upstream_probe_timeout 1s;

    upstream_probe backend_probe
        port=12345
        interval=5s
        test=$good
        essential
        fails=3
        passes=3
        max_response=512k
        mode=onfail
        "send=data:GET / HTTP/1.0\r\n\r\n";
}
```

#### NOTE
根据 RFC 2616 (HTTP/1.1) 和 RFC 9110 (HTTP Semantics)，HTTP 头部
必须使用 CRLF 序列 (`\r\n`) 分隔，而不是仅使用
`\n`。

<a id="directives-83"></a>

## 指令

<a id="index-0"></a>

<a id="s-u-upstream-probe"></a>

### upstream_probe (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `upstream_probe` name [`port=`number] [`interval=`time] [`test=`condition] [`essential` [`persistent`]] [`fails=`number] [`passes=`number] [`max_response=`size] [`mode=``always` | `idle` | `onfail`] [`udp`] [`send=`string] [`ping`] [`ping_timeout=`time];   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 默认值                                                                                  | —                                                                                                                                                                                                                                                                |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                                                                                                                                                                                                                                                           |

为 [upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-upstream) 组中的服务器定义主动健康探测，
该组在与 `upstream_probe` 指令位于同一 `server` 上下文中的 [proxy_pass](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#s-proxy-pass) 指令中指定。

如果对服务器的请求成功，则服务器通过探测，需考虑 `upstream_probe` 指令的所有参数设置以及影响定义它的 `server` 上下文如何使用上游的所有参数，包括 [proxy_next_upstream](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_proxy.md#s-proxy-next-upstream) 指令。

要使用探测功能，
上游必须具有共享内存区域 ([zone](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-u-zone))。
一个上游可以配置多个探测。

接受以下参数：

| `name`               | 探测的必需名称。                                                                                                                                                                                                                                                                                                                                                      |
|----------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `port`               | 探测请求的备用端口号。                                                                                                                                                                                                                                                                                                                                                   |
| `interval`           | 探测之间的 [间隔](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)。<br/>默认值 — `5s`。                                                                                                                                                                                                                                                         |
| `test`               | 探测的条件，定义为变量字符串。<br/>如果变量替换结果为 `""` 或 `"0"`，<br/>则探测未通过。                                                                                                                                                                                                                                                                                                       |
| `essential`          | 如果设置，将检查服务器的初始状态，因此服务器<br/>在通过探测之前不会接收客户端请求。                                                                                                                                                                                                                                                                                                                  |
| `persistent`         | 设置此参数需要首先启用 `essential`；<br/>在 [配置重载](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile-reloading) 之前被认为健康的<br/>`persistent` 服务器<br/>无需首先通过此探测即可开始接收请求。                                                                                                                                                                            |
| `fails`              | 使服务器变为不健康的连续失败探测次数。<br/>默认值 — 1。                                                                                                                                                                                                                                                                                                                              |
| `passes`             | 使服务器变为健康的连续通过探测次数。<br/>默认值 — 1。                                                                                                                                                                                                                                                                                                                               |
| `max_response`       | 响应的最大内存大小。如果指定零<br/>[值](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)，则禁用响应等待。<br/>默认值 — `256k`。                                                                                                                                                                                                                                  |
| `mode`               | 探测模式，取决于服务器的健康状态：<br/><br/>- `always` — 无论服务器状态如何都进行探测；<br/>- `idle` — 探测影响不健康的服务器以及自上次客户端请求以来已过<br/>  `interval` 的服务器。<br/>- `onfail` — 仅探测不健康的服务器。<br/><br/>默认值 — `always`。                                                                                                                                                                                 |
| `udp`                | 如果指定，则使用 UDP 协议进行探测。<br/>默认情况下，使用 TCP 进行探测。                                                                                                                                                                                                                                                                                                                   |
| `send`               | 为探测发送的数据：带有 `data:` 前缀的内联数据<br/>或文件路径（绝对路径或相对于 `/usr/local/angie/` 的路径）。<br/><br/>使用文件时：<br/><br/>- [工作进程](https://cn.angie.software//angie/docs/configuration/modules/core.md#worker-processes) 在每次访问时打开并读取<br/>  文件；内容不会缓存在内存中。<br/>- 文件更改时不需要重新加载配置；<br/>  下次访问时将读取新内容。<br/>- 所需的访问权限：文件为 `644`，<br/>  目录为 `755`。<br/>- 使用移动命令 (`mv`) 更新文件，<br/>  而不是直接编辑。 |
| `ping` (PRO)         | 使用 ICMP 回显请求代替 TCP/UDP 探测。<br/>需要使用 `--with-stream_upstream_probe_icmp` 构建 Angie。<br/>不兼容 `test`、`port`、<br/>`udp` 或 `send`。                                                                                                                                                                                                                                  |
| `ping_timeout` (PRO) | 等待 ICMP 回显应答的超时时间。<br/>默认值 — `1s`。                                                                                                                                                                                                                                                                                                                            |

示例：

```nginx
upstream backend {
    zone backend 1m;

    server a.example.com;
    server b.example.com;
}

map $upstream_probe_response $good {
    ~200    "1";
    default  "";
}

server {
    listen ...;

    # ...
    proxy_pass backend;
    upstream_probe_timeout 1s;

    upstream_probe backend_probe
        port=12345
        interval=5s
        test=$good
        essential
        persistent
        fails=3
        passes=3
        max_response=512k
        mode=onfail
        "send=data:GET / HTTP/1.0\r\n\r\n";
}
```

探测操作的详细信息：

- 最初，服务器在通过为其配置的  *所有* `essential` 探测之前不会接收客户端请求，
  如果配置已重载且服务器在此之前被认为健康，则跳过 `persistent` 探测。
  如果没有此类探测，则认为服务器健康。
- 如果为服务器配置的  *任何* 探测达到 `fails`
  或服务器达到 [max_fails](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-max-fails)，
  则认为服务器不健康且不会接收客户端请求。
- 要使不健康的服务器再次被认为健康，
  为其配置的  *所有* 探测必须达到各自的 `passes`；
  之后，还会考虑 [max_fails](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#s-max-fails)。

<a id="index-1"></a>

<a id="s-u-upstream-probe-timeout"></a>

### upstream_probe_timeout (PRO)

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `upstream_probe_timeout` time;   |
|--------------------------------------------------------------------------------------|----------------------------------|
| 默认值                                                                                  | `upstream_probe_timeout 50s;`    |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | server                           |

设置使用 [upstream_probe (PRO)](#s-u-upstream-probe) 指令配置的健康探测与服务器建立的连接的最大空闲 [时间](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)；如果超过此限制，连接将被关闭。

<a id="built-in-variables-26"></a>

## 内置变量

`stream_upstream` 模块支持以下内置变量：

<a id="v-s-upstream-probe"></a>

### `$upstream_probe` (PRO)

当前活动的 [upstream_probe](#s-u-upstream-probe) 的名称。

<a id="v-s-upstream-probe-response"></a>

### `$upstream_probe_response` (PRO)

在由 [upstream_probe](#s-u-upstream-probe) 配置的主动探测期间接收到的响应内容。


# https://cn.angie.software/angie/docs/installation/external-modules/subs.md

<!-- review: finished -->

<a id="external-subs"></a>

# Subs

Subs 模块允许替换 HTTP 响应正文中的字符串（包括固定字符串和使用正则表达式）。响应正文中找到的所有匹配项都会被替换。

<a id="installation-26"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-subs`；
- Angie PRO：`angie-pro-module-subs`。

<a id="loading-the-module-26"></a>

## 加载模块

在 `main{}` 上下文中包含该模块：

```nginx
load_module modules/ngx_http_subs_filter_module.so;
```

<a id="configuration-example-101"></a>

## 配置示例

```nginx
http {
    server {
        listen 80;

        location / {
            subs_filter_types text/html text/css text/xml;
            subs_filter st(\d*).example.com $1.example.com ir;
            subs_filter a.example.com s.example.com;
            subs_filter http://$host https://$host;
        }
    }
}
```

<a id="additional-information-27"></a>

## 更多信息

详细文档和源代码可在以下位置获取：
[https://github.com/yaoweibin/ngx_http_substitutions_filter_module](https://github.com/yaoweibin/ngx_http_substitutions_filter_module)


# https://cn.angie.software/support.md

# 标准技术支持

标准技术支持提供配置更改咨询和协助、文档说明，以及与Angie产品相关的网络协议和操作系统设置使用建议。

标准技术支持基于单独协议提供，服务时间为工作日莫斯科时间上午10点至晚上8点。我们承诺在收到请求后4小时内首次响应。标准技术支持的完整条款和条件可在 [`此处`](https://cn.angie.software//support/Angie_support.pdf) 查看。

## 标准技术支持提供的服务

- 软件功能问题故障排查。
- 软件使用咨询和文档说明。
- 就HTTP和TCP协议与软件功能相关的操作提供咨询。
- 就更改用户操作系统设置以提升软件性能提供咨询。
- 就软件与用户安装的其他解决方案之间的优化可能性提供咨询。
- 为满足用户个性化需求提供配置文件定制支持。
- 在技术支持服务期限内提供更新。


# https://cn.angie.software/vacancies/technical-product-manager.md

# 技术产品负责人（Angie ADC）

我们是 Angie Software 团队。公司的核心成员是参与了 nginx 早期开发的资深工程师，他们如今正在打造 nginx 的演进继任者——Angie。我们的产品已经在全球范围内获得越来越多的认可，我们也为自己设定了一个雄心勃勃的目标：超越 F5、Citrix、Radware 这样的行业巨头。

Angie ADC 是一款现代的企业级应用交付控制器。它负责流量路由、负载均衡、SSL 卸载和安全防护——确保应用程序在复杂网络环境中稳定运行所需的一切。我们坚信，制胜的关键不仅在于"引擎"的技术卓越，还在于对市场需求的深刻理解——正是这种理解将复杂的事物转化为真正受欢迎的产品。

我们的文化是非正式的、扁平的：大家平等交流，没有官僚作风，也没有多余的繁文缛节。决策迅速做出，论据比头衔更重要。

## 您将做什么：

- 全面负责 Angie ADC 的产品战略：从愿景、路线图，到 backlog 优先级排序和成功指标——您将是决定产品明天走向何方的那个人；
- 深入钻研业务领域（负载均衡、路由、网络协议、ADC），将市场需求和技术可能性转化为给研发团队的清晰功能规范；
- 成为客户的声音和团队的纽带：与架构师、设计师、项目经理和商务团队建立高效协作，参与 pre-sale 活动，并把产品价值传达给工程师和业务决策者；
- 研究竞争对手、分析行业趋势、发现新的增长机会——不是复制，而是另辟蹊径，提出更好的解决方案。

## 我们想招的人：

- 把产品视为解决真实客户问题的战略工具，而不仅仅是一组功能；
- 具备扎实的技术背景：作为技术产品经理、架构师或分析师，至少有 5 年高负载系统或系统软件的设计经验；理解 L4–L7 网络的工作原理；有网络软件或负载均衡器方面的经验——这是几乎必备的；
- 熟练运用架构框架和模式，能与开发人员平等对话，快速理解复杂的技术细节；
- 能在"这是怎么工作的"和"它解决了什么痛点"之间自如切换，并能向任何受众（从工程师到高管）有说服力地阐述自己的观点；
- 希望打造一款全球公司都会选择的产品，并准备从最早期阶段开始影响它。

## 我们提供：

- 真正影响一款世界级产品的机会，看到您的决策落地，而不必承受大公司的惯性；
- 在一支业内公认的专家团队中工作，团队重视专业能力、主动性和担当；
- 扁平结构，您的声音真正被重视，官僚作风不复存在；
- 有竞争力的薪资、补充医疗保险、报销培训和会议费用——我们支持您的职业成长；
- 已认证的 IT 企业资质和透明的工作条件。

**工作形式：** 混合办公或全坐班（可商议），萨维奥洛夫斯卡娅（Савёловская）地铁站，Factoria 商务中心。

如果您感兴趣，请将英文简历发送至 [hr@wbsrv.ru](mailto:hr@wbsrv.ru)。

#### NOTE
我们仅接受英文简历，请用英文提交您的简历。


# https://cn.angie.software/legal/terms-of-use.md

# 网站使用规则

网站管理员提供根据这些规则的条款使用网站的机会（以下简称"规则"）。

我们通知您，只有在您遵守以下规定的条件下，才能以任何方式访问和使用网站。如果您不同意这些规则，请停止使用网站。这些规则构成根据俄罗斯联邦民法典第437条第2款的公共提议，并定义了网站的使用条款，以及用户和管理员的权利和义务。通过以任何方式使用网站，包括在互联网上浏览网站，您确认您已熟悉并同意这些规则，且不作任何例外。

1. 术语和定义。

1.1. 网站 - 一组计算机设备和其他信息的程序，包含在一个信息系统中，通过域名和/或网络地址提供访问，从而允许识别这些网站。互联网上的网站页面 - 网站的一部分，通过由域名和网站所有者在互联网上定义的符号组成的指针进行访问。网站位于以下地址：www.wbsrv.ru，angie.software，统称为这些规则中的"网站"。

1.2. 网站管理员（管理员） - 有限责任公司"Web Server"（OGRN: 1227700436578；INN: 9704151517）。

1.3. 管理员的合作伙伴（合作伙伴） - 根据合作伙伴与用户之间签订的单独协议提供独立服务的个人。根据这些协议产生的权利和义务直接在用户与合作伙伴之间产生；管理员不是上述协议的当事方，仅在管理员的网站上放置信息关于合作伙伴和/或他们的网站，包括提供指向合作伙伴网站的超链接。管理员未验证指定网站是否符合任何要求（准确性、合法性等）。管理员不对用户通过网站访问的第三方网站上发布的任何信息，以及这些网站或内容的可用性及其对用户的使用后果负责。指向任何广告/描述任何产品、服务的网站的链接（以任何形式）并不构成管理员对这些产品和/或服务的支持或推荐，除非在网站上明确指出。

1.4. 用户（您） - 以任何方式使用网站的人，包括通过互联网访问网站。

1. 用户和管理员的权利和责任：

2.1. 使用网站即表示用户同意：

2.1.1. 遵守俄罗斯联邦的法律和这些规则；

2.1.2. 不使用软件，也不采取旨在破坏网站正常功能的行为，包括不使用恶意软件引入有害计算机程序或任何其他类似的有害代码，可能对管理员的设备及/或第三方造成技术损害；

2.1.3. 不上传、发布、通过电子邮件或以其他方式传送任何不需要或未授权的广告、促销材料，例如"垃圾邮件"和类似类型的邮件；

2.1.4. 不以任何方式使用网站来伤害或试图伤害未成年人；

2.1.5. 不使用网站进行逆向工程、反编译、拆解、修改，以及任何试图披露网站软件组件的源代码和/或基于其创建衍生作品的行为；

2.1.6. 不使用网站发布、通过电子邮件（如果网站提供此技术可能性）或以其他方式传输任何内容，以挑起非法、骚扰、诽谤、侵犯隐私或基于性别、种族和伦理基础的歧视的行为；

2.1.7. 不使用网站冒充任何其他人或扭曲与自然人或法人之间的关系，在法律要求或规定此类识别的情况下；

2.1.8. 不使用网站发布、通过电子邮件（如果网站提供此技术可能性）或以其他方式传输任何侵犯第三方知识产权的内容，包括侵犯任何专利、商标、商业秘密、生产秘密或任何其他第三方的知识产权的内容；

2.1.9. 不使用网站收集和存储其他用户的个人数据，未经他们事先同意进行此类收集和存储。

2.1.10. 不使用网站发布、通过电子邮件（如果网站提供此技术可能性）或以其他方式传输任何包含制造武器、爆炸物的信息，包含色情、儿童色情的元素（或进行宣传），代表制造、使用或其他使用麻醉物质或其类似物的广告；

2.1.11. 不使用网站以自己的名义提供网站上发布的商品或服务的信息，不使用网站向第三方提供商业产品或服务或用于其他商业目的，除非已获得管理员的直接许可。

2.2. 网站用户有权：

使用网站的条款和根据这些规则；向管理员提交查询和索赔，电子邮件地址为：[info@wbsrv.ru](mailto:info@wbsrv.ru)

2.3. 网站管理员有权：

2.3.1. 管理网站，确定其结构、设计，限制对网站及/或其个别部分（页面）的访问；

2.3.2. 在网站上放置广告，进行广告邮件派送，前提是用户同意接收此类邮件；

2.3.3. 在任何时候出于任何理由更改或删除用户在网站上发布的任何信息，而无需提前通知用户，如果该信息违反了第三方的法律权利和利益、规则和/或用户接受的管理员的其他文件（如有）；或者在管理员收到法院命令、政府机构的行为要求管理员从网站删除此类信息的情况下。

1. 管理员和合作伙伴的免责条款：

3.1. 网站，包括通过网站的功能能力使用、存储和/或部署的所有软件和其他对象，以及在网站上发布的内容和/或任何信息，均以"现状"提供。在任何情况下，管理员和/或管理员的合作伙伴不对用户或任何第三方承担任何损失，无论其发生的原因（包括但不限于附带或间接损失、与利润损失、商业或生产活动中断、商业信息丢失或任何其他损失相关的损失）因使用或无法使用网站而产生。网站管理员和合作伙伴不保证网站、管理员合作伙伴提供的服务将持续提供且无错误，并且任何服务和/或在网站上发布的内容的质量将满足您的目标和期望。

3.2. 网站管理员保留随时终止对网站的访问的权利，并保留以有限模式提供网站的功能和功能能力的权利。

3.3. 网站管理员不对用户的行为负责，也不对在网站上提供的第三方和/或管理员合作伙伴的服务负责。合作伙伴和第三方的服务根据用户与相应第三方和/或管理员合作伙伴之间签订的相关协议的条款提供。所有有关提供此类服务的争议，包括关于其安全性和服务是否符合用户期望和目标的索赔，均由用户与相应的第三方和/或管理员合作伙伴独立解决，不涉及管理员。管理员不对此类服务的错误运行或无法运行负责，或用户未能通过网站的功能能力获得预期结果负责。

3.4. 用户对其在网站上执行的任何行为，以及其上传到网站的任何信息和数据，任何用户上传到网站或以其他方式向其他用户展示的内容，承担全部责任。用户承诺独立解决与第三方相关的关于其内容非法发布的索赔。

3.5. 网站管理员不控制用户在网站上发布的用户内容的内容，并且不主动发起用户内容上传到网站。用户对他们在网站上或通过网站发布的任何用户内容或其他信息承担个人责任。如果管理员收到有关侵犯第三方权利的索赔，以及在收到相关授权政府机构关于因用户内容的发布、使用或传输而违反法律的请求时，网站管理员有权在未提前通知用户的情况下删除用户在网站上发布的相关内容和/或信息。

3.6. 访问第三方网站、安装任何计算机程序、使用合作伙伴和/或第三方的服务由用户自行承担风险和责任。

3.7. 管理员对其在网站上发布的广告（如果网站上有相应页面的广告）在俄罗斯联邦法律规定的范围内承担责任。

3.8. 在任何情况下，网站管理员的责任限于1,000（千）卢布，并且仅在其行为中存在过错的情况下才会被施加。

1. 知识产权。

4.1. 管理员在网站上发布的所有知识产权对象（设计元素、文本、图形、插图、视频、计算机程序、数据库、声音和任何其他知识活动成果）均为知识产权，管理员是其权利持有者或在其他法律基础上使用该知识产权。未经管理员事先书面同意，不得使用知识产权，规则第4.2条中规定的例外情况除外。

4.2. 管理员在网站上发布的内容的使用须遵循以下条件：以引用的方式，并提供指向网站的有效超链接。

4.3. 通过在网站上放置和/或展示内容（如果用户具备此技术能力），用户保证并保证他们对所述内容拥有独占权利（或相应内容的权利持有人依法授予他们使用该内容的权利）；用户发布此类内容不会侵犯第三方的法律权利和利益，包括第三方对其知识产权的权利。

4.4. 通过以任何方式开始使用网站，用户同意在规则的整个持续期间内，无需为使用用户识别手段（包括其商标、商号和商业名称）支付任何补偿，用于管理员的广告和其他材料、媒体，仅用于通知第三方用户是管理员的客户/合作伙伴。

1. 其他条款。

5.1. 网站管理员有权对这些规则进行更改。更改将通过互联网发布，网址为：
[https://cn.angie.software/legal/terms-of-use](https://cn.angie.software/legal/terms-of-use)。更改将适用于在更改生效时已成为网站用户的个人。规则的新版本自上述网址发布之时起生效。在规则更改后以任何方式继续使用网站，包括浏览，意味着用户接受此类更改。

5.2. 规则的适用和解释应遵循俄罗斯联邦的法律。规则未规定的事项应根据俄罗斯联邦的法律进行解决。

5.3. 因这些规则所调节的法律关系引起的所有争议应通过协商解决。如果未能达成协议，则提交莫斯科仲裁法院审理。

5.4. 规则自用户加入之时起生效，具体定义见规则的前言，并无限期有效。

5.5. 管理员可以单方面修改或终止规则，而无需事先通知用户，也无需因此支付任何赔偿。

5.6. 由于其无偿性质，基于这些规则产生的各方之间的关系不应适用消费者保护立法的规定。

5.7. 在用户违反规则的情况下，管理员未提出索赔并不构成对规则的放弃，也不剥夺管理员采取适当措施保护其利益的权利。

5.8. 规则已在互联网上发布，网址为：
[https://cn.angie.software/legal/terms-of-use](https://cn.angie.software/legal/terms-of-use)

Web Server, LLC.

OGRN: 1227700436578.

地址：127015, 俄罗斯, 莫斯科, Vyatskaya St., 27, bld. 7.

电话：+7 (495) 120 50 33.

电子邮件：[legal@wbsrv.ru](mailto:legal@wbsrv.ru).

发布日期：2023年2月1日。


# https://cn.angie.software/angie/docs/installation/external-modules/testcookie.md

<!-- review: finished -->

<a id="external-testcookie"></a>

# Testcookie

该模块使用基于 cookie 的质询-响应机制提供机器人防护。

<a id="installation-27"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-testcookie`
- Angie PRO：`angie-pro-module-testcookie`

<a id="loading-the-module-27"></a>

## 加载模块

在 `main{}` 上下文中启用该模块：

```nginx
load_module modules/ngx_http_testcookie_access_module.so;
```

<a id="configuration-example-102"></a>

## 配置示例

```none
http {
    testcookie off;
    testcookie_name BPC;
    testcookie_secret keepmesecret;
    testcookie_session $remote_addr;
    testcookie_arg ckattempt;
    testcookie_max_attempts 3;
    testcookie_p3p 'CP="CUR ADM OUR NOR STA NID", policyref="/w3c/p3p.xml"';
    testcookie_fallback http://google.com/cookies.html?backurl=http://$host$request_uri;

    testcookie_whitelist {
        8.8.8.8/32;
    }

    testcookie_redirect_via_refresh on;
    testcookie_refresh_encrypt_cookie on;
    testcookie_refresh_encrypt_cookie_key deadbeefdeadbeefdeadbeefdeadbeef;
    testcookie_refresh_encrypt_cookie_iv deadbeefdeadbeefdeadbeefdeadbeef;
    testcookie_refresh_template '<html><body>setting cookie...<script type="text/javascript" src="/aes.min.js" ></script><script>function toNumbers(d){var e=[];d.replace(/(..)/g,function(d){e.push(parseInt(d,16))});return e}function toHex(){for(var d=[],d=1==arguments.length&&arguments[0].constructor==Array?arguments[0]:arguments,e="",f=0;f<d.length;f++)e+=(16>d[f]?"0":"")+d[f].toString(16);return e.toLowerCase()}var a=toNumbers("$testcookie_enc_key"),b=toNumbers("$testcookie_enc_iv"),c=toNumbers("$testcookie_enc_set");document.cookie="BPC="+toHex(slowAES.decrypt(c,2,a,b))+"; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/";location.href="$testcookie_nexturl";</script></body></html>';

    server {
        listen 80;
        server_name test.com;

        location = /aes.min.js {
            gzip on;
            gzip_min_length 1000;
            gzip_types text/plain;
            root /var/www/public_html;
        }

        location = /w3c/p3p.xml {
            root /var/www/public_html;
        }

        location = /.well-known/acme-challenge/ {
            root /var/www/public_html;
        }

        location / {
            testcookie on;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:80;
        }
    }
}
```

<a id="additional-information-28"></a>

## 其他信息

详细文档和源代码可在以下位置获取：
[https://github.com/kyprizel/testcookie-nginx-module/](https://github.com/kyprizel/testcookie-nginx-module/)


# https://cn.angie.software/news/integrations/testiruem-angie-pro-na-baikale.md

# 在贝加尔测试Angie PRO

*31.08.2023*

我们成功地在ARM处理器架构上编译、构建软件包并测试了我们的产品Angie/Angie PRO。

![Alternative text](../../_images/news/testiruem-angie-pro-na-baikale.jpeg)![Alternative text](../../_images/news/testiruem-angie-pro-na-baikale.jpeg)

大家好！

在过去一周，虽然电报上错误地出现了关于我们尊敬的贝加尔电子"破产"的 [评论](https://t.me/electroshockNEWS/417)，但我们确切地知道贝加尔一切运转正常！

今年夏初，贝加尔电子公司友好地向我们提供了一台由其合作伙伴公司Elpitech生产的Elpi511系统主机。该系统主机采用BE-M1000（贝加尔-M）处理器，预装了经FSTEC认证的俄罗斯操作系统Astra Linux SE 4.7 Novorossiysk。我们成功地在ARM处理器架构上编译、构建软件包并测试了我们的产品Angie/Angie PRO。

目前，我们已将测试结果发送给Astra集团公司，以获取与Astra Linux SE 4.7操作系统的兼容性证书。感谢贝加尔电子的同事们！


# https://cn.angie.software/angie/docs/installation/thirdparty.md

<!-- review: finished -->

<a id="thirdparty"></a>

# Angie 的第三方软件源

我们建议使用官方软件包来安装 Angie:

- [Angie](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)
- [Angie PRO](https://cn.angie.software//angie/docs/installation/pro_packages.md#pro-packages)

如果您希望使用特定于您的系统或发行版的第三方软件源,
目前可以使用以下选项。

各种 Linux 发行版的官方软件源:

- [Alt Linux](https://packages.altlinux.org/ru/sisyphus/srpms/angie/)
- [Arch User Repository](https://aur.archlinux.org/packages/angie)
- [FreeBSD FreshPorts](https://www.freshports.org/www/angie/)
- [nixpkgs](https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/servers/http/angie/default.nix)
- [ROSA Linux ABF](https://abf.io/import/angie/)

macOS 的包管理器:

- [Homebrew](https://github.com/stychos/homebrew-angie):
  ```console
  $ brew tap stychos/angie
  $ brew install stychos/angie/angie
  ```
- [MacPorts](https://github.com/macports/macports-ports/tree/master/www/angie):
  ```console
  $ sudo port install angie
  ```

有关第三方来源的其他列表,请参见 [此处](https://repology.org/project/angie/versions)。

#### NOTE
我们不在这些软件源中发布任何内容,
也不对从这些软件源安装软件的后果负责。


# https://cn.angie.software/news/tri-nedeli-obnovleniy.md

# 三周更新计划

*19.09.2023*

在接下来的三周(没错!)中，我们将以更新来庆祝并让用户感到欣喜。

![Alternative text](../../_images/news/tri-nedeli-obnovleniy.jpeg)![Alternative text](../../_images/news/tri-nedeli-obnovleniy.jpeg)

在接下来的三周(没错!)中，我们将以更新来庆祝并让用户感到欣喜。

今天我们将Angie [更新](https://wbsrv.ru/tpost/yp7ycu13c1-veb-server-angie-s-otkritim-ishodnim-kod) 至1.3.0版本，简化了服务器配置和监控。

主要新增功能之一是支持在同一配置上下文（"location"指令）中使用多个请求URI匹配模式。这减少了所需的配置量，并降低了用户出错的可能性。此外，新版本的Angie包含了Prometheus格式的统计数据，这简化了在现代基础设施中构建监控系统的过程。

您可以在 [这里](https://en.angie.software) 试用。


# https://cn.angie.software/angie/docs/troubleshooting.md

<!-- review: finished -->

<a id="troubleshooting"></a>

# 故障排除

如果您遇到技术问题并且在其他部分找不到解决方案，请在 [社区论坛](https://forum.angie.support/) 或 [Telegram 频道](https://t.me/angie_support) 上提问。

客户技术支持：

- [https://support.angie.software](https://support.angie.software)
- [support@angie.software](mailto:support@angie.software)

<a id="debug-logging"></a>

## 调试日志

在执行自我诊断或按照技术支持建议进行操作之前，应启用调试日志。

为此，请使用支持调试的可执行文件运行 Angie：

Linux

在 Linux 的 [预构建包](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 中，`angie-debug` 文件是启用调试日志构建的：

```console
$ ls -l /usr/sbin/ | grep angie

   lrwxrwxrwx 1 root root      13 Sep 21 18:58 angie -> angie-nodebug
   -rwxr-xr-x 1 root root 1561224 Sep 21 18:58 angie-debug
   -rwxr-xr-x 1 root root 1426056 Sep 21 18:58 angie-nodebug
```

配置运行 `angie-debug`：

```console
$ sudo ln -fs angie-debug /usr/sbin/angie
$ sudo angie -t && sudo service angie upgrade
```

这将启动 [实时可执行文件升级](https://cn.angie.software//angie/docs/configuration/runtime.md#service-upgrade)。

调试后要恢复到常规可执行文件：

```console
$ sudo ln -fs angie-nodebug /usr/sbin/angie
$ sudo angie -t && sudo service angie upgrade
```

FreeBSD

在 FreeBSD 的 [预构建包](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 中，`angie-debug` 文件是启用调试日志构建的：

```console
$ ls -l /usr/local/sbin/ | grep angie

   lrwxrwxrwx 1 root root      13 Sep 21 18:58 angie -> angie-nodebug
   -rwxr-xr-x 1 root root 1561224 Sep 21 18:58 angie-debug
   -rwxr-xr-x 1 root root 1426056 Sep 21 18:58 angie-nodebug
```

配置运行 `angie-debug`：

```console
$ sudo ln -fs angie-debug /usr/local/sbin/angie
$ sudo angie -t && sudo service angie upgrade
```

这将启动 [实时可执行文件升级](https://cn.angie.software//angie/docs/configuration/runtime.md#service-upgrade)。

调试后要恢复到常规可执行文件：

```console
$ sudo ln -fs angie-nodebug /usr/local/sbin/angie
$ sudo angie -t && sudo service angie upgrade
```

Docker

在 [模板化 Docker 镜像](https://cn.angie.software//angie/docs/installation/docker.md#docker-images) 中，您可以通过覆盖 `ANGIE_BINARY` 环境变量切换到调试版本：

```console
$ docker run -it --rm -e ANGIE_BINARY="angie-debug" \
  docker.angie.software/angie:templated
```

从源构建

当从源构建 Angie 时，编译前 [启用调试](https://cn.angie.software//angie/docs/installation/sourcebuild.md#configure)：

```console
$ ./configure --with-debug ...
```

安装后，**angie -V** 可以验证是否启用了调试日志：

```console
$ angie -V

  ...
  configure arguments: --with-debug ...
```

#### NOTE
使用支持调试的可执行文件可能会略微降低性能；启用调试日志可能会显著降低性能并增加磁盘空间使用。

要启用调试日志，请在配置中使用 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 指令设置 `debug` 级别：

```nginx
error_log /path/to/log debug;
```

并重新加载配置：

```console
$ sudo angie -t && sudo service angie reload
```

在启用调试日志的 [模板化 Docker 镜像](https://cn.angie.software//angie/docs/installation/docker.md#docker-images) 中，您也可以使用 `ANGIE_ERROR_LOG_SEVERITY` 环境变量：

```console
$ docker run -it --rm -e ANGIE_BINARY="angie-debug" \
-e ANGIE_ERROR_LOG_SEVERITY="debug" \
docker.angie.software/angie:templated
```

如果切换到不支持调试的可执行文件但在 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 指令中保留 `debug` 级别，Angie 将以 `info` 级别记录条目。

在配置中覆盖 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 而不指定 `debug` 级别将禁用调试日志。在此处，在 [server](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#server) 级别覆盖日志会为单个服务器禁用调试日志：

```nginx
error_log /path/to/log debug;

http {
   server {
     error_log /path/to/log;
    # ...
```

要避免这种情况，请移除覆盖 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 的行，或在其中设置 `debug` 级别：

```nginx
error_log /path/to/log debug;

http {
   server {
     error_log /path/to/log debug;
   #  ...
```

<a id="directive-location"></a>

### 指令位置

[error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 指令的位置会影响收集的调试信息的完整性。

在较低配置级别（例如，在 `server` 或 `location` 块内）指定的指令会覆盖在较高级别（例如，在主配置级别或 `http` 块内）指定的日志设置。

### 为特定服务器禁用调试日志

如果全局启用了调试日志，但为单个服务器指定了不带 `debug` 级别的 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log)，则不会为该服务器收集调试信息。

```nginx
error_log /var/log/angie/error.log debug; # 全局调试日志

http {

    server {

        listen 80;
        server_name example.com;

        error_log /var/log/angie/example.com.error.log;
        # example.com 的调试日志被禁用，文件包含 info 级别

        # ...
    }

    server {

        listen 80;
        server_name another.com;

        # 此服务器将使用全局调试日志
        # ...
    }
}
```

### 在服务器级别保留调试日志

要为特定服务器保留调试信息收集但将其定向到不同的文件，您必须同时指定 `debug` 级别：

```nginx
error_log /var/log/angie/error.log debug; # 全局调试日志

http {

    server {

        listen 80;
        server_name example.com;

        error_log /var/log/angie/example.com.error.log debug;
        # example.com 的调试日志已启用但写入单独的文件

        # ...
    }
}
```

因此，要全局启用调试日志但为单个块覆盖日志文件，也请在这些覆盖中指定 `debug` 级别。否则，如果在 [error_log](https://cn.angie.software//angie/docs/configuration/modules/core.md#error-log) 指令中未指定日志级别，将默认使用 `error` 级别，这些块的调试信息将丢失。

<a id="logging-specific-addresses"></a>

### 记录特定地址

您可以仅为 [指定的客户端地址](https://cn.angie.software//angie/docs/configuration/modules/core.md#debug-connection) 启用调试日志：

```nginx
error_log /path/to/log;

events {
  debug_connection 192.168.1.1;
  debug_connection 192.168.10.0/24;
}
```

<a id="cyclic-memory-buffer"></a>

### 循环内存缓冲区

调试日志可以写入循环内存缓冲区：

```nginx
error_log memory:32m debug;
```

在 `debug` 级别写入内存缓冲区即使在高负载下也不会显著影响性能。在这种情况下，可以使用 GDB 脚本提取日志，例如：

```console
set $log = ngx_cycle->log

while $log->writer != ngx_log_memory_writer
  set $log = $log->next
end

set $buf = (ngx_log_memory_buf_t *) $log->wdata
dump binary memory debug_log.txt $buf->start $buf->end
```

<a id="core-dumps"></a>

## 核心转储

核心转储有助于调查崩溃。在 [联系支持](#troubleshooting) 时请包含它们。对于从 [我们的仓库](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 构建的版本，我们在特殊包中提供调试符号。它们与原始包同名，但添加了 `-dbg` 后缀，例如 `angie-dbg`。

#### NOTE
本节假设您以 `root` 用户身份运行 Angie（推荐）。

<a id="linux-systemd"></a>

### Linux: systemd

要在将 Angie 作为 **systemd** 服务运行时启用核心转储保存（例如，当 [从包安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 时），请修改 `/lib/systemd/system/angie.service` 文件中的 [服务设置](https://www.freedesktop.org/software/systemd/man/systemd.exec.html#Process%20Properties)：

```ini
[Service]
...
LimitCORE=infinity
LimitNOFILE=65535
```

或更新 `/etc/systemd/system.conf` 文件中的 [全局设置](https://www.freedesktop.org/software/systemd/man/systemd-system.conf.html)：

```ini
[Manager]
...
DefaultLimitCORE=infinity
DefaultLimitNOFILE=65535
```

然后重新加载服务配置并重启 Angie 以重现崩溃条件：

```console
$ sudo systemctl daemon-reload
$ sudo systemctl restart angie.service
```

崩溃后，查找核心转储文件：

```console
$ sudo coredumpctl -1 # 可选

   TIME                           PID   UID   GID SIG COREFILE  EXE
   --- |sampledateshort| 11:05:40 GMT   1157     0     0  11 present   /usr/sbin/angie

$ sudo ls -al /var/lib/systemd/coredump/  # 默认位置，另见 /etc/systemd/coredump.conf 和 /etc/systemd/coredump.conf.d/*.conf

  ...
  -rw-r----- 1 root root 177662 Jul 27 11:05 core.angie.0.6135489c850b4fb4a74795ebbc1e382a.1157.1590577472000000.lz4
```

<a id="linux-manual-configuration"></a>

### Linux: 手动配置

检查 `/etc/security/limits.conf` 文件中的 [核心转储设置](https://man7.org/linux/man-pages/man5/limits.conf.5.html)，必要时修改它们：

```none
root soft core 0          # 默认禁用核心转储
root hard core unlimited  # 允许增加大小限制
```

然后使用 [ulimit](https://man7.org/linux/man-pages/man1/ulimit.1p.html) 增加核心转储大小限制，然后重启 Angie 以重现崩溃条件：

```console
$ sudo ulimit -c unlimited
$ sudo cd <Angie 安装目录路径>
$ sudo sbin/angie  # 或 sbin/angie-debug
```

崩溃后，查找核心转储文件：

```console
$ sudo ls -al <Angie 工作目录路径>  # 默认位置，见 /proc/sys/kernel/core_pattern
  ...
  -rw-r----- 1 root root 177662 Jul 27 11:05 core.1157
```

<a id="freebsd"></a>

### FreeBSD

检查 `/etc/sysctl.conf` 文件中的 [核心转储设置](https://man.freebsd.org/cgi/man.cgi?query=sysctl.conf&sektion=5)，必要时修改它们：

```ini
kern.coredump=1                             # 应为 1
kern.corefile=/path/to/core/files/%N.core   # 需要正确路径
```

或在运行时更新设置：

```console
$ sudo sysctl kern.coredump=1
$ sudo sysctl kern.corefile=/path/to/core/files/%N.core
```

然后重启 Angie 以重现崩溃条件。
如果 Angie 作为服务安装：

```console
$ sudo service angie restart
```

如果 Angie 手动安装：

```console
$ sudo cd <Angie 安装目录路径>
$ sudo sbin/angie
```

崩溃后，查找核心转储文件：

```console
$ sudo ls -al <核心转储文件路径>

  ...
  -rw------- 1 root root 9912320 Jul 27 11:05 angie
```


# https://cn.angie.software/angie/docs/installation/external-modules/unbrotli.md

<!-- review: finished -->

<a id="external-unbrotli"></a>

# Unbrotli

`unbrotli` 模块用于为不支持 Brotli 压缩方法的客户端解压来自后端使用 Brotli 压缩(`Content-Encoding: br`)的响应。这在后端以压缩形式存储数据以节省空间的情况下特别有用。

<a id="installation-28"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie:`angie-module-unbrotli`
- Angie PRO:`angie-pro-module-unbrotli`

<a id="directives-89"></a>

## 指令

该模块提供以下指令:

- `unbrotli` – 类似于 [gunzip](https://cn.angie.software//angie/docs/configuration/modules/http/http_gunzip.md#id3)
- `unbrotli_buffers` – 类似于 [gunzip_buffers](https://cn.angie.software//angie/docs/configuration/modules/http/http_gunzip.md#gunzip-buffers)

<a id="loading-the-module-28"></a>

## 加载模块

要使用该模块,必须在 `main{}` 上下文中加载它:

```nginx
load_module modules/ngx_http_unbrotli_filter_module.so;
```

<a id="configuration-example-103"></a>

## 配置示例

```nginx
server {
    listen 80 default_server;
    location / {
        root  /usr/share/angie/html;
        index index.html;
    }

    location /storage {
        unbrotli on;
        proxy_pass http://127.0.0.1:8080;
    }
}

# 后端
server {
    listen 8080;
    location /storage {
        root   /usr/share/angie;
        rewrite ^(.*)$ $1.br break;  # 返回带 .br 后缀的压缩文件
        add_header Content-Encoding br; # 在响应头中指示 Brotli 压缩
    }
}
```

<a id="demonstration-3"></a>

## 演示

让我们放置压缩的测试文件 `war-and-peace.txt.br`:

```console
$ ls -l /usr/share/angie/storage/
total 2292
-rw-r--r-- 1 root root 1115616 Feb 27 16:10 war-and-peace.txt.br
```

如果客户端支持 Brotli,它将接收压缩文件而不进行解压:

```console
$ curl -s -H 'Accept-Encoding: br' -o tmp/war-and-peace.txt localhost/storage/war-and-peace.txt

$ ls -l tmp/
total 1092
-rw-r--r-- 1 asv asv 1115616 Feb 27 16:36 war-and-peace.txt
```

如果客户端不支持 Brotli,:samp:unbrotli 模块将在发送前在服务器上解压文件:

```console
$ curl -s -o tmp/war-and-peace.txt localhost/storage/war-and-peace.txt

$ ls -l tmp/
total 3284
-rw-r--r-- 1 asv asv 3359405 Feb 27 16:39 war-and-peace.txt
```

该文件在发送给客户端之前已由服务器解压。

<a id="additional-information-29"></a>

## 附加信息

详细文档和源代码可在以下位置获取:
[https://github.com/clyfish/ngx_unbrotli](https://github.com/clyfish/ngx_unbrotli)。


# https://cn.angie.software/angie/docs/installation/external-modules/upload.md

<!-- review: finished -->

<a id="external-upload"></a>

# Upload

`upload` 模块提供文件上传功能,支持 RFC 1867 定义的 `multipart/form-data` 编码。它还支持使用 `POST` 方法进行可恢复上传。

<a id="installation-29"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块,请使用以下软件包之一:

- Angie: `angie-module-upload`;
- Angie PRO: `angie-pro-module-upload`。

<a id="loading-the-module-29"></a>

## 加载模块

要使用该模块,必须在 `main{}` 上下文中加载它:

```nginx
load_module modules/ngx_http_upload_module.so;
```

<a id="additional-information-30"></a>

## 其他信息

完整文档和源代码可在以下位置获取:
[https://github.com/fdintino/nginx-upload-module](https://github.com/fdintino/nginx-upload-module)


# https://cn.angie.software/vacancies.md

# 招聘职位

大家好！

我们 Angie Software 正在寻找未来的同事。

如果您是一位非常忙碌的人，那就直奔主题。我们目前最希望招募的，是愿意和我们一起把 Application Delivery Controller（[Angie ADC](https://angie.software/adc/)）做大做强的同事。办公室极佳，薪酬可观，咖啡也还不错。最重要的是，任务有趣，您将与之共事的工程师水平极高。

如果您还有超过 5 分钟的时间，下面是同样的内容，但更详细。

到 2026 年，Angie Software 将迎来成立 4 周年。公司由一群在 2022 年 F5 公司退出俄罗斯市场后失去工作的工程师创办，其中大部分人曾参与 nginx 网络服务器的开发。关于我们前三年的经历，可以阅读 [这里](https://angie.software/news/angie-1-god/)、[这里](https://habr.com/ru/articles/853956/) 和 [这里](https://habr.com/ru/articles/980350/)。

我们从开源版本的 [Angie 网络服务器](https://angie.software/angie/) 起步，我们认为它在功能和质量上都超越了 nginx。随后，我们推出了首款商业产品 [Angie PRO](https://angie.software/angie/pro/)（一个更进阶版本的 Angie），以及基于 Angie PRO 的 ingress controller [ANIC](https://angie.software/anic/)。但我们解决的问题早已超出了"网络服务器"的范畴：我们在 L4–L7 层工作，构建复杂拓扑和全局负载均衡（GSLB），还与 Scala^r 合作打造 virtual appliance 和硬件负载均衡器。

目前我们专注于开发 Application Delivery Controller（[Angie ADC](https://angie.software/adc/)）。它不只是一套负载均衡系统，而是 Citrix NetScaler、F5 Big-IP 等行业巨头的直接、更现代的竞争者（这一点我们已经说过，并且会继续说下去）。产品已经构建完成并投入使用，同时也存在"硬件"版本。现在我们要做的，是让它成为全球市场上最优秀的产品。

是的，正是如此。我们的野心是打造能够在全球市场上具有竞争力的产品，并且正在朝着这个方向全力前进。

下面用几十个字介绍一下在我们这里工作是怎样的体验。

1. 我们尽可能对同事保持透明：公司目前状况如何、问题出在哪里、我们取得了哪些成绩、要往哪里走、不往哪里走，我们都尽量完整地告诉大家。
2. 核心开发流程已经成型。它显然不完美，但是：a) 它符合公司当前的发展阶段；b) 我们正在持续改进它。
3. 工作节奏快，对质量的要求极高，并且会持续提高。因此，我们不招聘有潜力的新人，而是更倾向于成熟的专业人士。
4. 工作氛围是务实的。"Disagree and commit"（保留意见但执行决定）是核心原则。如果您不了解这个概念，请提前查阅。
5. 我们以跨团队的方式协作，并尽量在短周期内聚焦。
6. 每个开发团队每周至少有一次内部进度会议。参与 Angie ADC 的同事会议更频繁。每周还有一次全公司层面的进度同步。
7. 我们要求同事具备高度的自主性。
8. 我们全力支持您——包括财务上的支持——去学习新知识、参加行业大会等等。
9. 办公室非常棒。这一点很重要，因为我们要求大多数同事在办公室工作。这不是任性的要求，请相信我们：我们一开始是完全远程的，但在我们的情况下，远程模式并不奏效。
10. 薪资，用通常的说法，是有竞争力的。公司已列入获认证的 IT 企业名册。
11. 厨房里的三台咖啡机、淋浴间和露台正等着您。

下面简要介绍一下当下对公司尤为重要的几个职位。

## 技术团队

[技术产品负责人](https://cn.angie.software//vacancies/technical-product-manager.md)（Angie ADC）

这个人将决定 Angie ADC 未来如何发展。

这是一个关于战略和市场理解的角色：哪些功能有需求、按什么顺序推出、如何让产品对客户的业务最有价值。在网络技术或负载均衡器方面的经验是很大的加分项，但更重要的是系统化思维和管理产品 backlog 的能力。

[UX/UI 设计师](https://cn.angie.software//vacancies/UX-UI-designer.md)（Angie ADC）

Angie ADC 不仅是一款强大的服务器端产品，也是工程师每天都在使用的界面。我们正在寻找一位能把复杂事物变得清晰的设计师，能为技术人员设计易用的仪表盘和界面。

[高级 Go 开发工程师](https://cn.angie.software//vacancies/senior-go-developer.md)（Angie ADC）

我们正在寻找愿意设计并编写服务器端逻辑的同事。Go 是 Angie ADC 核心组件和管理控制台的基础。任务有趣且规模庞大：高性能、高可靠性、复杂的网络处理。如果您喜欢推敲架构、解决非平凡的问题，这里就是您的舞台。

## 商务团队

[合作伙伴经理](https://cn.angie.software//vacancies/partner-account-manager.md)

适合喜欢建立长期合作关系的人。我们的目标是发展合作伙伴生态：系统集成商、分销商、经销商和技术合作伙伴。需要战略思维、谈判能力以及对 IT 行业格局的理解。

[Presale 工程师](https://cn.angie.software//vacancies/pre-sale-engineer.md)

我们研发与客户之间的纽带。这位同事将帮助客户理解 Angie 解决方案的价值，进行演示、回答技术问题、收集反馈。这里需要良好的沟通能力、宽广的技术视野，以及深入了解公司产品的意愿。

## 如何申请？

很简单：写邮件到 [hr@wbsrv.ru](mailto:hr@wbsrv.ru)。您可以发送简历，或者用几段话介绍自己、您的经验，以及为什么对这个方向感兴趣。

#### NOTE
我们仅接受英文简历，请用英文提交您的简历。

来加入我们，一起做点酷的事情吧。

附言：如果您没有找到合适的职位，也不必沮丧——我们随时可以认识一下，并找到合作的契机。顺便说一句，我们经常就是这样招人的：优秀的专业人士主动写信给我们，然后适合他们的任务总会自己冒出来。


# https://cn.angie.software/angie/docs/configuration/varindex.md

<a id="varindex"></a>

# 内置变量

| [HTTP 模块](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-http)                                                                | [Stream 模块](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-stream)                                                                                                                                             |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [$acme_cert_key_<名称>](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-cert-key-name)                                   | [$acme_cert_key_<name>](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_acme.md#v-s-acme-cert-key-name)                                                                                                            |
| [$acme_cert_<名称>](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-cert-name)                                           | [$acme_cert_<name>](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_acme.md#v-s-acme-cert-name)                                                                                                                    |
| [$acme_hook_challenge](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-hook-challenge)                                 |                                                                                                                                                                                                                                              |
| [$acme_hook_client](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-hook-client)                                       |                                                                                                                                                                                                                                              |
| [$acme_hook_domain](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-hook-domain)                                       |                                                                                                                                                                                                                                              |
| [$acme_hook_keyauth](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-hook-keyauth)                                     |                                                                                                                                                                                                                                              |
| [$acme_hook_name](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-hook-name)                                           |                                                                                                                                                                                                                                              |
| [$acme_hook_token](https://cn.angie.software//angie/docs/configuration/modules/http/http_acme.md#v-acme-hook-token)                                         |                                                                                                                                                                                                                                              |
| [$ancient_browser](https://cn.angie.software//angie/docs/configuration/modules/http/http_browser.md#v-ancient-browser)                                      |                                                                                                                                                                                                                                              |
| [$angie_version](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-angie-version)                                                 | [$angie_version](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-angie-version)                                                                                                                              |
| [$arg_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-arg)                                                              |                                                                                                                                                                                                                                              |
| [$args](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-args)                                                                   |                                                                                                                                                                                                                                              |
| [$binary_remote_addr](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-binary-remote-addr)                                       | [$binary_remote_addr](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-binary-remote-addr)                                                                                                                    |
| [$body_bytes_sent](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-body-bytes-sent)                                             |                                                                                                                                                                                                                                              |
|                                                                                                                                                             | [$bytes_received](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-bytes-received)                                                                                                                            |
| [$bytes_sent](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-bytes-sent)                                                       | [$bytes_sent](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-bytes-sent)                                                                                                                                    |
| [$connection](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-connection)                                                       | [$connection](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-connection)                                                                                                                                    |
| [$connection_requests](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-connection-requests)                                     |                                                                                                                                                                                                                                              |
| [$connection_time](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-connection-time)                                             |                                                                                                                                                                                                                                              |
| [$connections_active](https://cn.angie.software//angie/docs/configuration/modules/http/http_stub_status.md#v-connections-active)                            |                                                                                                                                                                                                                                              |
| [$connections_reading](https://cn.angie.software//angie/docs/configuration/modules/http/http_stub_status.md#v-connections-reading)                          |                                                                                                                                                                                                                                              |
| [$connections_writing](https://cn.angie.software//angie/docs/configuration/modules/http/http_stub_status.md#v-connections-writing)                          |                                                                                                                                                                                                                                              |
| [$connections_waiting](https://cn.angie.software//angie/docs/configuration/modules/http/http_stub_status.md#v-connections-waiting)                          |                                                                                                                                                                                                                                              |
| [$content_length](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-content-length)                                               |                                                                                                                                                                                                                                              |
| [$content_type](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-content-type)                                                   |                                                                                                                                                                                                                                              |
| [$cookie_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-cookie)                                                        |                                                                                                                                                                                                                                              |
| [$date_local](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssi.md#v-date-local)                                                    |                                                                                                                                                                                                                                              |
| [$date_gmt](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssi.md#v-date-gmt)                                                        |                                                                                                                                                                                                                                              |
| [$document_root](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-document-root)                                                 |                                                                                                                                                                                                                                              |
| [$document_uri](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-document-uri)                                                   |                                                                                                                                                                                                                                              |
| [$fastcgi_script_name](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#v-fastcgi-script-name)                              |                                                                                                                                                                                                                                              |
| [$fastcgi_path_info](https://cn.angie.software//angie/docs/configuration/modules/http/http_fastcgi.md#v-fastcgi-path-info)                                  |                                                                                                                                                                                                                                              |
| [$gzip_ratio](https://cn.angie.software//angie/docs/configuration/modules/http/http_gzip.md#v-gzip-ratio)                                                   |                                                                                                                                                                                                                                              |
| [$host](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-host)                                                                   |                                                                                                                                                                                                                                              |
| [$hostname](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-hostname)                                                           | [$hostname](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-hostname)                                                                                                                                        |
| [$http2](https://cn.angie.software//angie/docs/configuration/modules/http/http_v2.md#v-http2)                                                               |                                                                                                                                                                                                                                              |
| [$http3](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#v-http3)                                                               |                                                                                                                                                                                                                                              |
| [$http_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-http)                                                            |                                                                                                                                                                                                                                              |
| [$https](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-https)                                                                 |                                                                                                                                                                                                                                              |
| [$invalid_referer](https://cn.angie.software//angie/docs/configuration/modules/http/http_referer.md#v-invalid-referer)                                      |                                                                                                                                                                                                                                              |
| [$is_args](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-is-args)                                                             |                                                                                                                                                                                                                                              |
| [$is_request_port](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-is-request-port)                                             |                                                                                                                                                                                                                                              |
| [$limit_conn_status](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_conn.md#v-limit-conn-status)                               | [$limit_conn_status](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_limit_conn.md#v-s-limit-conn-status)                                                                                                          |
| [$limit_rate](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-limit-rate)                                                       |                                                                                                                                                                                                                                              |
| [$limit_req_status](https://cn.angie.software//angie/docs/configuration/modules/http/http_limit_req.md#v-limit-req-status)                                  |                                                                                                                                                                                                                                              |
| [$memcached_key](https://cn.angie.software//angie/docs/configuration/modules/http/http_memcached.md#v-memcached-key)                                        |                                                                                                                                                                                                                                              |
| [$metric_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#v-metric-zone)                                             |                                                                                                                                                                                                                                              |
| [$metric_<name>_key 和 $metric_<name>_value](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#v-metric-zone-key)              |                                                                                                                                                                                                                                              |
| [$metric_<name>_key 和 $metric_<name>_value](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#v-metric-zone-value)            |                                                                                                                                                                                                                                              |
| [$metric_<name>_value_<metric>](https://cn.angie.software//angie/docs/configuration/modules/http/http_metric.md#v-metric-zone-value-metric)                 |                                                                                                                                                                                                                                              |
| [$modern_browser](https://cn.angie.software//angie/docs/configuration/modules/http/http_browser.md#v-modern-browser)                                        |                                                                                                                                                                                                                                              |
|                                                                                                                                                             | [$mqtt_preread_clientid](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#v-mqtt-preread-clientid)                                                                                                  |
|                                                                                                                                                             | [$mqtt_preread_username](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_mqtt_preread.md#v-mqtt-preread-username)                                                                                                  |
| [$msec](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-msec)                                                                   | [$msec](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-msec)                                                                                                                                                |
| [$msie](https://cn.angie.software//angie/docs/configuration/modules/http/http_browser.md#v-msie)                                                            |                                                                                                                                                                                                                                              |
| [协议](https://cn.angie.software//angie/docs/configuration/modules/mail/mail_auth_http.md#v-m-protocol)                                                       |                                                                                                                                                                                                                                              |
| [$nginx_version](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-nginx-version)                                                 | [$nginx_version](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-nginx-version)                                                                                                                              |
| [$p8s_value](https://cn.angie.software//angie/docs/configuration/modules/http/http_prometheus.md#v-p8s-value)                                               |                                                                                                                                                                                                                                              |
| [$pid](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-pid)                                                                     | [$pid](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-pid)                                                                                                                                                  |
| [$pipe](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-pipe)                                                                   |                                                                                                                                                                                                                                              |
| [$proxy_add_x_forwarded_for](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#v-proxy-add-x-forwarded-for)                    |                                                                                                                                                                                                                                              |
| [$proxy_host](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#v-proxy-host)                                                  |                                                                                                                                                                                                                                              |
| [$proxy_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_proxy.md#v-proxy-port)                                                  |                                                                                                                                                                                                                                              |
|                                                                                                                                                             | [$protocol](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-protocol)                                                                                                                                        |
| [$proxy_protocol_addr](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-proxy-protocol-addr)                                     | [$proxy_protocol_addr](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-proxy-protocol-addr)                                                                                                                  |
| [$proxy_protocol_port](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-proxy-protocol-port)                                     | [$proxy_protocol_port](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-proxy-protocol-port)                                                                                                                  |
| [$proxy_protocol_server_addr](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-proxy-protocol-server-addr)                       | [$proxy_protocol_server_addr](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-proxy-protocol-server-addr)                                                                                                    |
| [$proxy_protocol_server_port](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-proxy-protocol-server-port)                       | [$proxy_protocol_server_port](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-proxy-protocol-server-port)                                                                                                    |
| [$proxy_protocol_tlv_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-proxy-protocol-tlv)                                | [$proxy_protocol_tlv_<name>](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-proxy-protocol-tlv)                                                                                                             |
| [$query_string](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-query-string)                                                   |                                                                                                                                                                                                                                              |
| [$quic_connection](https://cn.angie.software//angie/docs/configuration/modules/http/http_v3.md#v-quic-connection)                                           |                                                                                                                                                                                                                                              |
|                                                                                                                                                             | [$rdp_cookie](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#v-rdp-cookie),<br/>[$rdp_cookie_<name>](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_rdp_preread.md#id5) |
| [$realip_remote_addr](https://cn.angie.software//angie/docs/configuration/modules/http/http_realip.md#v-realip-remote-addr)                                 | [$realip_remote_addr](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_realip.md#v-s-realip-remote-addr)                                                                                                            |
| [$realip_remote_port](https://cn.angie.software//angie/docs/configuration/modules/http/http_realip.md#v-realip-remote-port)                                 | [$realip_remote_port](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_realip.md#v-s-realip-remote-port)                                                                                                            |
| [$realpath_root](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-realpath-root)                                                 |                                                                                                                                                                                                                                              |
| [$remote_addr](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-remote-addr)                                                     | [$remote_addr](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-remote-addr)                                                                                                                                  |
| [$remote_port](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-remote-port)                                                     | [$remote_port](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-remote-port)                                                                                                                                  |
| [$remote_user](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-remote-user)                                                     |                                                                                                                                                                                                                                              |
| [$request](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request)                                                             |                                                                                                                                                                                                                                              |
| [$request_body](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-body)                                                   |                                                                                                                                                                                                                                              |
| [$request_body_file](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-body-file)                                         |                                                                                                                                                                                                                                              |
| [$request_completion](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-completion)                                       |                                                                                                                                                                                                                                              |
| [$request_filename](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-filename)                                           |                                                                                                                                                                                                                                              |
| [$request_id](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-id)                                                       |                                                                                                                                                                                                                                              |
| [$request_length](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-length)                                               |                                                                                                                                                                                                                                              |
| [$request_method](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-method)                                               |                                                                                                                                                                                                                                              |
| [$request_port](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-port)                                                   |                                                                                                                                                                                                                                              |
| [$request_time](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-time)                                                   |                                                                                                                                                                                                                                              |
| [$request_uri](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-request-uri)                                                     |                                                                                                                                                                                                                                              |
| [$scheme](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-scheme)                                                               |                                                                                                                                                                                                                                              |
| [$secure_link](https://cn.angie.software//angie/docs/configuration/modules/http/http_secure_link.md#v-secure-link)                                          |                                                                                                                                                                                                                                              |
| [$secure_link_expires](https://cn.angie.software//angie/docs/configuration/modules/http/http_secure_link.md#v-secure-link-expires)                          |                                                                                                                                                                                                                                              |
| [$sent_http_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-sent-http)                                                  |                                                                                                                                                                                                                                              |
| [$sent_body](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-sent-body)                                                         |                                                                                                                                                                                                                                              |
| [$sent_trailer_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-sent-trailer)                                            |                                                                                                                                                                                                                                              |
| [$server_addr](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-server-addr)                                                     | [$server_addr](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-server-addr)                                                                                                                                  |
| [$server_name](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-server-name)                                                     |                                                                                                                                                                                                                                              |
| [$server_port](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-server-port)                                                     | [$server_port](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-server-port)                                                                                                                                  |
| [$server_protocol](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-server-protocol)                                             |                                                                                                                                                                                                                                              |
|                                                                                                                                                             | [$session_time](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-session-time)                                                                                                                                |
| [$slice_range](https://cn.angie.software//angie/docs/configuration/modules/http/http_slice.md#v-slice-range)                                                |                                                                                                                                                                                                                                              |
| [$ssl_alpn_protocol](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-alpn-protocol)                                      | [$ssl_alpn_protocol](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-alpn-protocol)                                                                                                                 |
| [$ssl_cipher](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-cipher)                                                    | [$ssl_cipher](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-cipher)                                                                                                                               |
| [$ssl_ciphers](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-ciphers)                                                  | [$ssl_ciphers](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-ciphers)                                                                                                                             |
| [$ssl_client_escaped_cert](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-escaped-cert)                          |                                                                                                                                                                                                                                              |
|                                                                                                                                                             | [$ssl_client_cert](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-client-cert)                                                                                                                     |
| [$ssl_client_fingerprint](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-fingerprint)                            | [$ssl_client_fingerprint](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-client-fingerprint)                                                                                                       |
| [$ssl_client_i_dn](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-i-dn)                                          | [$ssl_client_i_dn](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-client-i-dn)                                                                                                                     |
| [$ssl_client_i_dn_legacy](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-i-dn-legacy)                            |                                                                                                                                                                                                                                              |
| [$ssl_client_raw_cert](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-raw-cert)                                  | [$ssl_client_raw_cert](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-client-raw-cert)                                                                                                             |
| [$ssl_client_s_dn](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-s-dn)                                          | [$ssl_client_s_dn](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-client-s-dn)                                                                                                                     |
| [$ssl_client_s_dn_legacy](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-s-dn-legacy)                            |                                                                                                                                                                                                                                              |
| [$ssl_client_serial](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-serial)                                      | [$ssl_client_serial](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-client-serial)                                                                                                                 |
| [$ssl_client_sigalg](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-sigalg)                                      | [$ssl_client_sigalg](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-client-sigalg)                                                                                                                 |
| [$ssl_client_v_end](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-v-end)                                        | [$ssl_client_v_end](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-client-v-end)                                                                                                                   |
| [$ssl_client_v_remain](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-v-remain)                                  | [$ssl_client_v_remain](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-client-v-remain)                                                                                                             |
| [$ssl_client_v_start](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-v-start)                                    | [$ssl_client_v_start](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-client-v-start)                                                                                                               |
| [$ssl_client_verify](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-client-verify)                                      | [$ssl_client_verify](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-client-verify)                                                                                                                 |
| [$ssl_curve](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-curve)                                                      | [$ssl_curve](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-curve)                                                                                                                                 |
| [$ssl_curves](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-curves)                                                    | [$ssl_curves](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-curves)                                                                                                                               |
| [$ssl_early_data](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-early-data)                                            | [$ssl_early_data](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-early-data)                                                                                                                       |
| [$ssl_encrypted_hello](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-encrypted-hello)                                  | [$ssl_encrypted_hello](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-encrypted-hello)                                                                                                             |
|                                                                                                                                                             | [$ssl_preread_alpn_protocols](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#v-ssl-preread-alpn-protocols)                                                                                         |
|                                                                                                                                                             | [$ssl_preread_protocol](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#v-ssl-preread-protocol)                                                                                                     |
|                                                                                                                                                             | [$ssl_preread_server_name](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl_preread.md#v-ssl-preread-server-name)                                                                                               |
| [$ssl_protocol](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-protocol)                                                | [$ssl_protocol](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-protocol)                                                                                                                           |
| [$ssl_server_name](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-server-name)                                          | [$ssl_server_name](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-server-name)                                                                                                                     |
| [$ssl_server_cert_type](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-server-cert-type)                                | [$ssl_server_cert_type](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-server-cert-type)                                                                                                           |
| [$ssl_session_id](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-session-id)                                            | [$ssl_session_id](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-session-id)                                                                                                                       |
| [$ssl_session_reused](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-session-reused)                                    | [$ssl_session_reused](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-session-reused)                                                                                                               |
| [$ssl_sigalg](https://cn.angie.software//angie/docs/configuration/modules/http/http_ssl.md#v-ssl-sigalg)                                                    | [$ssl_sigalg](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_ssl.md#v-s-ssl-sigalg)                                                                                                                               |
| [$status](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-status)                                                               | [$status](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-status)                                                                                                                                            |
| [$sticky_sessid](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-sticky-sessid)                                         | [$sticky_sessid](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#v-s-sticky-sessid)                                                                                                                    |
| [$sticky_sid](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-sticky-sid)                                               | [$sticky_sid](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#v-s-sticky-sid)                                                                                                                          |
| [$time_iso8601](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-time-iso8601)                                                   | [$time_iso8601](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-time-iso8601)                                                                                                                                |
| [$time_local](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-time-local)                                                       | [$time_local](https://cn.angie.software//angie/docs/configuration/modules/stream/index.md#v-s-time-local)                                                                                                                                    |
| [$tcpinfo_rtt, $tcpinfo_rttvar, $tcpinfo_snd_cwnd, $tcpinfo_rcv_space](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-tcpinfo) |                                                                                                                                                                                                                                              |
| [$uid_got](https://cn.angie.software//angie/docs/configuration/modules/http/http_userid.md#v-uid-got)                                                       |                                                                                                                                                                                                                                              |
| [$uid_reset](https://cn.angie.software//angie/docs/configuration/modules/http/http_userid.md#v-uid-reset)                                                   |                                                                                                                                                                                                                                              |
| [$uid_set](https://cn.angie.software//angie/docs/configuration/modules/http/http_userid.md#v-uid-set)                                                       |                                                                                                                                                                                                                                              |
| [$upstream_addr](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-addr)                                         | [$upstream_addr](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#v-s-upstream-addr)                                                                                                                    |
| [$upstream_bytes_received](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-bytes-received)                     | [$upstream_bytes_received](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#v-s-upstream-bytes-received)                                                                                                |
| [$upstream_bytes_sent](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-bytes-sent)                             | [$upstream_bytes_sent](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#v-s-upstream-bytes-sent)                                                                                                        |
| [$upstream_cache_status](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-cache-status)                         |                                                                                                                                                                                                                                              |
| [$upstream_cache_key](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-cache-key)                               |                                                                                                                                                                                                                                              |
| [$upstream_connect_time](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-connect-time)                         | [$upstream_connect_time](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#v-s-upstream-connect-time)                                                                                                    |
| [$upstream_cookie_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-cookie)                              |                                                                                                                                                                                                                                              |
|                                                                                                                                                             | [$upstream_first_byte_time](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#v-s-upstream-first-byte-time)                                                                                              |
| [$upstream_header_time](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-header-time)                           |                                                                                                                                                                                                                                              |
| [$upstream_http_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-http)                                  |                                                                                                                                                                                                                                              |
| [$upstream_request_method](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-request-method)                     |                                                                                                                                                                                                                                              |
| [$upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#v-upstream-probe)                           | [$upstream_probe (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#v-s-upstream-probe)                                                                                                      |
| [$upstream_probe_body (PRO)](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream_probe.md#v-upstream-probe-body)                 |                                                                                                                                                                                                                                              |
|                                                                                                                                                             | [$upstream_probe_response (PRO)](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream_probe.md#v-s-upstream-probe-response)                                                                                    |
| [$upstream_response_length](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-response-length)                   |                                                                                                                                                                                                                                              |
| [$upstream_response_time](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-response-time)                       |                                                                                                                                                                                                                                              |
|                                                                                                                                                             | [$upstream_session_time](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#v-s-upstream-session-time)                                                                                                    |
| [$upstream_status](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-status)                                     |                                                                                                                                                                                                                                              |
| [$upstream_sticky_status](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-sticky-status)                       | [$upstream_sticky_status](https://cn.angie.software//angie/docs/configuration/modules/stream/stream_upstream.md#v-s-upstream-sticky-status)                                                                                                  |
| [$upstream_trailer_<name>](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-trailer)                            |                                                                                                                                                                                                                                              |
| [$upstream_queue_time](https://cn.angie.software//angie/docs/configuration/modules/http/http_upstream.md#v-upstream-queue-time)                             |                                                                                                                                                                                                                                              |
| [$uri](https://cn.angie.software//angie/docs/configuration/modules/http/index.md#v-uri)                                                                     |                                                                                                                                                                                                                                              |


# https://cn.angie.software/news/events/veb-server-angie-god-spustya-novie-vozmozhnosti.md

# Angie Web服务器一年后：新机遇与未来规划

*27.11.2023*

Angie开发负责人Valentin Bartenyev将在HighLoad 2023大会上回顾项目第一年的发展历程。

![替代文本](../../_images/news/veb-server-angie-god-spustya-novie-vozmozhnosti.jpeg)![替代文本](../../_images/news/veb-server-angie-god-spustya-novie-vozmozhnosti.jpeg)

即将到来的HighLoad 2023大会上，Angie开发负责人Valentin Bartenyev将详细介绍我们项目的第一年：开发团队专注的新功能、用于支持用户的基础设施，以及Angie web服务器中出现的令人振奋的新特性。我们还将简要讨论未来发展，包括我们的规划以及在近期乃至更远未来可能会推出的内容。

莫斯科，11月27日上午10:00，莫斯科厅（2楼），[详情请点击](https://highload.ru/moscow/2023/abstracts/11279)。


# https://cn.angie.software/news/releases/veb-server-angie-poluchil-podderzhku-acme.md

# Web服务器Angie新增ACME支持

*27.03.2024*

新增了http_acme模块，实现了对ACME(自动化证书管理环境)协议的支持，简化了网站数字证书的工作流程，
无需使用像EFF Certbot这样的第三方解决方案。

"Web Server"公司发布了开源Web服务器 [Angie 1.5.0](https://cn.angie.software/angie/docs/oss_changes/#angie-1-5-0) 和其商业版本 [Angie PRO 1.5.0](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-5-0/)。

此次发布的关键变更之一是新增了 [http_acme模块](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-5-0/)，该模块实现了对ACME
（自动化证书管理环境）协议的支持。这个模块简化了网站数字证书的工作流程，无需使用像EFF Certbot这样的第三方解决方案，
使Angie能够与Caddy等解决方案竞争。

俄罗斯Web服务器Angie的开发部门负责人Valentin Bartenev表示： *"Web服务器内置的ACME支持可以自动获取签名证书
并在需要时进行续期，简化了设置过程，为现在广泛使用的HTTPS启用TLS加密。用户无需使用额外的第三方解决方案，
这不仅节省了时间，还能避免潜在的错误。"*

Valentin解释道： *"在当前阶段，ACME模块实现了最基本的功能，可以在简单配置中运行。我们计划在今年内扩展支持，
提供完整的功能范围。"*

Angie PRO的新版本还包括代理服务器的"排空"模式，该模式可在服务器减负时保持会话亲和性，从而确保负载均衡器的
平稳运行。

其他改进包括增强了统计API、简化配置的 [auto_redirect指令](https://cn.angie.software/configuration/modules/) 、对RHEL 8的支持以及新增OpenTelemetry模块。
此外，本次发布还包含了最近发布的nginx 1.25.4版本的所有更改。


# https://cn.angie.software/news/releases/veb-server-angie-pro-poluchil-obnovlenie-1.2.0.md

# Web服务器Angie PRO发布1.2.0更新

*19.08.2023*

"Web Server"公司宣布发布其俄罗斯Web服务器Angie PRO 1.2.0新版本。

"Web Server"公司宣布发布其俄罗斯Web服务器Angie PRO 1.2.0新版本。

更新后的 [Angie PRO](https://cn.angie.software/angie/pro/) 版本包含多项重要变更。特别是，代理模块现在支持缓存分片（水平分区），这提高了数据缓存效率，提升了性能，并简化了扩展。现在可以在不重新加载配置的情况下动态管理负载均衡参数，减少了Web服务器的停机时间，简化了其在现代基础设施中的应用。为代理服务器添加了主动健康检查，有助于自动优化服务器之间的请求分配并减少延迟。此外，新版本支持现代HTTP/3协议。

正如"Web Server"公司首席执行官Zaur Abasmirzoev所述，Angie PRO的更新对于"Web Server"公司在产品开发和加强其在俄罗斯及国外市场地位方面是重要的一步。"我们将继续致力于改进我们的产品，为客户提供最佳解决方案，"Zaur Abasmirzoev强调。

自1.1.0版本发布以来，我们添加了最受欢迎的动态模块，如：

* auth-jwt。通过验证提供的JSON Web Token (JWT)实现客户端授权。
* cache-purge。允许清除FastCGI、代理、SCGI和uWSGI缓存内容。
* keyval。支持使用键值对中的值作为变量。
* lua。允许在Angie配置中使用Lua语言。
* postgres。包含PostgreSQL数据库的直接支持。
* redis2。为HTTP上游添加Redis 2.0协议支持。

此外，Angie PRO 1.2.0新版本增加了对FSTEC认证的操作系统Alt 8 SP（服务器）的支持。同时，Angie PRO现在可在Alma Linux 8和9版本、Alpine 3.18、CentOS 7、8和9版本、Debian "bookworm"以及Ubuntu 23.04（Lunar Lobster）上使用。


# https://cn.angie.software/news/releases/veb-server-angie-pro-poluchil-obnovlenie-1.3.0.md

# Web服务器Angie PRO发布1.3.0更新

*03.10.2023*

"Web Server"公司宣布发布俄罗斯Web服务器Angie PRO 1.3.0新版本。

"Web Server"公司宣布发布俄罗斯Web服务器Angie PRO 1.3.0新版本。

更新版本包含几项重要变更：

支持代理服务器的条件连接绑定——这使得可以代理使用Microsoft技术（如Exchange或Active Directory）进行身份验证的NTLM连接。
新增了一种基于计算服务器对请求的平均响应时间的代理服务器负载均衡方法（这在替换Citrix ADC、F5 BigIP等类似解决方案时特别相关），以及API中相应的指标。
各种监控嵌入功能，包括可视化的Web监控页面——Console Light，用于显示服务器的关键性能和负载指标。

最后，Angie PRO 1.3.0版本包含了开源Web服务器Angie 1.3.0的所有最新更新，具体如下。

主要创新之一是支持在同一配置上下文（"location"指令）中使用多个URI请求匹配模式。这减少了配置量并降低了用户出错的可能性。此外，新版本扩展了以Prometheus格式获取统计数据的功能，通过使用标签和类型的附加模板配置，简化了在现代基础设施中构建监控系统的过程。

其他值得注意的创新包括：

个别Web服务器进程的配置版本控制，这有助于监控、故障排查和问题解决；
通过HTTP API获取当前服务器配置的功能。

最后，之前在1.1.0版本中仅针对HTTP添加的两项创新现在也可在数据流环境（"stream"模块）中使用：

代理服务器的统计数据，扩展了Angie的指标功能覆盖范围；
代理服务器地址列表对DNS变更的动态适应，支持SRV记录，实现更快的服务扩展并在不过度消耗资源的情况下更改设置。


# https://cn.angie.software/news/integrations/veb-server-angie-pro-voshel-v-reestr-otechestvennogo-PO.md

# Web服务器Angie PRO被列入国产软件名录

*24.05.2023*

由前nginx团队开发的Web服务器Angie PRO已被列入国产软件名录。

由前nginx团队开发的Web服务器Angie PRO已被列入国产软件名录。该产品已被添加到俄罗斯电子计算机和数据库软件统一注册表中，注册号为17604。

如今，Angie PRO是俄罗斯联邦政府认定的对国家经济发展至关重要且无法在常规市场机制下复制的几类软件的核心组件——流量均衡器（替代Citrix ADC/Netscaler、Radware、F5 BIG-IP）和网络基础设施管理监控系统。

"Angie PRO被列入国产软件名录将很快使国内多个政府机构和国有企业能够替换国外解决方案。目前，多家大型企业也正在测试Angie PRO，计划在不久的将来转向使用该产品，""Web Server"公司首席执行官Zaur Abasmirzoev表示。

此前，Angie PRO已通过与RED OS、Astra Linux Special Edition和Alt Server 10操作系统的兼容性认证。因此，Angie PRO是同类产品中唯一一个已确认与这三个俄罗斯操作系统都兼容的产品。

到2023年底，计划更新Angie PRO的多项功能，包括：无需停止服务器即可动态管理配置行为的机制、用于构建CDN基础设施的应用数据缓存管理、用于高可用性和高性能配置的集群模式功能、对现代HTTP/3协议的支持，以及视频内容传输功能（包括直播），同时还将增加新的负载均衡方法、支持GOST加密，并与网络攻击防护服务集成。

"Web Server"公司还计划开发额外的应用程序，包括带有仪表板指标的Angie PRO集群统一界面，以及适用于所有安装的可视化配置编辑器。


# https://cn.angie.software/news/releases/veb-server-angie-s-otkritim-ishodnim-kodom-1.3.0.md

# 开源代码的Web服务器Angie更新至版本1.3.0

*19.09.2023*

公司“Web服务器”宣布发布俄罗斯开源Web服务器Angie 1.3.0的新版本。

公司“Web服务器”宣布发布俄罗斯开源Web服务器Angie 1.3.0的新版本。更新版本包含多个重要更改，以简化服务器配置和监控。

主要新增功能之一是支持在相同配置上下文（“location”指令）中为多个URI请求匹配模式。这减少了所需的配置量，并降低了用户出错的可能性。此外，Angie的新版本引入了Prometheus格式的统计信息，方便在现代基础设施中构建监控系统。

其他一些显著创新包括：

* 为各个Web服务器进程提供配置版本控制，使监控、故障排除和问题解决变得更加容易；
* 通过HTTP API检索当前服务器配置的能力。

最后，之前仅在Angie 1.1.0中为HTTP添加的两个创新现在也可以在数据流上下文中使用（“stream”模块）：

* 代理服务器的统计信息，扩展了Angie功能的指标覆盖范围；
* 动态调整代理服务器地址列表以应对DNS变化，考虑SRV记录，从而实现服务的快速扩展和在不浪费资源的情况下更改设置。


# https://cn.angie.software/news/integrations/veb-server-angie-stal-uchastnikom-rossijskogo-GitHub.md

# Angie Web服务器成为"俄罗斯版GitHub"的参与者

*06.06.2023*

由前nginx团队开发的俄罗斯Web服务器Angie已成为创建俄罗斯代码仓库实验的参与者。俄罗斯数字发展部于2023年5月31日发布了相关命令。

由前nginx团队开发的俄罗斯Web服务器Angie已成为创建俄罗斯代码仓库实验的参与者。俄罗斯数字发展部于2023年5月31日发布了相关命令。

Web Server公司首席执行官Zaur Abasmirzoev表示："对我们公司而言，参与创建俄罗斯代码仓库的实验是一个绝佳机会，我们可以作为这项倡议的测试者，并在产品更新迭代过程中评估其性能。对国家来说，拥有一个可信赖的软件产品来源非常重要，而俄罗斯代码仓库就可以成为这样的平台。这将使国内公司能够上传其源代码库，同时也让关键信息基础设施（CII）实体能够安装安全的软件。与此同时，我们认为有必要解决俄罗斯代码仓库的法律问题，至少在许可证方面需要明确，"这位专家指出。


# https://cn.angie.software/news/releases/vishli-obnovlenia-web-servera-angie-i-angie-pro.md

# Angie和Angie PRO Web服务器发布更新

*28.06.2024*

新版本显著扩展了负载均衡功能，并继续开发ACME模块。

Web Server公司发布了开源Web服务器 [Angie 1.6.0](https://cn.angie.software/oss_changes/#angie-1-6-0) 和其商业版本 [Angie PRO 1.6.0](https://cn.angie.software/pro_changes/#angie-pro-1-6-0) 的新版本。

新版本显著增强了负载均衡功能：

- 在"stream"模块中引入了TCP和UDP流量均衡的会话绑定。
- 增加了从RDP连接中提取客户端cookie信息的功能，允许记录日志并将客户端与特定RDP服务器关联。
- 主动服务器健康检查的"persistent"选项允许在配置重载后跳过强制检查（如果服务器之前已经检查过），这有助于在配置更改后更快地使服务器上线。
- 新的"feedback"负载均衡方法基于从代理服务器或外部服务收到的系数在HTTP服务器之间分配负载。

"在此次更新中，我们继续增强服务器的负载均衡能力。特别是，新的'feedback'负载均衡方法将允许基于从服务器收集的任意指标（如CPU负载、可用内存、队列长度等）来分配流量。关键在于负载均衡器基于动态权重运作，而形成系数的标准可以由用户自行开发，"Angie Web服务器开发部门负责人Valentin Bartenyev表示。

"RDP连接均衡的改进是基于我们客户的反馈而做出的。我们经常强调我们对产品路线图开发的灵活方法；如果客户表达需求，我们就会采取行动。总的来说，这个功能展示了我们致力于为国内快速发展的企业VDI市场提供高度可靠的解决方案，Web Server,有限责任公司总监Zaur Abasmirzoev补充道。

在新版本中，ACME模块的开发持续进行；修复了一些错误和问题，并引入了为单个虚拟服务器发行多种类型证书的功能。在未来的版本中，该模块的功能将进一步扩展，以覆盖自动HTTPS配置和动态证书发行的全部功能。

此外，Angie现在与最新版本的nginx具有向后兼容性，获得了基于SNI扩展的"stream"模块中虚拟服务器支持、TLS协议支持，以及将连接处理从L4流模块重定向到其他模块进行L7级别均衡和处理的能力。

此前，Angie Web服务器获得了对ACME（自动证书管理环境）协议的支持，这简化了网站数字证书的工作流程，消除了对EFF Certbot等第三方解决方案的需求，使Angie在这方面可以与Caddy等解决方案竞争。


# https://cn.angie.software/news/releases/vishli-obnovleniya-otechestvennogo-reshenia-ANIC.md

# 国产云环境Kubernetes解决方案Angie Ingress Controller (ANIC)发布更新

*02.03.2024*

Web Server公司发布了用于Kubernetes容器化应用流量管理的俄罗斯解决方案Angie Ingress Controller (ANIC) 0.3.0版本。

Web Server公司发布了用于Kubernetes容器化应用流量管理的俄罗斯 [解决方案](https://angie.software/anic/docs/) Angie Ingress Controller (ANIC) 0.3.0版本。此次重要更新包含多项关键改进，将提升用户体验并扩展产品功能。

ANIC 0.3.0的主要创新之一是增加了对注解 `angie.software/force-ssl-redirect` 的支持，该功能允许用户强制将不安全的HTTP流量重定向到安全的HTTPS，从而纠正潜在的SSL使用错误。

此外，新版本在Helm charts中引入了CRDs（自定义资源定义），如Virtual Server、Virtual Server Route、TransportServer和Policies。现在，使用Helm的用户可以在其项目中利用这些定义，与标准Ingress资源相比，显著扩展了Web服务器的配置能力。

此前，ANIC已 [被列入](https://cn.angie.software/news/integrations/ingress-controller-anic-voshel-v-reestr-otechestvennogo-po/) 国产软件注册表（2023年12月29日，编号20891）。这证实了该产品的高质量以及符合本地标准和要求。

如今，ANIC可以作为Ingress资源部署在任何Kubernetes平台上。ANIC基于Angie PRO web服务器，这使得用户能够使用俄罗斯解决方案创建安全、可扩展、高性能的环境，并享受俄语专业迁移和支持服务。


# https://cn.angie.software/news/releases/vishli-obnovleniya-rossiiskogo-veb-servera-Angie-Pro.md

# 俄罗斯网络服务器Angie PRO更新发布

*21.12.2023*

Web Server公司宣布发布新版本的俄罗斯网络服务器Angie PRO 1.4.0。

Web Server公司宣布发布新版本的俄罗斯网络服务器Angie PRO 1.4.0。此版本包含以下重要变更：

在HTTP模块中：

* 增加了代理服务器的请求队列—这提高了服务质量。相应的指标已集成到统计API中。
* 实现了sticky指令的学习模式，其中客户端会话基于代理服务器的响应创建—这允许在应用程序级别集成会话绑定机制。

在stream模块中：

* 负载均衡现在支持三种新的可配置模式，用于计算来自代理服务器的平均响应时间；相应的指标也已集成到统计API中。
* 增加了代理服务器的主动检查，扩展了监控功能；相应的指标也可通过统计API获取。

在配置API中，引入了动态配置、添加和移除代理服务器的功能，且state指令将所有此类更改保存到文件中；HTTP模块中此前已添加类似功能。

## 来自Angie OSS 1.4.0的补充

此外，Angie PRO还包含了最近发布的开源版本Angie 1.4.0中的一些适配功能：

* 增加了对代理服务器HTTP/3连接的支持；现在服务器和客户端可以独立使用HTTP/1.1、HTTP/2或HTTP/3。
* 实现了负载渐增模式，允许平滑引入从故障中恢复的代理服务器。
* 引入了限制MP4流媒体的指令，以减少服务器基础设施的负载。
* 改进了对物联网（IoT）解决方案中常用的MQTT协议的负载均衡支持。

## 软件包和模块

我们的 [软件包集合](https://wbsrv.ru/angie-pro/docs/installation/#install-dynamicmodules/) 增加了两个第三方模块：[auth-ldap](https://github.com/kvspb/nginx-auth-ldap)，它添加了支持多服务器的LDAP认证，以及 [ModSecurity连接器](https://github.com/owasp-modsecurity/ModSecurity-nginx/)，这是一个用于保护网站免受网络攻击的流行WAF工具。我们还 [认证了](https://t.me/angie_software/29/) 对"ROSA Chrome"系统的支持，并为其发布了 [软件包](https://wbsrv.ru/angie-pro/docs/installation/#install-packages/)。

最后，我们最近 [开放了](https://github.com/webserver-llc/angie-console-light/) Console Light的源代码，并在此版本中将控制台更新到1.2.0版本。


# https://cn.angie.software/news/releases/vishli-obnovleniya-rossiiskogo-veb-servera-s-otkrytym-iskhodnym-kodom-Angie.md

# 俄罗斯开源Web服务器Angie发布更新

*12.12.2023*

"Web Server"公司发布了俄罗斯开源Web服务器Angie 1.4.0新版本。

"Web Server"公司 [发布了](https://cn.angie.software/) 俄罗斯开源Web服务器Angie 1.4.0新版本。此次更新包括对代理服务器连接的HTTP/3协议支持。

除了现有的 [客户端连接方面的HTTP/3支持](https://cn.angie.software/configuration/modules/http_v3/) 外，还增加了基于相似理念但可独立配置的代理功能。这特别适用于使用HTTP/1.1或HTTP/2的客户端通过Angie连接到使用HTTP/3的服务器的情况。与由客户端协议决定的端到端代理场景相比，这进一步提升了解决方案的灵活性。

此外，还为从故障中恢复的代理服务器实现了渐进式负载增加模式，允许在指定时间间隔内平稳恢复运行。同时还添加了用于限制MP4流媒体的指令，以减轻服务器基础设施的负载。

改进了对物联网（IoT）解决方案中广泛使用的MQTT协议的负载均衡支持。我们的软件包集合新增了第三方模块 [auth-ldap](https://github.com/kvspb/nginx-auth-ldap/)，该模块添加了支持多服务器的LDAP认证功能。其他包含第三方模块的软件包以及Console Light版本也进行了更新。

最近，我们 [开放了](https://github.com/webserver-llc/angie-console-light/) Console Light的源代码，[添加了](https://cn.angie.software/configuration/modsecurity/) ModSecurity集成模块到软件包中（这是一个用于保护网站免受网络攻击的流行WAF工具），并 [通过了](https://t.me/angie_software/29/) "ROSA Chrome"系统的认证，为其 [发布了软件包](https://cn.angie.software/angie/docs/installation/oss_packages/#alma-centos-msvsphere-oracle-red-os-rocky-rosa-sberlinux/)。


# https://cn.angie.software/news/releases/vishli-obnovleniya-veb-servera-angie-i-ego-proprietarnoi-versii-angie-pro.md

# Angie Web服务器及其专有版本Angie PRO发布更新

*15.02.2024*

Web Server公司发布了俄罗斯开源Web服务器Angie 1.4.1及其商业版本Angie PRO 1.4.1。

Web Server公司发布了俄罗斯开源Web服务器 [Angie 1.4.1](https://cn.angie.software/angie/docs/oss_changes/#angie-1-4-1) 及其商业版本 [Angie PRO 1.4.1](https://cn.angie.software/angie/docs/pro_changes/#angie-pro-1-4-1/)。

在此次更新中，公司开发人员成功修复了最近在nginx的QUIC和HTTP/3协议实验性实现中发现的漏洞，该漏洞被注册为CVE-2024-24989。此漏洞可能会在使用特制的QUIC会话时导致Web服务器发生段错误。值得注意的是，从Angie 1.4.0版本开始就不会受到相关漏洞CVE-2024-24990的影响。


# https://cn.angie.software/angie/docs/installation/external-modules/vod.md

<!-- review: finished -->

<a id="external-vod"></a>

# VOD

该模块允许重新打包 MP4 文件以通过 HLS、HDS、MSS 和 DASH 进行流媒体传输。

<a id="installation-30"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-vod`
- Angie PRO：`angie-pro-module-vod`

<a id="operating-modes"></a>

## 操作模式

- 本地：提供本地可用的文件（本地磁盘或 NFS 挂载）。
- 远程：使用范围请求通过 HTTP 提供可用的文件。
- 映射：根据以 JSON 格式编码的规范提供文件（JSON 可以从远程服务器获取或从本地文件读取）。

<a id="supported-codecs"></a>

## 支持的编解码器

- 视频编解码器：H264、H265（DASH/HLS）、AV1（DASH/HLS）、VP8（DASH）、VP9（DASH）。
- 音频编解码器：AAC、MP3（HLS/HDS/MSS）、AC-3（DASH/HLS）、E-AC-3（DASH/HLS）、VORBIS（DASH）、OPUS（DASH）、FLAC（HLS）、DTS（HLS）。

<a id="loading-the-module-30"></a>

## 加载模块

在 `main{}` 上下文中加载模块：

```nginx
load_module modules/ngx_http_vod_module.so;
```

<a id="configuration-example-104"></a>

## 配置示例

```nginx
location ~ ^/cenchls/p/\d+/(sp/\d+/)?serveFlavor/entryId/([^/]+)/(.*) {
    vod hls;
    vod_hls_encryption_method sample-aes-cenc;
    vod_hls_encryption_key_format "urn:uuid:edef8ba9-79d6-4ace-a3c8-27dcd51d21ed";
    vod_hls_encryption_key_format_versions "1";

    vod_drm_enabled on;
    vod_drm_request_uri "/udrm/system/ovp/$vod_suburi";

    vod_last_modified_types *;
    add_header Access-Control-Allow-Headers '*';
    add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
    add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
    add_header Access-Control-Allow-Origin '*';
    expires 100d;
}
```

<a id="additional-information-31"></a>

## 其他信息

详细文档和源代码可在以下位置获取：
[https://github.com/kaltura/nginx-vod-module](https://github.com/kaltura/nginx-vod-module).


# https://cn.angie.software/news/articles/vstrechaite-console-light.md

# 认识 Console Light

*27.09.2023*

我们推出了一款用于实时活动监控的轻量级可视化控制台。

![Alternative text](../../_images/news/vstrechaite-console-light.jpg)![Alternative text](../../_images/news/vstrechaite-console-light.jpg)

大家好！

在新版本中，Angie用户现在有多种选择来组织网络服务器状态监控。其中之一是 Console Light —— 一款用于实时活动监控的轻量级可视化控制台。它显示服务器负载和性能的关键指标。

我们的同事在Habr上发表了一篇非常详细的分析文章，介绍如何为Angie设置全面的监控而不会影响系统性能。[点击这里阅读](https://habr.com/ru/articles/763626/)

另外，你可以在 [https://console.angie.software/](https://console.angie.software/) 查看 Console Light 的演示版本。


# https://cn.angie.software/angie/docs/installation/external-modules/vts.md

<!-- review: finished -->

<a id="external-vts"></a>

# VTS

这是一组用于流量跟踪和实时活动监控的模块。它提供对虚拟主机、上游、缓存状态信息的访问,还包括用于可视化统计信息的现成 HTML 模板。

<a id="installation-31"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-vts`
- Angie PRO：`angie-pro-module-vts`

<a id="loading-modules-1"></a>

## 加载模块

在 `main{}` 上下文中加载模块：

```nginx
load_module modules/ngx_http_stream_server_traffic_status_module.so;
load_module modules/ngx_http_vhost_traffic_status_module.so;
load_module modules/ngx_stream_server_traffic_status_module.so;
```

<a id="preparing-for-demonstration-2"></a>

## 准备演示

HTML 页面模板安装在 `/usr/share/angie-module-vts/` 目录中：

- `/usr/share/angie-module-vts/status.compress.html`
- `/usr/share/angie-module-vts/status.template.html`
- `/usr/share/angie-module-vts/stream/status.compress.html`
- `/usr/share/angie-module-vts/stream/status.template.html`

要使用下面的配置示例，您需要：

1. 将 `/usr/share/angie-module-vts/status.template.html` 复制到
   `/usr/share/angie-module-vts/status.html`：
   ```console
   cp /usr/share/angie-module-vts/status.template.html \
      /usr/share/angie-module-vts/status.html
   ```
2. 在 `/usr/share/angie-module-vts/status.html` 文件中，找到以下行：
   ```html
   var vtsStatusURI = "{{uri}}/format/json", vtsUpdateInterval = 1000;
   ```

   并将 ` *{uri*}` 替换为 `/status`。

<a id="configuration-example-105"></a>

## 配置示例

```nginx
http {
    # ...
    vhost_traffic_status_zone;

    server {
        listen 80;
        server_name localhost;

        root  /usr/share/angie/html;
        index index.html index.htm;

        location = /status.html {
            root  /usr/share/angie-module-vts;
        }

        location /status {
            vhost_traffic_status_display;
            vhost_traffic_status_display_format html;
        }
    }
}
```

<a id="additional-information-32"></a>

## 其他信息

详细文档和源代码可在以下位置获取：
[https://github.com/vozlt/nginx-module-vts](https://github.com/vozlt/nginx-module-vts)。


# https://cn.angie.software/news/articles/wasm.md

# Angie 启用 WebAssembly 支持

*29.11.2024*

此次更新使得可以构建 WASM 模块，以便 Angie 加载并在服务器配置中使用它们。

Angie 软件公司发布了 Angie Web 服务器功能的重大更新：一系列模块使 WebAssembly (WASM) 支持成为可能，并提供一个专用的 SDK，允许使用更高级的抽象来构建与 Angie 兼容的 WASM 模块。

该服务器端实现为开发者提供了两个选项：

- 开发可以在几乎任何 [请求处理阶段](https://cn.angie.software//angie/docs/configuration/processing.md#http-sessions) 中被调用的 WASM 模块，使用他们偏好的语言
- 开发和运行利用服务器新增加的 WASM 功能的 Angie 模块

启用 WebAssembly 支持的三个模块是：

- [WASM Core](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#wasm-core):
  实现了 Angie 中的基本 WASM 功能。
- [WAMR](https://cn.angie.software//angie/docs/configuration/modules/wasm/wasm_wamr.md#wasm-wamr):
  与 [WebAssembly Micro Runtime](https://github.com/bytecodealliance/wasm-micro-runtime) 集成。
- [Wasmtime](https://cn.angie.software//angie/docs/configuration/modules/wasm/wasm_wasmtime.md#wasm-wasmtime):
  与 [Wasmtime](https://wasmtime.dev/) 集成。

所有三个模块都可以作为 [预构建的 Angie 包](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages) 安装。模块及其配置指令的文档可在 [我们的网站](https://cn.angie.software//angie/docs/configuration/modules/index.md#modules-wasm) 上找到。

这些模块、SDK 的源代码，以及使用它们的示例都可以在我们的仓库中找到：

- [Angie WASM 模块](https://git.angie.software/web-server/angie-wasm/):
  启用 WASM 代码执行的 Angie 模块的源代码，以及一系列扩展服务器 WASM 功能的示例 Angie 模块。
- [Angie WASM SDK](https://git.angie.software/web-server/angie-wasm-sdk/):
  提供接口定义和库，以便使用更高级的抽象为 Angie 构建 WASM 模块。
- [WASM 模块示例](https://git.angie.software/web-server/angie-wasm-examples/):
  用 C 和 Rust 编写的示例，展示如何使用 Angie WASM SDK 编写启用 Angie 的 WASM 模块。


# https://cn.angie.software/angie/docs/configuration/modules/wasm.md

<!-- review: finished -->

<a id="wasm-core"></a>

# WASM 模块

核心模块实现了 Angie 中的基本 WASM 功能：
这包括支持加载替代运行时和 WASM 模块，
以及配置它们的特性和限制。

本节中的其他模块扩展了此功能，使您能够
灵活配置和优化各种场景和需求的 WASM 特性。

在我们的代码库中，该模块构建为
[动态](https://cn.angie.software//angie/docs/installation/index.md#install-dynamicmodules)，
并作为一个名为 `angie-module-wasm` 的独立包提供。

<a id="configuration-example-75"></a>

## 配置示例

```none
# 这些指令加载核心功能
load_module modules/ngx_wasm_module.so;
load_module modules/ngx_wasm_core_module.so;

load_module modules/ngx_wasmtime_module.so;

# 可在此处找到: https://git.angie.software/web-server/angie-wasm
load_module modules/ngx_http_wasm_host_module.so;

events {

}

wasm_modules {

    #use wasmtime;

    load ngx_http_handler.wasm id=handler;
    load ngx_http_vars.wasm id=vars type=reactor;
}

http {

    wasm_var vars "ngx:wasi/var-utils#sum-entry" $rvar $arg_a $arg_b $arg_c $arg_d;

    server {

        listen *:8080;

        location / {

            return 200 "sum('$arg_a','$arg_b','$arg_c','$arg_d')=$rvar\n";
        }

        location /wasm {

            client_max_body_size 20M;
            wasm_content handler "ngx:wasi/http-handler-entry#handle-request";
        }
    }
}
```

<a id="directives-84"></a>

## 指令

<a id="index-0"></a>

<a id="load"></a>

### load

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `load` file `id=`identifier [`fs=`host_path:guest_path]... [`api=`api]... [`type=``command` | `reactor`]   |
|--------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------|
| 默认                                                                                   | —                                                                                                          |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | wasm_modules                                                                                               |

从磁盘 file 加载模块并为其分配一个唯一的 identifier （必需参数）。
在加载过程中，将验证模块以确保它可以实例化。

该指令支持以下参数：

| `fs`   | 允许客户端访问主机上的目录。<br/>可以为不同的目录多次指定该参数。                                                                                                                            |
|--------|----------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `api`  | 通过列出API明确限制模块允许使用的API列表。<br/>如果模块尝试使用不可用的API（未在此处列出），<br/>将返回"API未找到"错误。<br/><br/>默认情况下，所有API都可用于模块。                                                           |
| `type` | 控制加载模块的生命周期。<br/><br/>- 在 `command` 模式下，机器执行一次<br/>  并在执行后销毁其状态。<br/>- 在 `reactor` 模式下，机器有效地无限期运行，<br/>  允许代码多次执行。<br/>  这需要仔细的内存管理：<br/>  如果资源未被释放，可能会发生内存泄漏。 |

<a id="index-1"></a>

<a id="wasm-modules"></a>

### wasm_modules

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `wasm_modules` { ... };   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认                                                                                   | —                         |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | main                      |

一个顶级指令，提供了应该指定WASM指令的配置文件上下文。
它可以包含用于加载WASM模块的命令和配置特定运行时参数的命令。


# https://cn.angie.software/angie/docs/configuration/modules/wasm/wasm_wamr.md

<!-- review: finished -->

<a id="wasm-wamr"></a>

# WAMR

该模块提供与 [WebAssembly Micro Runtime](https://github.com/bytecodealliance/wasm-micro-runtime) 的集成，用于执行 WASM 代码，并向 [wasm_modules](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#wasm-modules) 上下文添加多个特定于运行时的指令。

在我们的代码库中，该模块是 [动态构建](https://cn.angie.software//angie/docs/installation/index.md#install-dynamicmodules) 的，并作为一个名为 `angie-module-wamr` 的独立软件包提供。

<a id="configuration-example-76"></a>

## 配置示例

```nginx
wasm_modules {

    wamr_heap_size 16k;

    wamr_stack_size 16k;

    load fft_transform.wasm id=fft;
}
```

<a id="directives-85"></a>

## 指令

<a id="index-0"></a>

<a id="wamr-heap-size"></a>

### wamr_heap_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `wamr_heap_size` size;   |
|--------------------------------------------------------------------------------------|--------------------------|
| 默认                                                                                   | `wamr_heap_size 8k;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | wasm_modules             |

为单个模块实例设置堆 [大小](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)。

<a id="index-1"></a>

<a id="wamr-global-heap-size"></a>

### wamr_global_heap_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `wamr_global_heap_size` size;   |
|--------------------------------------------------------------------------------------|---------------------------------|
| 默认                                                                                   | `wamr_global_heap_size 1m;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | wasm_modules                    |

为整个 WAMR 运行时设置堆 [大小](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)。

<a id="index-2"></a>

<a id="wamr-stack-size"></a>

### wamr_stack_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `wamr_stack_size` size;   |
|--------------------------------------------------------------------------------------|---------------------------|
| 默认                                                                                   | `wamr_stack_size 8k;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | wasm_modules              |

为单个模块实例设置栈 [大小](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)。


# https://cn.angie.software/angie/docs/configuration/modules/wasm/wasm_wasmtime.md

<a id="wasm-wasmtime"></a>

# Wasmtime

该模块支持与 [Wasmtime](https://wasmtime.dev/) 运行时的集成，以执行 WASM 代码，
并向 [wasm_modules](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#wasm-modules) 上下文添加了一些特定于运行时的指令。

在我们的代码库中，该模块是以 [动态](https://cn.angie.software//angie/docs/installation/index.md#install-dynamicmodules) 方式构建的，
并作为一个名为 `angie-module-wasmtime` 的单独包提供。

<a id="configuration-example-77"></a>

## 配置示例

```nginx
wasm_modules {

    wasmtime_stack_size 8k;

    wasmtime_enable_wasi on;

    load fft_transform.wasm id=fft;
}
```

<a id="directives-86"></a>

## 指令

<a id="index-0"></a>

<a id="wasmtime-enable-wasi"></a>

### wasmtime_enable_wasi

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `wasmtime_enable_wasi` `on` | `off`;   |
|--------------------------------------------------------------------------------------|----------------------------------------|
| 默认值                                                                                  | `wasmtime_enable_wasi on;`             |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | wasm_modules                           |

启用或禁用 [WebAssembly System Interface](https://github.com/WebAssembly/WASI) API 的使用，
这些 API 为在 Angie 上运行的 WASM 模块提供了基本的 [POSIX 类功能](https://wasi.dev/interfaces)。

#### NOTE
可以使用 [load](https://cn.angie.software//angie/docs/configuration/modules/wasm/index.md#load) 指令明确允许使用 Angie 特定的 API。

<a id="index-1"></a>

<a id="wasmtime-stack-size"></a>

### wasmtime_stack_size

| [语法](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)   | `wasmtime_stack_size` size;   |
|--------------------------------------------------------------------------------------|-------------------------------|
| 默认值                                                                                  | `wasmtime_stack_size 8k;`     |
| [上下文](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)  | wasm_modules                  |

将 [max_wasm_stack](https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.max_wasm_stack)
值设置为特定的 [size](https://cn.angie.software//angie/docs/configuration/configfile.md#syntax)，
从而限制执行 WASM 代码时可用的最大堆栈空间。


# https://cn.angie.software/angie/docs/installation/external-modules/zip.md

<!-- review: finished -->

<a id="external-zip"></a>

# Zip

`zip` 模块支持动态生成 ZIP 归档。它支持包含从代理服务器获取的文件，以及多个现代 ZIP 格式特性：

- 大文件支持；
- UTC 时间戳；
- UTF-8 编码的文件名。

这些功能允许客户端使用 `Range` 和 `If-Range` 头恢复大型归档下载，前提是服务器预先知道文件的 CRC-32 校验和。

<a id="installation-32"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-zip`；
- Angie PRO：`angie-pro-module-zip`。

<a id="loading-the-module-31"></a>

## 加载模块

要使用该模块，必须在 `main{}` 上下文中加载：

```nginx
load_module modules/ngx_http_zip_module.so;
```

<a id="additional-information-33"></a>

## 其他信息

完整文档和源代码可在以下位置获取：
[https://github.com/evanmiller/mod_zip](https://github.com/evanmiller/mod_zip)


# https://cn.angie.software/angie/docs/installation/external-modules/zstd.md

<!-- review: finished -->

<a id="external-zstd"></a>

# Zstandard (zstd)

该模块添加了对响应进行 Zstandard 压缩的支持，包括动态压缩（即时）和静态压缩（预压缩文件）。与 gzip 相比，zstd 在相当或更好的压缩率下提供更高的压缩和解压缩速度。

该模块由两个组件组成：

- **http_zstd_filter** — 用于动态压缩响应；
- **http_zstd_static** — 用于提供预压缩文件。

<a id="installation-33"></a>

## 安装

要 [安装](https://cn.angie.software//angie/docs/installation/index.md#install-packages) 该模块，请使用以下软件包之一：

- Angie：`angie-module-zstd`
- Angie PRO：`angie-pro-module-zstd`

<a id="module-loading"></a>

## 模块加载

在 `main{}` 上下文中启用模块：

```nginx
load_module modules/ngx_http_zstd_filter_module.so;
load_module modules/ngx_http_zstd_static_module.so;
```

<a id="example-configuration-2"></a>

## 配置示例

```nginx
server {
    listen 80 default_server;

    zstd_types text/plain text/css;
    zstd_min_length 256;         # 压缩的最小响应长度
    zstd_comp_level 3;           # 压缩级别（1 到 22）

    # 动态文件压缩
    location / {
        zstd on;
        root /usr/share/angie/html;
    }

    # 后端响应的动态压缩
    location /bk/ {
        zstd on;
        proxy_pass http://127.0.0.1:8081/;
    }

    # 使用预压缩的 .zst 文件
    location /static/ {
        zstd_static on;
        root /usr/share/angie;
    }
}

server {
    listen 8081;
    location / {
        root /usr/share/angie/html;
        index index.html;
    }
}
```

<a id="how-it-works"></a>

## 工作原理

您可以组合使用动态压缩（`zstd on`）和静态压缩（`zstd_static on`）。在这种情况下，服务器将首先查找预压缩的 `.zst` 文件。如果不存在，它将动态压缩响应。

仅当 `Accept-Encoding` 请求头包含 `zstd` 时才执行压缩，例如：

```none
Accept-Encoding: gzip, zstd
```

如果应用了压缩或找到了预压缩文件，则会添加以下响应头：

```none
Content-Encoding: zstd
```

<a id="more-information"></a>

## 更多信息

完整文档和源代码可在以下位置获取：
[https://github.com/tokers/zstd-nginx-module](https://github.com/tokers/zstd-nginx-module)


