Nginx反代代理MySQL配置实例

Nginx官方模块: ngx_stream_core_module --with-stream_ssl_module(ssl协议支持,比如MySQL ssl)

1、查看现有编译

--user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module

2、重新编译:
--user=nginx --group=nginx --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_gzip_static_module --with-stream --with-stream_ssl_module

注意:--with-stream --with-stream_ssl_module

3、配置、检测、重启nginx:
配置:
stream { 
upstream mysql { 
zone myapp1 64k; 
server localhost:3306 weight=1 max_fails=3 fail_timeout=30s; 
#server 192.168.1.221:3306 weight=1 max_fails=2 fail_timeout=30s;    

server { 
        listen 2188; 
        proxy_connect_timeout 1s; 
        proxy_timeout 3s; 
        proxy_pass mysql; 

}

检测:

nginx -t {conf path}

启动:

nginx -c {conf path}

查看启动后代理端口 :

netstat -atupn|grep nginx

验证:

mysql -u{username} -p{password} -h {host} -P {port}

posted on 2019-09-20 15:17  xiaofei01gm  阅读(2646)  评论(0编辑  收藏  举报