1. Nginx在安裝的時候,須要加上一個參數:--with-stream html
即Nginx安裝指令爲:./configure --prefix=/u01/app/nginx --with-streamnginx
Nginx的安裝教程,可參見:https://www.cnblogs.com/Charles-Yuan/articles/9737617.html數據庫
2. nginx安裝完成後,編輯nginx.conf文件,指令:vim
vim /u01/app/nginx/conf/nginx.conf服務器
在文件的最下方(位置也能夠不是最下方,stream必須和http平級)添加以下內容:app
stream {socket
upstream cloudsocket {
hash $remote_addr consistent;
server 數據庫實際IP:數據庫實際端口號 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 數據庫代理端口號;
proxy_connect_timeout 10s;
proxy_timeout 300s;
proxy_pass cloudsocket;
}
}spa
3. 重啓nginx服務器.代理
若有問題,歡迎糾正!!!server
若有轉載,請標明源處:http://www.javashuo.com/article/p-dpyrixxc-bc.html