nginx之MySQL代理


修改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连接


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM