首页 > 其他 > 详细

nginx实现tcp代理--ngx_stream_core_module

时间:2021-08-25 17:58:14      阅读:7      评论:0      收藏:0      [点我收藏+]

Nginx------ngx_stream_core_module
*stream 模块用于一般的 TCP 代理和负载均衡。
安装stream模块
[root@hhht-hly-hly-srv02 conf.d]# nginx -V ####原安装模块
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/src/nginx-module-vts-0.1.18/ --with-http_stub_status_module --with-http_sub_module

安装stream模块实现tcp代理
cd nginx-1.14.2/
[root@hhht-hly-hly-srv02 nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/src/nginx-module-vts-0.1.18/ --with-http_stub_status_module --with-http_sub_module --with-stream

[root@hhht-hly-hly-srv02 nginx-1.14.2]# make

Nginx -s stop

备份原有的nginx二进制文件

Mv /use/sbin/nginx{,.bak}

替换原nginx二进制文件

Cp objs/nginx /use/sbin/

启动nginx

[root@hhht-hly-hly-srv02 nginx-1.14.2]# nginx

查看版本模块信息:nginx -V
[root@hhht-hly-hly-srv02 conf.d]# nginx -V
nginx version: nginx/1.14.2
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/src/nginx-module-vts-0.1.18/ --with-http_stub_status_module --with-http_sub_module --with-stream

配置nginx配置文件。

1,nginx.conf
http{
.....
stream {
proxy_connect_timeout 3s;
include ./conf.d/*.stream.conf;
}
.....
}

[root@hhht-hly-hly-srv02 conf.d]# cat proxy-server.http.conf
server {
listen 8081;
server_name localhost;
location / {
proxy_pass http://10.2.19.177:8787;
}
}
server {
listen 8082;
server_name localhost;
location / {
proxy_pass http://10.2.19.177:3000;
}
}

[root@hhht-hly-hly-srv02 conf.d]# cat proxy-server.stream.conf

server {
listen 8083;
proxy_connect_timeout 10s;
proxy_timeout 30s;
proxy_pass 10.2.19.171:3306;
}
server {
listen 8084;
proxy_connect_timeout 10s;
proxy_timeout 30s;
proxy_pass 10.2.19.171:7001;
}
server {
listen 8085;
proxy_connect_timeout 10s;
proxy_timeout 30s;
proxy_pass 10.2.19.171:5672;
}

nginx实现tcp代理--ngx_stream_core_module

原文:https://www.cnblogs.com/LiuXiangYang/p/15185512.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!