/etc/nginx/nginx.conf:86 中的未知指令“流”

use*_*404 20 nginx stream

我有nginx/1.12.0并且根据文档它包含stream模块。我已经使用以下命令安装了 nginx。

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
nginx -v
nginx version: nginx/1.12.0
Run Code Online (Sandbox Code Playgroud)

我尝试在以下位置添加流指令nginx.conf

stream {
    upstream sys {
        server 172.x.x.x:9516;
        server 172.x.x.x:9516;
    }
    server {
        listen 9516 udp;
        proxy_pass sys;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是当我重新启动nginx时,nginx日志中出现以下错误

unknown directive "stream" in /etc/nginx/nginx.conf:86

nginx -V output
Run Code Online (Sandbox Code Playgroud)
nginx version: nginx/1.12.0
built with OpenSSL 1.0.1f 6 Jan 2014
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector --param=ssp                                                                                          -buffer-size=4 -Wformat -Werror=format-security -fPIC -D_FORTIFY_SOURCE=2' --w                                                                                          ith-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -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=/var/log/nginx/error.log --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-p                                                                                          ath=/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-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_m                                                                                          odule --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_geoip_module=dynamic --with-http_gunzip_modul                                                                                          e --with-http_gzip_static_module --with-http_image_filter_module=dynamic --wit                                                                                          h-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with                                                                                          -stream_ssl_module --with-stream_ssl_preread_module --with-mail=dynamic --with                                                                                          -mail_ssl_module --add-dynamic-module=/build/nginx-ZgS12K/nginx-1.12.0/debian/                                                                                          modules/nginx-auth-pam --add-dynamic-module=/build/nginx-ZgS12K/nginx-1.12.0/d                                                                                          ebian/modules/nginx-dav-ext-module --add-dynamic-module=/build/nginx-ZgS12K/ng                                                                                          inx-1.12.0/debian/modules/nginx-echo --add-dynamic-module=/build/nginx-ZgS12K/                                                                                          nginx-1.12.0/debian/modules/nginx-upstream-fair --add-dynamic-module=/build/ng                                                                                          inx-ZgS12K/nginx-1.12.0/debian/modules/ngx_http_substitutions_filter_module
Run Code Online (Sandbox Code Playgroud)

我在谷歌上搜索了这个错误,有些人说我必须单独安装/配置这个模块。有人说它带有nginx1.12.0 版本。有人可以建议我如何在已安装的模块上安装/配置此模块nginx吗?

问候 VG

Joe*_*ord 41

流模块被添加为动态,根据:

--with-stream=dynamic
Run Code Online (Sandbox Code Playgroud)

你需要它是“静态的”——所以直接加载模块。为此,请在 nginx.conf 的最顶部添加以下内容:

load_module /usr/lib/nginx/modules/ngx_stream_module.so;
Run Code Online (Sandbox Code Playgroud)

然后:

nginx -t
Run Code Online (Sandbox Code Playgroud)

如果一切顺利:

nginx -s reload
service nginx restart
Run Code Online (Sandbox Code Playgroud)

编辑:

-s signal' Send signal to the master process. The argument signal can be one of: stop, quit, reopen, reload. The following table shows the corresponding system signals.

stop' SIGTERM
quit' SIGQUIT
reopen' SIGUSR1
reload' SIGHUP
Run Code Online (Sandbox Code Playgroud)

  • `load_module /usr/lib64/nginx/modules/ngx_stream_module.so; ` 在某些情况下是需要的。(64位系统) (4认同)

小智 8

nginx在 AWS EC2 实例上运行的 Amazon Linux 上遇到了这个问题,我的/usr/lib64/nginx/modules/文件夹是空的。

我安装了模块yum

yum install nginx-mod-stream
Run Code Online (Sandbox Code Playgroud)

stream指令现在可以在不更改nginx.conf.


Ill*_*dan 7

没有足够的声誉来评论乔的回答,所以在这里写:

在 CentOS7 上,模块路径位于 lib64 文件夹下。所以,你需要添加这一行:

load_module '/usr/lib64/nginx/modules/ngx_stream_module.so';
Run Code Online (Sandbox Code Playgroud)