首页 > 编程知识 正文

nginx模块开发(nginx stream配置)

时间:2023-05-06 02:24:34 阅读:66969 作者:3752

另一方面,stream模块概要stream模块一般用于tcp/UDP数据流的代理和负载均衡,可以通过stream模块代理转发TCP消息。 ngx_stream_core_module模块由1.9.0版提供。 默认情况下,没有构建此模块。 -必须使用-with stream配置参数启用。 也就是说,必须在使用./configure --with-stream编译时添加流模块。 流模块的使用方法与http模块相同,语法也基本相同。

二、使用场景说明stream主要有两个可用场景。 一是实现流量的代理转发。 这里所述的代理转发是指,只有一些端口服务被限制为活动IP地址。 例如,mysql账户一般将源地址限制为APP应用服务器,而nginx可能同时是web APP应用服务器。 开发人员需要验证一些数据库数据问题,但帐户的源地址有限制。 此时,通过在nginx中进行流传送,可以实现从开发终端向mysql的访问。 二是实现流量负载均衡。 有多个tcp或udp端口服务,如DNS。 流模块支持负载平衡算法,如轮询、最小连接数和ip_hash,从而实现数据流负载平衡。

三、配置实例0、stream块配置stream块配置与http块并列,配置在nginx.conf上,可以include方式单独配置我们的配置实例,方便管理。

stream { log _ format proxy ' $ remote _ addr [ $ time _ local ] ' $ protocol $ status $ bytes _ sent $ bytes _ received open_log_file_cache off; include/etc/nginx/conf.d/*.stream; } 1、tcp端口数据流代理#cat tcp_3306.stream

# # # # proxy_timeout 30s; proxy _ pass 192.168.10.15133603306; #需要代理的端口} 2、负载平衡配置#cat load_udp_53.stream

# # # # 配置ip_hash方案,默认轮询server 192.168.10.10:53; #在此配置为访问地址和端口server 192.168.10.20:53。 server 192.168.10.30:53; }服务器{ listen 53 UDP reuse port; 由于udp不是不可靠的传输协议,因此需要监听的端口将使用reuseport确保请求被分配给统一会话中的proxy_connect_timeout 5s。 proxy_timeout 20s; proxy_pass mydns; (四、QA 1、配置检查时报告unknown directive“流”错误信息

nginx : [ emerg ] unknown directive“stream”in/etc/nginx/nginx.conf :77

nginx :配置文件/etc/nginx/nginx.conftest failed错误原因:找不到流模块解决方案:

在nginx.conf配置文件的第一行中添加以下内容:

load _ module/usr/lib 64/nginx/modules/ngx _ stream _ module.so; 2、添加ngx_stream_module.so模块时报告错误信息:

ls : cannot access/usr/lib/nginx/modules 3360 nosuchfileordirectory报告错误原因:

ngx_stream_module.so模块路径错误解决方案:

使用nginx -V命令检查nginx的模块安装路径。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。