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