# 1.9 stream not working? 'directive is not allowed here'

**URL:** <https://www.ruby-forum.com/t/1-9-stream-not-working-directive-is-not-allowed-here/241761>\
**Category:** NGINX\
**Created:** [April 28, 2015, 11:14pm UTC](https://www.ruby-forum.com/t/1-9-stream-not-working-directive-is-not-allowed-here/241761 "2015-04-28T23:14:27Z")\
**Posts on this page:** 6\
**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:** [April 28, 2015, 11:14pm UTC](https://www.ruby-forum.com/t/1-9-stream-not-working-directive-is-not-allowed-here/241761/1 "2015-04-28T23:14:27Z")

</div>

Hmm, following:

> **[TCP and UDP Load Balancing | NGINX Documentation](https://docs.nginx.com/nginx/admin-guide/load-balancer/tcp-udp-load-balancer/)**
>
> This chapter describes how to use NGINX Plus and NGINX Open Source to proxy and load balance TCP and UDP traffic.

I get a nginx: [emerg] “stream” directive is not allowed here  
eventhough its within the http context like upstreams are, anyone with a  
good example? or did I stumble on a context eval bug?

Posted at Nginx Forum:

> **[1.9 stream not working? 'directive is not allowed here'](https://forum.nginx.org/read.php?2,258463,258463#msg-258463)**
>
> Hmm, following: http://nginx.com/resources/admin-guide/tcp-load-balancing/ I get a nginx: \[emerg\] "stream" directive is not allowed here eventhough its within the http context like upstreams are, anyone with a good example? or did I stumble...

---

<div class="post-metadata">

**Author:** ![itpp2012](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/f05b48/32.png) [@itpp2012](https://www.ruby-forum.com/u/itpp2012)\
**Post date:** [April 28, 2015, 11:34pm UTC](https://www.ruby-forum.com/t/1-9-stream-not-working-directive-is-not-allowed-here/241761/2 "2015-04-28T23:34:19Z")

</div>

On 4/29/15 12:13 AM, itpp2012 wrote:

> Hmm, following: [NGINX | F5](http://nginx.com/resources/admin-guide/tcp-load-balancing/)  
> I get a nginx: [emerg] “stream” directive is not allowed here  
> eventhough its within the http context like upstreams are, anyone with a  
> good example? or did I stumble on a context eval bug?

Put it in the same level as http. E.g.

…  
http { foo }

stream { bar }

# EOF

–  
Maxim K.

> **[F5 NGINX: Built for cloud-native apps. Ready for AI traffic.](https://www.f5.com/products/nginx)**
>
> Deliver modern applications with NGINX. Explore high-performance load balancing, API gateways, and web server solutions trusted by top global enterprises.

---

<div class="post-metadata">

**Author:** ![itpp2012](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/f05b48/32.png) [@itpp2012](https://www.ruby-forum.com/u/itpp2012)\
**Post date:** [April 28, 2015, 11:36pm UTC](https://www.ruby-forum.com/t/1-9-stream-not-working-directive-is-not-allowed-here/241761/3 "2015-04-28T23:36:39Z")

</div>

On 29.04.2015 00:13, itpp2012 wrote:

> Hmm, following: [http://nginx.com/resources/admin-guide/tcp-load-balancing/](http://nginx.com/resources/admin-guide/tcp-load-balancing/)  
> I get a nginx: [emerg] “stream” directive is not allowed here  
> eventhough its within the http context

You need to define it in the main context.

See [Module ngx\_stream\_core\_module](http://nginx.org/r/stream) for details.

---

<div class="post-metadata">

**Author:** ![itpp2012](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/f05b48/32.png) [@itpp2012](https://www.ruby-forum.com/u/itpp2012)\
**Post date:** [April 29, 2015, 12:28am UTC](https://www.ruby-forum.com/t/1-9-stream-not-working-directive-is-not-allowed-here/241761/4 "2015-04-29T00:28:04Z")

</div>

It needs to be at the -same- level as the http {} block, not -within-  
the  
http {} block.

worker\_processes 4;

events {  
worker\_connections 8192;  
}

http {  
include mime.types;  
default\_type application/octet-stream;  
}

stream {  
upstream stream\_backend {  
server 192.168.222.22:810 weight=5;  
server 192.168.222.17:810 weight=5;  
}  
server {  
listen 12345;  
proxy\_pass stream\_backend;  
}  
}

---

<div class="post-metadata">

**Author:** ![itpp2012](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/f05b48/32.png) [@itpp2012](https://www.ruby-forum.com/u/itpp2012)\
**Post date:** [April 28, 2015, 11:49pm UTC](https://www.ruby-forum.com/t/1-9-stream-not-working-directive-is-not-allowed-here/241761/5 "2015-04-28T23:49:31Z")

</div>

Minimal conf;

worker\_processes 4;

events {  
worker\_connections 8192;  
}

http {  
include mime.types;  
default\_type application/octet-stream;

```
stream {
    upstream stream_backend {
        server 192.168.222.22:810 weight=5;
        server 192.168.222.17:810 weight=5;
    }
}

server {
    listen 12345;
    proxy_pass stream_backend;
}

```

}

nginx -t  
nginx: [emerg] “stream” directive is not allowed here in  
conf\nginx.conf:11  
nginx: configuration file conf\nginx.conf test failed

Whats incorrect here then?

Posted at Nginx Forum:

> **[Re: 1.9 stream not working? 'directive is not allowed here'](https://forum.nginx.org/read.php?2,258463,258467#msg-258467)**
>
> Hmm, following: http://nginx.com/resources/admin-guide/tcp-load-balancing/ I get a nginx: \[emerg\] "stream" directive is not allowed here eventhough its within the http context like upstreams are, anyone with a good example? or did I stumble...

---

<div class="post-metadata">

**Author:** ![itpp2012](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/f05b48/32.png) [@itpp2012](https://www.ruby-forum.com/u/itpp2012)\
**Post date:** [April 29, 2015, 9:05am UTC](https://www.ruby-forum.com/t/1-9-stream-not-working-directive-is-not-allowed-here/241761/6 "2015-04-29T09:05:07Z")

</div>

## Robert P. Wrote:

> It needs to be at the -same- level as the http {} block, not -within-  
> the http {} block.

Ah! makes sense as a stream is not http.  
That passes -t

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,258463,258481#msg-258481](http://forum.nginx.org/read.php?2,258463,258481#msg-258481)
