nginx支持tcp代理mysql
来源:互联网 发布:数据分析临界值 编辑:程序博客网 时间:2024/06/01 08:55
公司有一个公网ip,有公网ip(222.222.222.222)那台服务器上装的nginx,mysql装在公司另外一台服务器上假设ip为192.168.0.7,我想利用公网ip去访问内网电脑上mysql就可以利用我下面的配置操作了
nginx1.9及以上才可以支持tcp协议;
window上直接添加配置就可以使用,linux网上说需要下载依赖,没试过;
在nginx安装路径/nginx-1.9.0/conf
目录下nginx.conf
文件添加如下代码:
下面这段代码可以在upstream中设置多个server,目的是为了实现监听的3307端口的负载均衡,其中weight属于负载的比重数;
stream { upstream cloudsocket { hash $remote_addr consistent; server 192.168.0.7:3306 weight=5 max_fails=3 fail_timeout=30s; } server { listen 3307;#公网机器监听端口 proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass cloudsocket; }}
如果不实现负载均衡,操作更加简单,下面代码是实现用不同端口代理不同mysql的配置:
stream { server { listen 3308; proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass 192.168.0.7:3306; } server { listen 3307; proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass 192.168.0.8:3306; }}
其中192.168.0.7:3306
为内网数据库ip加端口;接下来用客户端访问:
访问测试成功!
0 0
- nginx支持tcp代理mysql
- nginx安装并支持upstream和tcp代理模块
- nginx TCP 反向代理
- Nginx TCP/UDP 代理
- nginx tcp代理
- nginx tcp代理
- nginx搭建TCP代理
- nginx代理TCP模块
- nginx tcp 反向代理
- Nginx发布1.9.0版本,新增支持TCP代理和负载均衡的stream模块
- Nginx发布1.9.0版本,新增支持TCP代理和负载均衡的stream模块
- Nginx发布1.9.0版本,新增支持TCP代理和负载均衡的stream模块
- Nginx发布1.9.0版本,新增支持TCP代理和负载均衡的stream模块
- nginx添加tcp代理模块
- Nginx实现TCP反向代理
- nginx实现tcp反向代理
- Nginx实现TCP反向代理
- 安装nginx及tcp代理
- android intent 传递list或者对象
- 设计模式笔记:观察者模式
- Android M(6.0) 权限解决方案
- 欢迎使用CSDN-markdown编辑器
- bzoj3223 文艺平衡树 Splay & Treap
- nginx支持tcp代理mysql
- 自定义层叠布局StackLayout
- Java批量文件打包下载
- 以小米4手机为例换算px,dip,dpi等数值
- Adapter不调用getView()的可能
- 合理使用Android提供的Annotation来提高代码的质量
- MySql安装过程以及中文乱码解决办法
- Effective-OC 10.在既有类中使用关联对象存储自定义数据
- Mysql字符串字段判断是否包含某个字符串的3种方法