nginx常规使用时作为http协议的反向代理,这里要讲的是非http的Mysql端口代理,理论支持其他协议
nginx.conf配置如下:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/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 /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
# 重点配置
stream {
upstream cloudsocket {
hash $remote_addr consistent;
# $binary_remote_addr;
server 116.115.119.7:33306 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 33306;#数据库服务器监听端口
proxy_connect_timeout 10s;
proxy_timeout 300s;#设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
proxy_pass cloudsocket;
}
}
# 重点配置
stream {upstream cloudsocket {
hash $remote_addr consistent;
# $binary_remote_addr;
server 116.115.119.7:33306 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 33306;#数据库服务器监听端口
proxy_connect_timeout 10s;
proxy_timeout 300s;#设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开。
proxy_pass cloudsocket;
}
}
原创文章,作者:sunnyman218,如若转载,请注明出处:https://blog.ytso.com/243923.html