修改nginx.conf,添加如下配置(注意:stream和http是同级的):

stream {
    upstream cloudsocket {
       hash $remote_addr consistent;
       server 192.168.1.101:3389 weight=5 max_fails=3 fail_timeout=30s;
    }
    server {
       listen 25674; # 数据库服务器监听端口
       proxy_connect_timeout 10s;
       proxy_timeout 300s; # 设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
       proxy_pass cloudsocket;
    }
}

配置stream的前提,该Nginx要按照如下命令编译安装才行,否则会报错:

./configure --prefix=/usr/local/nginx-mysql --with-http_stub_status_module --with-http_ssl_module --with-pcre=/usr/local/src/pcre-8.35 --with-stream

参考链接:
nginx转发mysql连接

相关文章:

  • 2022-12-23
  • 2021-12-10
  • 2021-10-28
  • 2021-11-28
  • 2022-01-30
  • 2022-01-01
  • 2021-07-05
  • 2021-07-22
猜你喜欢
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-10
  • 2021-11-28
  • 2022-12-23
相关资源
相似解决方案