The default Nginx only supports HTTP reverse proxy, if you want to support TCP reverse proxy, you also need to increase the TCP proxy module support at compile time, that is Nginx_tcp_proxy_module
The following steps only let Nginx support Tcp_proxy, do not add Prce, gzip, SSL and other functions, if necessary, you can add the relevant parameters at compile time.
wget https:Github.com/yaoweibin/nginx_tcp_proxy_module/archive/master.zipunzip Master TAR-ZXVF Nginx-1.6-1.6< Span class= "Hljs-number" >.3PATCH&NBSP;-P1&NBSP;<&NBSP; /nginx_tcp_proxy_module-master/tcp.patch ./configure --add-module=. /nginx_tcp_proxy_module-master --prefix=/usr/local/ Nginx-1.6 .3 --with-http_stub_ Status_module --with-http_gzip_static_ Modulemakemake install
The following configuration configuration is added to the nginx.conf master configuration file: (You can also configure the include in the master configuration file, which contains the configuration file include/usr/local/nginx-1.6.3/conf/tcp_proxy.conf for TCP forwarding;)
User nobody;Worker_processes1;#error_log Logs/error.log;#error_log Logs/error.log Notice;Error_log Logs/error.logInfo#pid Logs/nginx.pid;Events {Worker_connections1024;}include/usr/local/nginx-1.6.3/conf/tcp_proxy.conf;HTTP {Include Mime.types;Default_type Application/octet-stream;Log_format Main‘$remote _addr-$remote _user[$time _local] "$request" ‘‘$status$body _bytes_sent"$http _referer" ‘‘"$http _user_agent" "$http _x_forwarded_for"‘;#access_log Logs/access.log Main;SendfileOn#tcp_nopush on;#keepalive_timeout 0;Keepalive_timeout65;#gzip on;server {Listen3306;server_name localhost;#charset Koi8-r;#access_log Logs/host.access.log Main;Location/{root HTML;Index index.html index.htm; }Location/nginx_status {Stub_statusOnAccess_log Logs/nginx_status.log;Allow10.195.197.124;Deny all;}#error_page 404/404.html;# redirect server error pages to the static page /50x.html # error_page < Span class= "Hljs-number" >500 502 503 504 /50x.html; location = /50x.html { root html; } }}
include/usr/local/nginx-1.6.3/conf/tcp_proxy.conf;
TCP {Upstream MySQL {Server10.207.238.66:3306;Server10.207.238.67:3306;Check interval=Rise=2 fall=5 timeout=1000;#check interval=3000 rise=2 fall=5 timeout=1000 #check interval=3000 rise=2 fall=5 Timeout=1000 #check_http_send "get /http/1.0\r\n\r\n"; #check_http_expect_alive http_ 2xxhttp_3xx; } server {listen 3307; PROXY_PASS&NBSP;MYSQL;&NBSP;&NBSP;&NBSP;&NBSP;}}
Description
Check interval Health Check, unit is in milliseconds
Rise check the normal number of times, add reslserver to the load list
Fall after several unsuccessful checks, remove Realserver
Timeout check time-out, unit allowable milliseconds
You can see Nginx_tcp_proxy_module-master/readme, very detailed.
Nginx for MySQL load balancing