【nginx】用 nginx stream 模块实现 tcp/udp 4层代理

yum -y install epel-release

yum -y install nginx

vim /etc/nginx/nginx.conf


# For more information on configuration, see:

#   * Official English Documentation:[http://nginx.org/en/docs/](https://links.jianshu.com/go?to=http%3A%2F%2Fnginx.org%2Fen%2Fdocs%2F)

#   * Official Russian Documentation:[http://nginx.org/ru/docs](https://links.jianshu.com/go?to=http%3A%2F%2Fnginx.org%2Fru%2Fdocs)/

user nginx;

worker_processes auto;

error_log /var/log/nginx/error.log;

pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.

include /usr/share/nginx/modules/*.conf;

events {

    worker_connections 1024;

}

##############################
stream {
    proxy_timeout 30s;
    upstream stream_backend {
        server 192.168.170.41:8080;
        server 192.168.170.42:8080;
}

server {
    listen 8080;
    proxy_pass stream_backend;
   }
}
#################################

systemctl start nginx

systemctl enable nginx

systemctl status nginx

image.png

参考

TCP和UDP的负载均衡
https://mp.weixin.qq.com/s/T6Axis20oJg29IXbXuZCoA

Nginx - UDP健康检查介绍
https://mp.weixin.qq.com/s/vrUKoOEd4osuRe9PmBDVGw

用stream模块实现TCP端口转发
https://www.jianshu.com/p/d6396d8c5418

Module ngx_stream_proxy_module
https://nginx.org/en/docs/stream/ngx_stream_proxy_module.html

TCP/UDP Load Balancing with NGINX: Overview, Tips, and Tricks
https://www.nginx.com/blog/tcp-load-balancing-udp-load-balancing-nginx-tips-tricks

NGINX as a Reverse Stream Proxy
https://www.eigenmagic.com/2021/09/20/nginx-as-a-reverse-stream-proxy

nginx stream proxy vs http proxy for ssl termination
https://serverfault.com/questions/1011928/nginx-stream-proxy-vs-http-proxy-for-ssl-termination

nginx reverse stream proxy with multiple ports to the same server
https://serverfault.com/questions/850714/nginx-reverse-stream-proxy-with-multiple-ports-to-the-same-server

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容