大网数据广告活动
服务器运维问答

nginx stream and upstream block

· 52CE 我爱测

I googled but i did not understand the difference between nginx stream and upstream block for load balancing. stream { upstream { } } i showed google that some people used stream block, some people ignored for http load balancing…

问题原文

原帖链接 · Moin Uddin · CC BY-SA 3.0

I googled but i did not understand the difference between nginx stream and upstream block for load balancing.

stream
{
    upstream
   {
   }
}

i showed google that some people used stream block, some people ignored for http load balancing but all people used stream block for tcp/udp load balncing.

when i have to use stream block? when i may ignore stream block?

已采纳解答

原帖链接 · Alexander Makarenko · CC BY-SA 4.0

Since v1.9.0 Nginx can be used as load balancer for any tcp and udp (mysql, dns, etc..)

https://nginx.ru/en/docs/stream/ngx_stream_core_module.html

stream {

    upstream  mysql_backend{  
         server 1.1.1.1:3306;
         server unix:/var/lib/mysql.sock;
    }

    server {
         # frontend
         listen 127.0.0.1:3306;
         proxy_pass mysql_backend;
    }
}

So if you want to use nginx as usal (web server only). You don't need this derective. If you need to balance you dns (for example) traffic, use it.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-11-16)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。