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.
升级:
可以下载新版本的,可以通过sbin/nginx -V 查看之前编译的的模块,解压新版本,直接编译安装到之前安装的目录即可,然后通过sbin/nginx -v 查看是否升级成功。
安装模块:
nginx从1.9.0开始,新增加了一个stream模块,用来实现四层协议的转发、代理或者负载均衡等。
stream模块默认没有编译到nginx, 编译nginx时候 ./configure –with-stream 即可
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; } }