https://nginx.org/en/docs/stream/ngx_stream_core_module.html
Module ngx_stream_core_module
The ngx_stream_core_module
module is available since version 1.9.0. This module is not built by default, it should be enabled with the --with-stream
configuration parameter.
Example Configuration
worker_processes auto; error_log /var/log/nginx/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; proxy_responses 1; proxy_timeout 20s; proxy_pass dns; } server { listen [::1]:12345; proxy_pass unix:/tmp/stream.socket; } }
Directives
listen |
— |
server |
Sets the address
and port
for the socket on which the server will accept connections. It is possible to specify just the port. The address can also be a hostname, for example:
listen 127.0.0.1:12345; listen *:12345; listen 12345; # same as *:12345 listen localhost:12345;
IPv6 addresses are specified in square brackets:
listen [::1]:12345; listen [::]:12345;
UNIX-domain sockets are specified with the “unix:
” prefix:
listen unix:/var/run/nginx.sock;
The ssl
parameter allows specifying that all connections accepted on this port should work in SSL mode.
The udp
parameter configures a listening socket for working with datagrams (1.9.13).
The proxy_protocol
parameter (1.11.4) allows specifying that all connections accepted on this port should use the PROXY protocol.
The listen
directive can have several additional parameters specific to socket-related system calls.
backlog
=number
backlog
parameter in the listen()
call that limits the maximum length for the queue of pending connections (1.9.2). By default, backlog
is set to -1 on FreeBSD, DragonFly BSD, and Mac OS X, and to 511 on other platforms.bind
bind()
call for a given address:port pair. The fact is that if there are several listen
directives with the same port but different addresses, and one of the listen
directives listens on all addresses for the given port (*:
port
), nginx will bind()
only to *:
port
. It should be noted that the getsockname()
system call will be made in this case to determine the address that accepted the connection. If the ipv6only
or so_keepalive
parameters are used then for a given address
:port
pair a separate bind()
call will always be made.ipv6only
=on
|off
IPV6_V6ONLY
socket option) whether an IPv6 socket listening on a wildcard address [::]
will accept only IPv6 connections or both IPv6 and IPv4 connections. This parameter is turned on by default. It can only be set once on start.reuseport
SO_REUSEPORT
socket option), allowing a kernel to distribute incoming connections between worker processes. This currently works only on Linux 3.9+ and DragonFly BSD.
Inappropriate use of this option may have its security implications.
so_keepalive
=on
|off
|[keepidle
]:[keepintvl
]:[keepcnt
]on
”, the SO_KEEPALIVE
option is turned on for the socket. If it is set to the value “off
”, the SO_KEEPALIVE
option is turned off for the socket. Some operating systems support setting of TCP keepalive parameters on a per-socket basis using the TCP_KEEPIDLE
, TCP_KEEPINTVL
, and TCP_KEEPCNT
socket options. On such systems (currently, Linux 2.4+, NetBSD 5+, and FreeBSD 9.0-STABLE), they can be configured using the keepidle
, keepintvl
, and keepcnt
parameters. One or two parameters may be omitted, in which case the system default setting for the corresponding socket option will be in effect. For example,
will set the idle timeout (so_keepalive=30m::10
TCP_KEEPIDLE
) to 30 minutes, leave the probe interval (TCP_KEEPINTVL
) at its system default, and set the probes count (TCP_KEEPCNT
) to 10 probes.
Different servers must listen on different address
:port
pairs.
preread_buffer_size |
preread_buffer_size 16k; |
stream , server
|
This directive appeared in version 1.11.5.
Specifies a size
of the preread buffer.
preread_timeout |
preread_timeout 30s; |
stream , server
|
This directive appeared in version 1.11.5.
Specifies a timeout
of the preread phase.
proxy_protocol_timeout |
proxy_protocol_timeout 30s; |
stream , server
|
This directive appeared in version 1.11.4.
Specifies a timeout
for reading the PROXY protocol header to complete. If no entire header is transmitted within this time, the connection is closed.
resolver |
— |
stream , server
|
This directive appeared in version 1.11.3.
Configures name servers used to resolve names of upstream servers into addresses, for example:
resolver 127.0.0.1 [::1]:5353;
An address can be specified as a domain name or IP address, and an optional port. If port is not specified, the port 53 is used. Name servers are queried in a round-robin fashion.
By default, nginx will look up both IPv4 and IPv6 addresses while resolving. If looking up of IPv6 addresses is not desired, the ipv6=off
parameter can be specified.
By default, nginx caches answers using the TTL value of a response. The optional valid
parameter allows overriding it:
resolver 127.0.0.1 [::1]:5353 valid=30s;
Before version 1.11.3, this directive was available as part of our commercial subscription.
resolver_timeout |
resolver_timeout 30s; |
stream , server
|
This directive appeared in version 1.11.3.
Sets a timeout for name resolution, for example:
resolver_timeout 5s;
Before version 1.11.3, this directive was available as part of our commercial subscription.
server { ... } |
— |
stream |
Sets the configuration for a server.
stream { ... } |
— |
main |
Provides the configuration file context in which the stream server directives are specified.
tcp_nodelay |
tcp_nodelay on; |
stream , server
|
This directive appeared in version 1.9.4.
Enables or disables the use of the TCP_NODELAY
option. The option is enabled for both client and proxied server connections.
variables_hash_bucket_size |
variables_hash_bucket_size 64; |
stream |
This directive appeared in version 1.11.2.
Sets the bucket size for the variables hash table. The details of setting up hash tables are provided in a separate document.
variables_hash_max_size |
variables_hash_max_size 1024; |
stream |
This directive appeared in version 1.11.2.
Sets the maximum size
of the variables hash table. The details of setting up hash tables are provided in a separate document.
Embedded Variables
The ngx_stream_core_module
module supports variables since 1.11.2.
$binary_remote_addr
$bytes_received
$bytes_sent
$connection
$hostname
$msec
$nginx_version
$pid
$protocol
TCP
or UDP
(1.11.4)$proxy_protocol_addr
The PROXY protocol must be previously enabled by setting the proxy_protocol
parameter in the listen directive.
$proxy_protocol_port
The PROXY protocol must be previously enabled by setting the proxy_protocol
parameter in the listen directive.
$remote_addr
$remote_port
$server_addr
Computing a value of this variable usually requires one system call. To avoid a system call, the listen directives must specify addresses and use the bind
parameter.
$server_port
$session_time
$status
200
400
403
500
502
503
$time_iso8601
$time_local
相关推荐
nginx反向代理tcp端口详细操作说明,代理所有tcp端口说明
nginx.conf tcp转发、http反向代理
freeswitch支持UDP、TCP、WS(websocket)、WSS方式进行注册,而反向代理是指通过nginx配置,通过WSS的方式连接WS,这样使得freeswitch连接对外是加密的;当然freeswitch本身是支持WSS的, 用ngnix一般除了反向代理,...
官方tcp模块,配置stream {} 也可以代理tcp,--with-http_stub_status_module --with-stream https://blog.csdn.net/e_wsq/article/details/79408263 来自GitHub开源提交版及官方公布版,清单如下 nginx_tcp_proxy...
Nginx与前端的连接默认为长连接,一个用户跟Nginx建立连接之后,通过这个长连接发送多个请求。如果Nginx只是作为reverse proxy的话,可能一个用户连接就需要多个向后端的短连接。如果后端的服务器(源站或是缓存...
Nginx可以作为一个HTTP服务器进行网站的发布处理,另外Nginx可以作为反向代理进行负载均衡的实现。 Nginx使用基于事件驱动架构,使得其可以支持数以百万级别的TCP连接 高度的模块化和自由软件许可证使得第三方模块...
CentOS7.3系统下安装nginx1.13.9负载均衡器软件,通过二进制源码包编译安装,开启stream 功能模块,进行TCP/UDP负载,已经对nginx的http和tcp负载进行配置
如果我们使用了nginx去作为反向代理或者负载均衡,从客户端过来的长连接请求就会被转换成短连接发送给服务器端。 为了支持长连接,我们需要在nginx服务器上做一些配置。 ·【要求】 使用nginx时,想要做到长连接,...
说明:nginx版本要求是1.9以上 ,编译nginx的时候需要加上 –with-stream ...1.因为mysql默认使用了3306端口所以配置nginx tcp反向代理mysql的时候注意端口不要与mysql监听的端口一样比如我使用的是3307 2
18.搭建nginx反向代理用做内网域名转发 19.Nginx+keepalived+proxy_cache配置高可用Nginx群集和高速缓冲 20.Nginx最难一战 优化指南 21.确保Nginx安全的10大关键技巧 Nginx变量详解 Nginx模块与实践案例 提供了目前...
用Nginx作为反向代理的Gametron。 从20/04/16(04/16/2021)Ubuntu 18.04(Microsoft Azure VM)开始工作 根据此处的官方文档指南安装gametron: ://docs.gametron.io/getting-started/installation-master/ 安装...
使用WebUI配置nginx的各项功能, 包括http协议转发, tcp协议转发, 反向代理, 负载均衡, ssl证书自动申请、续签、配置等, 最终生成nginx.conf文件并覆盖nginx的默认配置文件, 完成nginx的最终功能配置。 支持nginx...
Nginx是一款轻量级的Web服务器 反向代理服务器及电子邮件IMAP POP3)代理服务器 并在一个BSD like 协议下发行 Nginx由俄罗斯的程序设计师Igor Sysoev所开发 可供大型的门户网站及搜索引擎使用 Nginx是一个很...
Nginx的[ X ]是一个HTTP引擎和反向代理服务器,邮件代理服务器,和一个通用的TCP代理服务器,在BSD协议下发行,其占有内存少,支持并发响应能力强。相信很多读者都对Apache非常熟悉,与Apache类似,Nginx是一款高...
-prefix=/usr/local/nginx –with-pcre=/home/soft/pcre-8.30 –with-openssl=/home/soft/openssl-1.0.2g –add-module=../nginx_tcp_proxy_module-master 如果安装中出现: configure: error: zlib library not ...
Nginx 是一个高性能的 HTTP 和反向代理服务器。它最初由 Nigel Cook 开发,旨在解决 Apache 服务器在高并发环境下性能瓶颈的问题。Nginx 具有占用资源少、处理能力强等优点,在互联网应用中广泛应用于静态资源服务、...
使用 Dockxy,您可以监听 docker 事件(例如,创建或删除新容器)并自动创建 nginx 配置文件以将 nginx 反向代理到这些容器。 端口和 IP 以及容器的名称将自动填写。 跑步 您可以下载预先构建的二进制文件。 或者...
默认nginx不支持tcp的负载均衡,需要打补丁,(连接方式:从客户端收到一个连接,将从本地新建一个连接发起到后端服务器),具体配置如下: 一、安装Nginx 1.下载nginx # wget ...
用Rust实现仿nginx,力争实现一个可替代方案,http/https代理, socks5代理, 负载均衡, 反向代理, 静态文件服务器,四层TCP/UDP转发,websocket转发, 内网穿透nat
方便快捷易用的Nginx可视化UI网页管理部署配置工具系统,使用Web网页系统来快速配置部署,支持在线配置你的Nginx/Openresty的反向代理、负载均衡、SSL/HTTPS证书免费签发,自动续签、TCP/UDP 3-4层转发、可以自定义...