Centos 7配置使用nginx反向代理mysql 您所在的位置:网站首页 nginx分流 Centos 7配置使用nginx反向代理mysql

Centos 7配置使用nginx反向代理mysql

#Centos 7配置使用nginx反向代理mysql| 来源: 网络整理| 查看: 265

背景:由于WEB服务和MySQL数据库服务分开部署的,由于网络问题限制,有时需要通过中间代理服务器跳转连接MySQL,所以需要在中间服务器上配置代理。

1、添加stearm模块

# nginx通常代理http协议属于第七层,要代理其他协议就要用到第四层协议,需要用到Nginx的stream模块。 # 查看nginx是否编译时添加了stream模块 nginx -V # 如果未添加stream模块,请重新编译添加 ./configure --with-stream

2、配置nginx反向代理

# 在nginx.conf中添加stream模块 stream { include /etc/nginx/stream/*.conf; } # 在nginx安装路径下创建stream文件夹,并在下面创建stream的反向代理配置文件 mkdir -p /etc/nginx/stream cd /etc/nginx/stream vim mysql3306.conf # 在mysql3306.conf中添加代理配置 upstream mysql { server x.x.x.x:3306; } server { listen 3306; proxy_connect_timeout 8s; proxy_timeout 24h; proxy_pass mysql; } # x.x.x.x是你实际服务器ip地址 # 重启nginx nginx -c /etc/nginx/nginx.conf

3、防火墙配置

firewall-cmd --permanent --add-port=3306/tcp firewall-cmd --reload

4、验证mysql连接

mysql -h {host} -P 3306 -uroot -p # 这里的host为代理服务器的ip地址


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有