35

I have nginx/1.12.0 and as per document it contains stream module. I have installed nginx with the following commands.

sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx
nginx -v
nginx version: nginx/1.12.0

I tried to add stream directive in nginx.conf:

stream {
    upstream sys {
        server 172.x.x.x:9516;
        server 172.x.x.x:9516;
    }
    server {
        listen 9516 udp;
        proxy_pass sys;
    }
}

but when I restart nginx I am getting below error in the nginx logs

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

nginx -V output
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

I googled this error and some folks say I have to install/configure this module separately. Some says it comes with nginx 1.12.0 release. Can someone suggest how I can install/configure this module on already installed nginx?

Regards VG

3
  • Is Nginx starting with the stream module enabled? Please post the output of nginx -V. Commented Jun 27, 2017 at 7:57
  • Thanks Joe, So I have updated my question and paste my nginx -V output . Commented Jun 27, 2017 at 8:02
  • Under /usr/lib/nginx/modules I can see following modules ngx_http_image_filter_module.so ngx_http_geoip_module.so ngx_http_echo_module.so ngx_http_dav_ext_module.so ngx_http_auth_pam_module.so ngx_stream_module.so ngx_mail_module.so ngx_http_xslt_filter_module.so ngx_http_upstream_fair_module.so ngx_http_subs_filter_module.so Commented Jun 27, 2017 at 8:15

3 Answers 3

66

The stream module is being added as dynamic, as per:

--with-stream=dynamic

You need it to be 'static' - so load the module directly. To do so, add the following at the very top of your nginx.conf:

load_module /usr/lib/nginx/modules/ngx_stream_module.so;

Then:

nginx -t

If all is well:

nginx -s reload
service nginx restart

Edit:

-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
7
  • Awesome!! no more errors . Thanks alot Joe you are my savior .BTW what is nginx -s actually while running this I am getting below error nginx: option "-s" requires parameter Commented Jun 27, 2017 at 8:24
  • I edited my answer, I missed a bit. nginx -s reload reloads the master process - the service restart basically does the same thing. Commented Jun 27, 2017 at 8:28
  • what is stream module going to do? what is the use of it
    – Satish
    Commented Nov 8, 2017 at 17:42
  • 1
    What does nginx -t do?
    – A X
    Commented Dec 24, 2021 at 7:18
  • 4
    load_module /usr/lib64/nginx/modules/ngx_stream_module.so; is needed in some cases. (64bit systems)
    – Jayan
    Commented Dec 26, 2022 at 12:12
20

I have come across this issue with nginx on Amazon Linux running on AWS EC2 instance, and my /usr/lib64/nginx/modules/ folder was empty.

I installed the module with yum:

yum install nginx-mod-stream

The stream directive works now without changing the nginx.conf.

1
  • This worked for me with nginx 1.20.1 on Rocky 9.2 Commented Jun 28 at 10:38
10

Have not enough reputation to comment Joe's answer, so writing here:

On CentOS7, the modules path located under lib64 folder. So, you need to add this line:

load_module '/usr/lib64/nginx/modules/ngx_stream_module.so';
1
  • is correct. in centos 7.9, you only need to "yum install nginx-mod-stream". then nginx -t, it is up. Commented Aug 4, 2021 at 4:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .