Nginx reverse proxy MySQL configuration example

Nginx official module: ngx_stream_core_module --with-stream_ssl_module (ssl protocol support, such as MySQL ssl)

1. View the existing compilation

--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; 

}

Detection:

nginx -t {conf path}

start up:

nginx -c {conf path}

View the proxy port after startup:

netstat -atupn|grep nginx

verify:

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

Reprinted in: https://www.cnblogs.com/yxfcnbg/p/11557425.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324772483&siteId=291194637