小编joe*_*els的帖子

如何使用 nginx 在一个端口上代理多个 tcp 流

使用 nginx http 指令,您可以在同一个端口上拥有多个具有不同名称的服务器:

server {
    listen       80;
    server_name server1.example.com;
    location / {
      proxy_pass http://server1.example.com;
    }
}
server {
    listen       80;
    server_name server2.example.com;
    location / {
      proxy_pass http://server2.example.com;
    }
}
Run Code Online (Sandbox Code Playgroud)

是否可以像使用 http 一样在同一端口上使用不同名称的 nginx 代理多个 mysql 服务器?它们不是集群或任何东西的一部分。有不同的,不相关的表。

stream {
  upstream db1.example.com {
    server db1.example.com:3306;
    #server_name db1.example.com; "server_name" directive is not allowed here
  }
  upstream db2.example.com {
    server db2.example.com:3306;
  }

  server {
    listen 3306;
    proxy_pass db1.example.com;
  }
  #duplicate "3306" address and port pair
  #server { listen 3306; proxy_pass db2.example.com; }


}
Run Code Online (Sandbox Code Playgroud)

nginx proxy stream

10
推荐指数
2
解决办法
3万
查看次数

标签 统计

nginx ×1

proxy ×1

stream ×1