nginx 如何处理 TCP/UDP 会话

How nginx processes a TCP/UDP session - nginx 如何处理 TCP/UDP 会话

https://nginx.org/en/docs/stream/stream_processing.html

A TCP/UDP session from a client is processed in successive steps called phases:

​ 客户端的 TCP/UDP 会话在称为阶段的连续步骤中进行处理:

Post-accept

The first phase after accepting a client connection. The ngx_stream_realip_module module is invoked at this phase.

​ 在接受客户端连接后的第一个阶段。此阶段调用 ngx_stream_realip_module 模块。

Pre-access

Preliminary check for access. The ngx_stream_limit_conn_module and ngx_stream_set_module modules are invoked at this phase.

​ 用于预先检查访问权限。在此阶段,调用 ngx_stream_limit_conn_modulengx_stream_set_module 模块。

Access

Client access limitation before actual data processing. At this phase, the ngx_stream_access_module module is invoked, for njs, the js_access directive is invoked.

​ 在实际数据处理之前对客户端访问进行限制。在此阶段,调用 ngx_stream_access_module 模块;对于 njs,调用 js_access 指令。

SSL

TLS/SSL termination. The ngx_stream_ssl_module module is invoked at this phase.

​ TLS/SSL 终止。在此阶段,调用 ngx_stream_ssl_module 模块。

Preread

Reading initial bytes of data into the preread buffer to allow modules such as ngx_stream_ssl_preread_module analyze the data before its processing. For njs, the js_preread directive is invoked at this phase.

​ 将初始数据的前几个字节读入 预读缓冲区,以便让模块(例如 ngx_stream_ssl_preread_module)在处理数据之前分析数据。对于 njs,在此阶段调用 js_preread 指令。

Content

Mandatory phase where data is actually processed, usually proxied to upstream servers, or a specified value is returned to a client. For njs, the js_filter directive is invoked at this phase.

​ 数据实际处理的必要阶段,通常将数据 代理上游 服务器,或者将指定的值 返回 给客户端。对于 njs,在此阶段调用 js_filter 指令。

Log

The final phase where the result of a client session processing is recorded. The ngx_stream_log_module module is invoked at this phase.

​ 客户端会话处理结果记录的最终阶段。在此阶段调用 ngx_stream_log_module 模块。

最后修改 August 15, 2023: 更新 (9ab71f5)