官方解释如下:
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.
在安装nginx时,带上参数--with-stream,如下
./configure --with-stream ###此处省略其他参数,如需要自行添加
然后make;make install
nginx.conf配置如下
worker_processes auto;
error_log /var/log/nginx/error.log info;
events {
worker_connections 1024;
}
stream { //原配置文件这里默认是http
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;
}
}
详情参考:http://nginx.org/en/docs/stream/ngx_stream_core_module.html