nginx1.9实现TCP代理转发
2016-04-14 17:06
886 查看
1.软件下载(目前最稳定版本):
wget http://nginx.org/download/nginx-1.9.12.tar.gz
2.建立nginx运行用户和程序目录:
6、实例配置
准备两个mysql实例,详细如下:
server 192.168.100.70:3306 ;
server 192.168.100.71:3306 ;
案例如下:
健康检查、负载配置参考 https://www.nginx.com/resources/admin-guide/tcp-load-balancing/
资料nginx 限制
https://www.nginx.com/resources/admin-guide/restricting-access-tcp/upstream https://www.nginx.com/resources/admin-guide/load-balancer
wget http://nginx.org/download/nginx-1.9.12.tar.gz
2.建立nginx运行用户和程序目录:
groupadd www useradd -s /sbin/nologin -g www www mkdir -p /usr/local/nginx mkdir -p /usr/local/pcre mkdir -p /data/nginxlog/ tar xvf nginx1.9.tar cd /workspace/nginx1.93.安装pcre
unzip pcre-8.32.zip cd pcre-8.32 ./configure --prefix=/usr/local/pcre --enable-utf8 --enable-pcregrep-libbz2 --enable-pcregrep-libz make && make install cd .. pwd tar -xvf nginx-1.9.12.tar.gz cd nginx-1.9.12
./configure --user=www --group=www \ --prefix=/usr/local/nginx \ --with-pcre \ --with-pcre=/workspace/nginx1.9/pcre-8.32 \ --with-http_ssl_module \ --with-http_gzip_static_module \ --with-http_stub_status_module \ --with-stream \ --with-stream_ssl_module \ --sbin-path=/usr/sbin/nginx \ --error-log-path=/data/nginxlog/error.log \ --http-log-path=/data/nginxlog/access.log4、nginx做个快捷方式
ln -s /usr/local/nginx/sbin/nginx/ /usr/sbin/5、启动nginx
6、实例配置
准备两个mysql实例,详细如下:
server 192.168.100.70:3306 ;
server 192.168.100.71:3306 ;
案例如下:
1、nginx 主配置文件nginx.conf添加内容如下: events { worker_connections 1024; } stream { include /usr/local/nginx/conf/stream_conf/*.conf; limit_conn_zone $binary_remote_addr zone=ip_addr:10m; #定义限制IP连接数名称,与大小 $binary_remote_addr以2进制存放远程地址 } 2、然后建立相应目录 mkdir -p /usr/local/nginx/conf/stream_conf/ cd /usr/local/nginx/conf/stream_conf/ 3、vim mysql3306.conf配置文件如下: upstream db { hash $remote_addr consistent; #iphash根据访问地址分配到固定的后端服务器。 server 192.168.100.70:3306; server 192.168.100.71:3306; } server { listen 3306; proxy_pass db; proxy_connect_timeout 1s; #快速故障检查 proxy_timeout 3s; #设置超时时间,连接将超时断开。 proxy_download_rate 1k; #限制下载速度为1k proxy_upload_rate 10k; #限制上传速度为10k limit_conn ip_addr 1; ##是限制每个IP只能发起1个连接 (addr 要跟 limit_conn_zone 的变量对应) allow 127.0.0.1; #acl,设置允许访问IP地址; deny all; }
健康检查、负载配置参考 https://www.nginx.com/resources/admin-guide/tcp-load-balancing/
资料nginx 限制
https://www.nginx.com/resources/admin-guide/restricting-access-tcp/upstream https://www.nginx.com/resources/admin-guide/load-balancer
相关文章推荐
- nginx代理指定目录
- 访问Nginx发生SSL connection error的一种情况
- Nginx+Naxsi部署专业级Web应用防火墙
- CentOS 6.2实战部署Nginx+MySQL+PHP
- nginx中http核心模块的配置指令2
- nginx中http核心模块的配置指令3
- nginx中http核心模块的配置指令4
- nginx中http的fastcgi模块的配置指令1
- Nginx 学习笔记(一)
- 网站502与504错误分析
- 用zabbix监控nginx_status状态
- 用PS实现纹理浮雕效果代码
- 用vbs实现cmd功能的代码
- 用双网卡实现三机互联
- 艰难完成 nginx + puma 部署 rails 4的详细记录
- 把Lua编译进nginx步骤方法
- C#中实现判断某个类是否实现了某个接口
- DL.DT.DD实现左右的布局简单例子第1/2页
- TCP版backshell的VBS脚本代码