# Trouble with stream directive

**URL:** <https://www.ruby-forum.com/t/trouble-with-stream-directive/242368>\
**Category:** NGINX\
**Created:** [June 19, 2015, 4:56am UTC](https://www.ruby-forum.com/t/trouble-with-stream-directive/242368 "2015-06-19T04:56:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [June 19, 2015, 4:56am UTC](https://www.ruby-forum.com/t/trouble-with-stream-directive/242368/1 "2015-06-19T04:56:03Z")

</div>

I’m trying to test the TCP load balancing function in 1.9.2, but am  
having  
some problems getting a very basic configuration working. TIA

ubuntu@dev:~$ cat /etc/nginx/stream.d/test.conf  
stream {

```
server {
    listen 12345;
    proxy_pass mybackend:12345;
}

```

}  
ubuntu@dev:~$ sudo nginx -t  
nginx: [emerg] “stream” directive is not allowed here in  
/etc/nginx/stream.d/test.conf:1  
nginx: configuration file /etc/nginx/nginx.conf test failed

ubuntu@dev:~$ nginx -V  
nginx version: nginx/1.9.2  
built by gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1)  
built with OpenSSL 1.0.1f 6 Jan 2014  
TLS SNI support enabled  
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx  
–conf-path=/etc/nginx/nginx.conf  
–error-log-path=/var/log/nginx/error.log  
–http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid  
–lock-path=/var/run/nginx.lock  
–http-client-body-temp-path=/var/cache/nginx/client\_temp  
–http-proxy-temp-path=/var/cache/nginx/proxy\_temp  
–http-fastcgi-temp-path=/var/cache/nginx/fastcgi\_temp  
–http-uwsgi-temp-path=/var/cache/nginx/uwsgi\_temp  
–http-scgi-temp-path=/var/cache/nginx/scgi\_temp --user=nginx  
–group=nginx  
–with-http\_ssl\_module --with-http\_realip\_module  
–with-http\_addition\_module  
–with-http\_sub\_module --with-http\_dav\_module --with-http\_flv\_module  
–with-http\_mp4\_module --with-http\_gunzip\_module  
–with-http\_gzip\_static\_module --with-http\_random\_index\_module  
–with-http\_secure\_link\_module --with-http\_stub\_status\_module  
–with-http\_auth\_request\_module --with-threads --with-stream  
–with-stream\_ssl\_module --with-mail --with-mail\_ssl\_module  
–with-file-aio  
–with-http\_spdy\_module --with-cc-opt=‘-g -O2 -fstack-protector  
–param=ssp-buffer-size=4 -Wformat -Werror=format-security  
-Wp,-D\_FORTIFY\_SOURCE=2’ --with-ld-opt=‘-Wl,-Bsymbolic-functions  
-Wl,-z,relro -Wl,–as-needed’ --with-ipv6

Posted at Nginx Forum:

> **[Trouble with stream directive](https://forum.nginx.org/read.php?2,259748,259748#msg-259748)**
>
> I'm trying to test the TCP load balancing function in 1.9.2, but am having some problems getting a very basic configuration working. TIA ubuntu@dev:~$ cat /etc/nginx/stream.d/test.conf stream { server { listen 12345; proxy\_

---

<div class="post-metadata">

**Author:** ![kecorbin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@kecorbin](https://www.ruby-forum.com/u/kecorbin)\
**Post date:** [June 19, 2015, 6:21am UTC](https://www.ruby-forum.com/t/trouble-with-stream-directive/242368/2 "2015-06-19T06:21:57Z")

</div>

Please watch the top-level config (nginx.conf) where this file is  
included.  
Most probably it already has the “stream” directive surrounding the  
include.

> ```
> proxy_pass mybackend:12345;
> 
> ```
> 
> built by gcc 4.8.2 (Ubuntu 4.8.2-19ubuntu1)  
> –http-scgi-temp-path=/var/cache/nginx/scgi\_temp --user=nginx --group=nginx  
> -Wl,-z,relro -Wl,–as-needed’ --with-ipv6
> 
> Posted at Nginx Forum:  
> [http://forum.nginx.org/read.php?2,259748,259748#msg-259748](http://forum.nginx.org/read.php?2,259748,259748#msg-259748)
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–  
Roman A.

---

<div class="post-metadata">

**Author:** ![kecorbin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@kecorbin](https://www.ruby-forum.com/u/kecorbin)\
**Post date:** [June 19, 2015, 12:46pm UTC](https://www.ruby-forum.com/t/trouble-with-stream-directive/242368/3 "2015-06-19T12:46:19Z")

</div>

You nailed it. Thank you.

Posted at Nginx Forum:

> **[Re: Trouble with stream directive](https://forum.nginx.org/read.php?2,259748,259755#msg-259755)**
>
> I'm trying to test the TCP load balancing function in 1.9.2, but am having some problems getting a very basic configuration working. TIA ubuntu@dev:~$ cat /etc/nginx/stream.d/test.conf stream { server { listen 12345; proxy\_

---

<div class="post-metadata">

**Author:** ![KathouQC](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/57b2e6/32.png) [@KathouQC](https://www.ruby-forum.com/u/KathouQC)\
**Post date:** [August 10, 2021, 12:44am UTC](https://www.ruby-forum.com/t/trouble-with-stream-directive/242368/4 "2021-08-10T00:44:01Z")

</div>

I have the same problem maybe you can help me? I try to setup it as a proxy  
That is nginx.conf

#user nobody;  
worker\_processes 1;

#error\_log logs/error.log;  
#error\_log logs/error.log notice;  
#error\_log logs/error.log info;

#pid logs/nginx.pid;

events {  
worker\_connections 1024;

}

```
http {
    include mime.types; 
    default_type application/octet-stream;
    include stream-proxy.conf;
    proxy_cache_path /srv/cache levels=1:2 keys_zone=assets:48m max_size=20g inactive=2h;
 
    #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    # '$status $body_bytes_sent "$http_referer" '
    # '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log logs/access.log main;

    sendfile on;
    #tcp_nopush on;

    #keepalive_timeout 0;
    keepalive_timeout 65;

    #gzip on;

    server {
        listen 88;
        server_name localhost;

        #charset koi8-r;

        #access_log logs/host.access.log main;

        location / {
            root html;
            index index.html index.htm;
        }

        #error_page 404 /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
            root html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        # proxy_pass http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        # root html;
        # fastcgi_pass 127.0.0.1:9000;
        # fastcgi_index index.php;
        # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
        # include fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        # deny all;
        #}
    }

    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    # listen 8000;
    # listen somename:8080;
    # server_name somename alias another.alias;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

    # HTTPS server
    #
    #server {
    # listen 443 ssl;
    # server_name localhost;

    # ssl_certificate cert.pem;
    # ssl_certificate_key cert.key;

    # ssl_session_cache shared:SSL:1m;
    # ssl_session_timeout 5m;

    # ssl_ciphers HIGH:!aNULL:!MD5;
    # ssl_prefer_server_ciphers on;

    # location / {
    # root html;
    # index index.html index.htm;
    # }
    #}

}

```

and the is the stream-proxy.conf (i have remove my IP)

I got this error:nginx: [emerg] “stream” directive is not allowed here in C:\nginx/conf/stream-proxy.conf:2  
stream {  
upstream backend{  
server ip:port

```
    }
    server {
		listen 30120;
       
		proxy_pass backend;
	}
	server {
		listen 30120 udp reuseport;
        

		proxy_pass backend;
	}
}

```

thank
