Nginx中文文档
DocsHome
  • 贡献导引
  • 介绍
    • 安装 nginx
    • 从源码构建 nginx
    • 初学者指南
    • 管理指南
    • 控制 nginx
    • 连接处理方式
    • 设置哈希
    • 调试日志
    • 记录日志到 syslog
    • 配置文件度量单位
    • 命令行参数
    • Windows 下的 nginx
    • QUIC 和 HTTP/3 支持
    • nginx 如何处理请求
    • 服务器名称
    • 使用 nginx 作为 HTTP 负载均衡器
    • 配置 HTTPS 服务器
    • nginx 如何处理 TCP/UDP 会话
    • 关于 nginScript
  • 其他
    • Linux 软件包
  • How-To
    • 在 Win32 平台上使用 Visual C 构建 nginx
    • 设置 Amazon EC2 的 Nginx Plus 环境
    • 使用 DTrace pid 提供程序调试 nginx
    • 转换重写规则
    • WebSocket 代理
  • 开发
    • 贡献指南
    • 开发指南
  • 模块参考
  • 核心功能
    • HTTP
      • ngx_http_core_module
      • ngx_http_access_module
      • ngx_http_addition_module
      • ngx_http_api_module
      • ngx_http_auth_basic_module
      • ngx_http_auth_jwt_module
      • ngx_http_auth_request_module
      • ngx_http_autoindex_module
      • ngx_http_browser_module
      • ngx_http_charset_module
      • ngx_http_dav_module
      • ngx_http_empty_gif_module
      • ngx_http_f4f_module
      • ngx_http_fastcgi_module
      • ngx_http_flv_module
      • ngx_http_geo_module
      • ngx_http_geoip_module
      • ngx_http_grpc_module
      • ngx_http_gunzip_module
      • ngx_http_gzip_module
      • ngx_http_gzip_static_module
      • ngx_http_headers_module
      • ngx_http_hls_module
      • ngx_http_image_filter_module
      • ngx_http_index_module
      • ngx_http_js_module
      • ngx_http_keyval_module
      • ngx_http_limit_conn_module
      • ngx_http_limit_req_module
      • ngx_http_log_module
      • ngx_http_map_module
      • ngx_http_memcached_module
      • ngx_http_mirror_module
      • ngx_http_mp4_module
      • ngx_http_perl_module
      • ngx_http_proxy_module
      • ngx_http_random_index_module
      • ngx_http_realip_module
      • ngx_http_referer_module
      • ngx_http_rewrite_module
      • ngx_http_scgi_module
      • ngx_http_secure_link_module
      • ngx_http_session_log_module
      • ngx_http_slice_module
      • ngx_http_spdy_module(过时)
      • ngx_http_split_clients_module
      • ngx_http_ssi_module
      • ngx_http_ssl_module
      • ngx_http_status_module(过时)
      • ngx_http_stub_status_module
      • ngx_http_sub_module
      • ngx_http_upstream_module
      • ngx_http_upstream_conf_module
      • ngx_http_upstream_hc_module
      • ngx_http_userid_module
      • ngx_http_uwsgi_module
      • ngx_http_v2_module
      • ngx_http_xslt_module
    • Mail
      • ngx_mail_core_module
      • ngx_mail_auth_http_module
      • ngx_mail_proxy_module
      • ngx_mail_ssl_module
      • ngx_mail_imap_module
      • ngx_mail_pop3_module
      • ngx_mail_smtp_module
    • Stream
      • ngx_stream_core_module
      • ngx_stream_access_module
      • ngx_stream_geo_module
      • ngx_stream_geoip_module
      • ngx_stream_js_module
      • ngx_stream_keyval_module
      • ngx_stream_limit_conn_module
      • ngx_stream_log_module
      • ngx_stream_map_module
      • ngx_stream_proxy_module
      • ngx_stream_realip_module
      • ngx_stream_return_module
      • ngx_stream_split_clients_module
      • ngx_stream_ssl_module
      • ngx_stream_ssl_preread_module
      • ngx_stream_upstream_module
      • ngx_stream_upstream_hc_module
      • ngx_stream_zone_sync_module
    • 其他
      • ngx_google_perftools_module
由 GitBook 提供支持
在本页
  • 示例配置
  • 指令
  • proxy_bind
  • proxy_buffer_size
  • proxy_connect_timeout
  • proxy_download_rate
  • proxy_next_upstream
  • proxy_next_upstream_timeout
  • proxy_next_upstream_tries
  • proxy_pass
  • proxy_protocol
  • proxy_requests
  • proxy_responses
  • proxy_session_drop
  • proxy_socket_keepalive
  • proxy_ssl
  • proxy_ssl_certificate
  • proxy_ssl_certificate_key
  • proxy_ssl_ciphers
  • proxy_ssl_crl
  • proxy_ssl_name
  • proxy_ssl_password_file
  • proxy_ssl_protocols
  • proxy_ssl_server_name
  • proxy_ssl_session_reuse
  • proxy_ssl_trusted_certificate
  • proxy_ssl_verify
  • proxy_ssl_verify_depth
  • proxy_timeout
  • proxy_upload_rate
  • 原文档
  1. 核心功能
  2. Stream

ngx_stream_proxy_module

上一页ngx_stream_map_module下一页ngx_stream_realip_module

最后更新于5年前

ngx_stream_proxy_module 模块(1.9.0)允许通过 TCP、UDP(1.9.13)和 UNIX 域套接字代理数据流。

示例配置

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;
}

指令

proxy_bind

-

说明

语法

proxy_bind address [transparent] | off;

默认

——

上下文

stream、server

提示

该指令在 1.9.2 版本中出现

使到被代理服务器的出站连接源自指定的本地 IP 地址(address)。参数值可以包含变量(1.11.2)。特殊值 off 指定不继承上级 proxy_bind 指令配置,这使系统可以自动分配本地 IP 地址。

transparent 参数(1.11.0)允许到被代理服务器的出站连接源自非本地 IP 地址,例如,来自一个客户端的真实 IP 地址:

proxy_bind $remote_addr transparent;

proxy_buffer_size

-

说明

语法

limit_conn_log_level size;

默认

proxy_buffer_size 16k;

上下文

stream、server

提示

该指令在 1.9.4 版本中出现

设置读取被代理服务器数据的缓冲区的大小(size)。也用于设置读取客户端数据的缓冲区的大小(size)。

proxy_connect_timeout

-

说明

语法

proxy_connect_timeout time;

默认

proxy_connect_timeout 60s;

上下文

stream、server

设置与被代理服务器建立连接的超时时间。

proxy_download_rate

-

说明

语法

proxy_download_rate rate;

默认

proxy_download_rate 0;

上下文

stream、server

提示

该指令在 1.9.3 版本中出现

限制读取被代理服务器数据的速率。rate 以每秒字节数指定。零值禁用速率限制。该限制是针对每个连接设置的,因此,如果 nginx 同时打开两个与被代理服务器的连接,则总速率将是指定限制速率的两倍。

参数值可以包含变量(1.17.0)。如果需要根据特定条件限制速率,可参考以下配置示例:

map $slow $rate {
    1     4k;
    2     8k;
}

proxy_download_rate $rate;

proxy_next_upstream

-

说明

语法

proxy_next_upstream on | off;

默认

proxy_next_upstream on;

上下文

stream、server

当连接无法与某个被代理服务器建立连接时,是否将客户端连接传递给下一个服务器。

proxy_next_upstream_timeout

-

说明

语法

proxy_next_upstream_timeout time;

默认

proxy_next_upstream_timeout 0;

上下文

stream、server

proxy_next_upstream_tries

-

说明

语法

proxy_next_upstream_tries number;

默认

proxy_next_upstream_tries 0;

上下文

stream、server

proxy_pass

-

说明

语法

proxy_pass address;

默认

——

上下文

server

设置被代理服务器的地址。该地址可以指定为一个域名或 IP 地址以及端口:

proxy_pass localhost:12345;

或作为 UNIX 域套接字路径:

proxy_pass unix:/tmp/stream.socket;

也可以使用变量(1.11.3)指定地址:

proxy_pass $upstream;

proxy_protocol

-

说明

语法

proxy_protocol on | off;

默认

proxy_protocol off;

上下文

stream、server

提示

该指令在 1.9.2 版本中出现

proxy_requests

-

说明

语法

proxy_requests number;

默认

proxy_requests 0;

上下文

stream、server

提示

该指令在 1.15.7 版本中出现

proxy_responses

-

说明

语法

proxy_responses number;

默认

——

上下文

stream、server

提示

该指令在 1.9.13 版本中出现

如果指定零值,则不会响应。但如果收到响应并且会话仍未完成,则该响应将被处理。

proxy_session_drop

-

说明

语法

proxy_session_drop on | off;

默认

proxy_session_drop off;

上下文

stream、server

提示

该指令在 1.15.8 版本中出现

proxy_socket_keepalive

-

说明

语法

proxy_socket_keepalive on | off;

默认

proxy_socket_keepalive off;

上下文

stream、server

提示

该指令在 1.15.6 版本中出现

为到被代理服务器的出站连接配置 TCP keepalive 行为。默认情况下,操作系统的设置影响到套接字。如果指令设置为 on 值,则将为套接字打开 SO_KEEPALIVE 套接字选项。

proxy_ssl

-

说明

语法

proxy_ssl on | off;

默认

proxy_ssl off;

上下文

stream、server

为到被代理服务器的连接启用 SSL/TLS 协议。

proxy_ssl_certificate

-

说明

语法

proxy_ssl_certificate file;

默认

——

上下文

stream、server

指定一个 PEM 格式的证书文件,用于验证被代理服务器的身份。

proxy_ssl_certificate_key

-

说明

语法

proxy_ssl_certificate_key file;

默认

——

上下文

stream、server

指定一个 PEM 格式的私钥文件,用于验证被代理服务器的身份。

proxy_ssl_ciphers

-

说明

语法

proxy_ssl_ciphers ciphers;

默认

proxy_ssl_ciphers DEFAULT;

上下文

stream、server

指定连接到被代理服务器启用的密码算法。密码算法需要 OpenSSL 库支持。

可以使用 openssl ciphers 命令查看完整的算法支持列表。

proxy_ssl_crl

-

说明

语法

proxy_ssl_crl file;

默认

——

上下文

stream、server

proxy_ssl_name

-

说明

语法

proxy_ssl_name name;

默认

proxy_ssl_name 来自 proxy_pass 的 host;

上下文

stream、server

proxy_ssl_password_file

-

说明

语法

proxy_ssl_password_file file;

默认

——

上下文

stream、server

proxy_ssl_protocols

-

说明

语法

proxy_ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2] [TLSv1.3];

默认

proxy_ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

上下文

stream、server

为到被代理服务器的连接启用指定协议。

proxy_ssl_server_name

-

说明

语法

proxy_ssl_server_name on | off;

默认

proxy_ssl_server_name off;

上下文

stream、server

proxy_ssl_session_reuse

-

说明

语法

proxy_ssl_session_reuse on | off;

默认

proxy_ssl_session_reuse on;

上下文

stream、server

在使用被代理服务器时是否可以重用 SSL 会话。如果日志中出现错误 SSL3_GET_FINISHED:digest check failed,请尝试禁用会话重用。

proxy_ssl_trusted_certificate

-

说明

语法

proxy_ssl_trusted_certificate file;

默认

——

上下文

stream、server

proxy_ssl_verify

-

说明

语法

proxy_ssl_verify on | off;

默认

proxy_ssl_verify off;

上下文

stream、server

启用或禁用被代理服务器证书验证。

proxy_ssl_verify_depth

-

说明

语法

proxy_ssl_verify_depth number;

默认

proxy_ssl_verify_depth 1;

上下文

stream、server

设置被代理服务器证书链验证深度。

proxy_timeout

-

说明

语法

proxy_timeout timeout;

默认

proxy_timeout 10m;

上下文

stream、server

设置客户端或被代理服务器连接两次连续读取或写入操作之间的超时时间(timeout)。如果在此时间内没有数据传输,则连接将关闭。

proxy_upload_rate

-

说明

语法

proxy_upload_rate rate;

默认

proxy_upload_rate 0;

上下文

stream、server

提示

该指令在 1.9.3 版本中出现

限制读取客户端数据的速率。该速率以每秒字节数指定。零值禁用速率限制。该限制只针对单个连接,因此,如果客户端同时打开两个连接,则总速率将是指定限制速率的两倍。

参数值可以包含变量(1.17.0)。如果需要根据特定条件设置限制速率,可参考以下配置示例:

map $slow $rate {
    1     4k;
    2     8k;
}

proxy_upload_rate $rate;

原文档

为了使此参数生效,通常必须使用运行 nginx worker 进程。在 Linux上,如果指定了 transparent 则不需要(1.13.8),worker 进程从 master 进程继承 CAP_NET_RAW 能力。还需要配置内核路由表以拦截来自被代理服务器的网络流量。

将连接传递到下一个服务器可能会受到和的限制。

设置将连接传递到的超时时间。0 值关闭此限制。

设置将连接传递到的尝试次数。0 值关闭此限制。

如果一个域名解析为多个地址,则所有这些地址都将以轮询的方式使用。另外,可以将地址指定为一个。

在这种情况下,在配置的中查找服务器名称,如果找不到,则使用一个 确定服务器名称。

为到被代理服务器的连接启用 。

设置丢弃客户端和现有 UDP 流会话之间绑定的客户端数据报的数量。在收到指定数量的数据报后,来自同一客户端的下一个数据报将启动一个新会话。当所有客户端数据报都发送到被代理服务器并接收到预期的数时,或者达到时,会话将终止。

如果使用 协议,设置响应客户端数据报中来自被代理服务器的数据报期望数。该数字用作会话终止的提示。默认情况下,数据报的数量不受限制。

设置在将被代理服务器从组中删除或标记为永久不可用后,是否可以终止与被代理服务器的所有会话。在或使用了 API 命令时,可能会发生这种情况。如果服务器处于状态或使用 API 命令修改,服务器可标记为永久不可用。当为客户端或被代理服务器处理下一个读取或写入事件时,每个会话都会终止。

该指令为部分。

指定一个 PEM 格式的吊销证书(CRL)文件,用于被代理服务器的证书。

允许覆盖用于被代理服务器证书的服务器名称,并在与被代理服务器建立连接时。也可以使用变量(1.11.3)指定服务器名称。

默认情况下,使用 地址的主机部分。

指定一个保存有密码的文件,每个密码独占一行。加载密钥时依次尝试使用这些密码。

与被代理服务器建立连接时,启用或禁用通过 (SNI、RFC 6066)传递服务器名称。

指定一个 PEM 格式的可信 CA 证书文件,该证书用于被代理服务器的证书。

服务器组
PROXY 协议
商业订阅
TLS 服务器名称指示扩展
http://nginx.org/en/docs/stream/ngx_stream_proxy_module.html
示例配置
指令
proxy_bind
proxy_buffer_size
proxy_connect_timeout
proxy_download_rate
proxy_next_upstream
proxy_next_upstream_timeout
proxy_next_upstream_tries
proxy_pass
proxy_protocol
proxy_requests
proxy_responses
proxy_session_drop
proxy_socket_keepalive
proxy_ssl
proxy_ssl_certificate
proxy_ssl_certificate_key
proxy_ssl_ciphers
proxy_ssl_crl
proxy_ssl_name
proxy_ssl_password_file
proxy_ssl_protocols
proxy_ssl_server_name
proxy_ssl_session_reuse
proxy_ssl_trusted_certificate
proxy_ssl_verify
proxy_ssl_verify_depth
proxy_timeout
proxy_upload_rate
尝试次数
时间
下一个服务器
下一个服务器
响应
超时时间
DELETE
不健康
PATCH
重新解析
验证
验证
通过 SNI 传递
proxy_pass
密钥
验证
服务器组
resolver
UDP
超级用户特权