更新时间:2022-08-15 11:44:47
参考地址【1】:https://www.runoob.com/linux/nginx-install-setup.html
参考地址【2】:https://www.cnblogs.com/boonya/p/7907999.html
yum -y install make gcc-c++ pcre pcre-devel zlib zlib-devel libtool openssl openssl-devel
下载地址:http://nginx.org/download/,注意:选择1.9以上版本,只有1.9以上版本才支持--with-stream。
cd /usr/local/src
wget http://nginx.org/download/nginx-1.9.10.tar.gz
tar zxvf nginx-1.9.10.tar.gz
cd nginx-1.9.10
./configure --with-stream
make & make install
whereis nginx
/usr/local/nginx/sbin/nginx -v
设置代理,将连接服务器【117.73.3.71:3306】请求转发到内网数据库【172.31.0.17:3306】。
stream {
upstream rdsmysql {
hash $remote_addr consistent;
server 172.31.0.17:3306 weight=5 max_fails=3 fail_timeout=30s;
}
server {
listen 3306;#数据库服务器监听端口
proxy_connect_timeout 10s;
proxy_timeout 300s;#设置客户端和代理服务之间的超时时间,如果5分钟内没操作将自动断开
proxy_pass rdsmysql;
}
}
cd /usr/local/nginx/sbin
./nginx
ps aux|grep nginx
/usr/local/nginx/sbin/nginx -s reload
netstat -nap|grep 3306
/usr/local/nginx/sbin/nginx -s stop
使用本地工具Navicat连接MySQL
连接失败原因:ECS服务器本身的防火墙未开放3306端口。注意:ECS的安全组只是针对外网访问做了限制,服务器本身仍然有限制,共两层限制。
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT