在Pve的Ubuntu LXC容器中,使用apt install nginx安装的Nginx中stream模块时报错
unknown directive "stream" in /etc/nginx/nginx.conf:64
这是未加载stream模块而导致的。
1. 查看stream配置选项
root@ss:/home# nginx -V
nginx version: nginx/1.24.0 (Ubuntu)
built with OpenSSL 3.0.13 30 Jan 2024
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -ffile-prefix-map=/build/nginx-5QYLpr/nginx-1.24.0=. -flto=auto -ffat-lto-objects -fstack-protector-strong -fstack-clash-protection -Wformat -Werror=format-security -fcf-protection -fdebug-prefix-map=/build/nginx-5QYLpr/nginx-1.24.0=/usr/src/nginx-1.24.0-2ubuntu7.3 -fPIC -Wdate-time -D\_FORTIFY\_SOURCE=3' --with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=stderr --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-compat --with-debug --with-pcre-jit --with-http\_ssl\_module --with-http\_stub\_status\_module --with-http\_realip\_module --with-http\_auth\_request\_module --with-http\_v2\_module --with-http\_dav\_module --with-http\_slice\_module --with-threads --with-http\_addition\_module --with-http\_flv\_module --with-http\_gunzip\_module --with-http\_gzip\_static\_module --with-http\_mp4\_module --with-http\_random\_index\_module --with-http\_secure\_link\_module --with-http\_sub\_module --with-mail\_ssl\_module --with-stream\_ssl\_module --with-stream\_ssl\_preread\_module --with-stream\_realip\_module --with-http\_geoip\_module=dynamic --with-http\_image\_filter\_module=dynamic --with-http\_perl\_module=dynamic --with-http\_xslt\_module=dynamic --with-mail=dynamic --with-stream=dynamic --with-stream\_geoip\_module=dynamic
然后,安装模式是 --with-stream=dynamic,这是动态模块编译,需要系统中有对应的ngx_stream_module.so
模块调用才可以使用stream。
2. 查找ngx_stream_module.so文件
ngx_stream_module.so 文件默认位置在 /usr/lib/nginx/modules/ngx_stream_module.so
,如果没有就使用find全局查找
find / -name 'ngx_stream_module.so' 2>/dev/null
3. 如果不存在ngx_stream_module.so文件
安装 Ubuntu 官方动态模块包
sudo apt install libnginx-mod-stream
4. 如果存在ngx_stream_module.so文件
如果文件,则可能是文件所在位置不在环境变量中,nginx无法读取到。可以在nginx.conf
最前面添加配置
# 这里是ngx_stream_module文件与nginx的相对路径
load_module modules/ngx_stream_module.so;
评论区