UDP代理 如果需要保持心跳服务,需要设置proxy_requests参数。此参数nginx版本>=1.18.0才支持。所以需要升级nginx版本。
[root@ecs-a0b2-0001 install]# wget https://nginx.org/download/nginx-1.18.0.tar.gz[root@ecs-a0b2-0001 conf]# tar -xzf nginx-1.18.0.tar.gz[root@ecs-a0b2-0001 conf]# cd nginx-1.18.0[root@ecs-a0b2-0001 nginx-1.18.0]# nginx-1.18.0[root@ecs-a0b2-0001 nginx-1.18.0]# ./configure --prefix=/usr/local/nginx-1.18.0 --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_gunzip_module --with-http_gzip_static_module --with-pcre-jit --with-http_geoip_module --add-module=/opt/install/headers-more-nginx-module-master --with-stream[root@ecs-a0b2-0001 nginx-1.18.0]# make && make install[root@ecs-a0b2-0001 nginx-1.18.0]# /usr/local/nginx-1.18.0/sbin/nginx -t
nginx配置如下:
worker_processes 1;worker_rlimit_nofile 20480;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server_tokens off;gzip on;}stream {log_format main '$remote_addr [$time_local] ''$protocol $status $bytes_sent $bytes_received ''$session_time';upstream dns_upstreams {server 192.168.0.233:10001 max_fails=3 fail_timeout=3s;server 192.168.0.18:10001 max_fails=3 fail_timeout=3s;}server {listen 10001 udp;proxy_pass dns_upstreams;proxy_timeout 60s;proxy_responses 1;proxy_requests 1000000;access_log logs/cat.access.log main;error_log logs/cat.error.log;}}
