去评论
海欣资源

如何添加nginx中的stream模块

Spring
2022/06/18 16:13:58
模块加载位置(root用户加载):
Cd  /nginx-1.21.0

加载模块 添加–with-stream
./configure --prefix=/home /nginx/nginx --add-module=/home /nginx-rtmp-module-master --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-openssl=/home /openssl-1.1.1b --with-pcre=/home /pcre-8.43 --with-stream

加载完成后进行make编译
千万不要进行make install !!!
完成编译后 现将之前的nginx文件进行备份
Cd /home/nginx/nginx/sbin(启动文件位置)
Cp nginx nginx.bak.xxx

再将编译好的nginx文件复制过来(编译文件)
Cp  /nginx-1.21.0/objs/nginx .

因为加的是–with-stream 所以要将nginx.conf修改一下 添加上模块内容
Cd /home /nginx/nginx/conf
Vi nginx.conf

添加需要的内容,格式如下:
stream{
..........
}

重启nginx(/home/nginx/nginx/sbin)
./nginx -s reload

诶嘿!报错了.
线程数不够,具体报错忘截图了。
解决如下:
修改nginx.conf
Worker_connections 1024  改成102400

再次启动,诶嘿,又报错了
nginx 出错:socket() failed (24: Too many open files) while connecting to upstream,
修改linux打开文件句柄数,编辑vi /etc/security/limits.conf(需要root修改),添加
   <domain>      <type>          <item>         <value>
*                soft             nofile          204800
*                hard            nofile          204800

修改nginx打开文件数, 编辑nginx.conf,添加worker_rlimit_nofile值
worker_rlimit_nofile 20480;

再再次启动,诶嘿,又又报错了
nginx: [error] open() “/run/nginx.pid” failed (2: No such file or directory)(类似错误,就是找不到nginx.pid文件)
这是/logs下没有nginx.pid文件
在/home /nginx/nginx/sbin 执行
./nginx -c /home /nginx/nginx/conf/nginx.conf

再再再次执行,好了!!
查看页面,没有问题。
添加模块成功!!!