UDP代理 如果需要保持心跳服务,需要设置proxy_requests参数。此参数nginx版本>=1.18.0才支持。所以需要升级nginx版本。

    1. [root@ecs-a0b2-0001 install]# wget https://nginx.org/download/nginx-1.18.0.tar.gz
    2. [root@ecs-a0b2-0001 conf]# tar -xzf nginx-1.18.0.tar.gz
    3. [root@ecs-a0b2-0001 conf]# cd nginx-1.18.0
    4. [root@ecs-a0b2-0001 nginx-1.18.0]# nginx-1.18.0
    5. [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
    6. [root@ecs-a0b2-0001 nginx-1.18.0]# make && make install
    7. [root@ecs-a0b2-0001 nginx-1.18.0]# /usr/local/nginx-1.18.0/sbin/nginx -t

    nginx配置如下:

    1. worker_processes 1;
    2. worker_rlimit_nofile 20480;
    3. events {
    4. worker_connections 1024;
    5. }
    6. http {
    7. include mime.types;
    8. default_type application/octet-stream;
    9. sendfile on;
    10. keepalive_timeout 65;
    11. server_tokens off;
    12. gzip on;
    13. }
    14. stream {
    15. log_format main '$remote_addr [$time_local] '
    16. '$protocol $status $bytes_sent $bytes_received '
    17. '$session_time';
    18. upstream dns_upstreams {
    19. server 192.168.0.233:10001 max_fails=3 fail_timeout=3s;
    20. server 192.168.0.18:10001 max_fails=3 fail_timeout=3s;
    21. }
    22. server {
    23. listen 10001 udp;
    24. proxy_pass dns_upstreams;
    25. proxy_timeout 60s;
    26. proxy_responses 1;
    27. proxy_requests 1000000;
    28. access_log logs/cat.access.log main;
    29. error_log logs/cat.error.log;
    30. }
    31. }