首先是須要安裝Nginx。通常Linux環境Nginx依賴pcre,OpenSSL-fips ,zlib 。因此在安裝Nginx以前須要安裝這幾個。mysql
./configure --with-stream Nginx的時候須要加上參數 --with-stream才能開啓socket的轉發。默認是沒有的。nginx
後面的make &make install 都是同樣的。sql
編輯 $nginx_home/conf/nginx.confsocket
stream { upstream bss_num_socket { hash $remote_addr consistent; server rm-2ze3tgn1qo9a6a998.mysql.rds.aliyuncs.com:3306 weight=5 max_fails=3 fail_timeout=30s; } server { listen 3389; proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass bss_num_socket; } }
上面就是一個簡單的socket轉發的例子。監聽3389端口。將接受的包轉發到server 指定的主機地址code