解决Nginx unknown directive “stream”问题

背景
Nginx代理渠道接口的 tcp 端口时报错:unknown directive “stream”

解决
编译时,通过添加 –with-stream参数来安装 stream 模块。
需要手工加载 ngx_stream_module.so 模块。

#安装到/home/ jjtg6/soft/nginx-1.6.3,关联软件路径根据上面解压路径确定
[/home/jjtg6/soft] cd nginx-1.6.3/
[/home/jjtg6/soft/nginx-1.6.3]./configure--prefix=/home/hstc61/nginx-1.6.3 --with-openssl=/home/hstc61/openssl-1.1.1k --with-pcre=/home/hstc61/pcre-8.35  --with-zlib=/home/hstc61/zlib-1.2.11 --with-stream
#编译
[/home/jjtg6/soft/nginx-1.6.3]make
[/home/jjtg6/soft/nginx-1.6.3]make install

检查版本
[/home/jjtg6/nginx-1.6.3/sbin]./nginx -v
nginxversion: nginx/1.6.3

操作系统信息

$ uname -a
Linux oa2 3.10.0-1160.31.1.el7.x86_64 #1 SMP Thu Jun 10 13:32:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
$ cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)

Nginx 编译信息

$ ./nginx -V
Tengine version: Tengine/2.3.3
nginx version: nginx/1.18.0
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 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_addition_module --with-stream --with-stream=dynamic --with-stream_ssl_module --with-stream_realip_module --with-http_dav_module --http-proxy-temp-path=/usr/local/nginx/tmp/proxy --http-client-body-temp-path=/usr/local/nginx/tmp/client --http-fastcgi-temp-path=/usr/local/nginx/tmp/fastcgi --http-uwsgi-temp-path=/usr/local/nginx/tmp/uwsgi --http-scgi-temp-path=/usr/local/nginx/tmp/scgi --add-module=/tmp/tengine-2.3.3/modules/ngx_http_upstream_check_module --add-module=/tmp/tengine-2.3.3/modules/ngx_http_proxy_connect_module

报错信息

$ ./nginx -t
nginx: [emerg] unknown directive “stream” in /usr/local/nginx/conf/nginx.conf:11
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

nginx.conf 第一行加入

$ vi /usr/local/nginx/conf/nginx.conf
load_module /usr/local/nginx/modules/ngx_stream_module.so;

Nginx出现 `[emerg] unknown directive "stream"` 错误,通常是因为当前安装的Nginx版本未开启Stream模块,可尝试以下解决办法: ### 1. 检查Nginx是否支持Stream模块 可以通过以下命令查看Nginx编译时的参数: ```bash nginx -V ``` 如果输出中没有 `--with-stream` ,则表示当前安装的Nginx未启用Stream模块。 ### 2. 重新编译安装Nginx并启用Stream模块 - **下载Nginx源码**:从Nginx官方网站下载最新的稳定版本: ```bash wget http://nginx.org/download/nginx-1.23.4.tar.gz ``` - **解压源码包**: ```bash tar -zxvf nginx-1.23.4.tar.gz cd nginx-1.23.4 ``` - **配置编译参数**:在配置时添加 `--with-stream` 参数来启用Stream模块: ```bash ./configure --with-stream ``` - **编译并安装**: ```bash make make install ``` ### 3. 使用包管理器安装支持Stream模块的Nginx 如果你使用的是基于RPM的系统(如CentOS),可以使用Nginx官方的Yum仓库来安装支持Stream模块的Nginx: - **添加Nginx官方Yum仓库**: ```bash vim /etc/yum.repos.d/nginx.repo ``` 在文件中添加以下内容: ```plaintext [nginx-stable] name=nginx stable repo baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true [nginx-mainline] name=nginx mainline repo baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ gpgcheck=1 enabled=0 gpgkey=https://nginx.org/keys/nginx_signing.key module_hotfixes=true ``` - **安装Nginx**: ```bash yum install nginx ``` ### 4. 验证配置文件 在完成上述操作后,使用以下命令验证Nginx配置文件是否正确: ```bash nginx -t ``` 如果没有报错,即可重新启动Nginx: ```bash systemctl restart nginx ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值