I have the latest NGINX from ppa installed on Ubuntu 16.04.

nginx version: nginx/1.12.1

From my understanding, it should support stream and UDP load balancing.

But I get this error message:

nginx: [emerg] "stream" directive is not allowed here in /etc/nginx/conf.d/load-balancer.conf:3

This is my config in /etc/nginx/conf.d/load-balancer.conf

stream {
        upstream backend {
                server fail_timeout=10s;
                server fail_timeout=10s;

        server {
                listen          500 udp;
                listen          4500 udp;
                proxy_pass      backend;
                proxy_timeout   1s;
                proxy_responses 1;
                error_log       logs/dns.log;
  • is that the whole file?
    – Mike
    Nov 12 '17 at 17:02
  • Yes Mike. This is the whole file.
    – Houman
    Nov 12 '17 at 17:02
  • The nginx configuration file is located at /etc/nginx/nginx.conf. The stream block is a top-level block. Ensure that files located in the conf.d directory are included into the top-level. Nov 12 '17 at 17:06

stream needs to be on the same level as http block so like

http { foo }
stream { bar }

My guess is your include for /etc/nginx/conf.d/*.conf is located in the http {} block and not outside of it. Checkout the /etc/nginx/nginx.conf for the include and maybe you have to make a new one for the stream section

  • I've updated the question with the path of my config. /etc/nginx/conf.d/load-balancer.conf. You are right! The include is inside the http.
    – Houman
    Nov 12 '17 at 17:08
  • Sorry Mike, I have a follow-up issue that I don't understand. Why do I need to specify the port for upstream? nginx: [emerg] no port in upstream "". Since the UDP ports are defined already under server...
    – Houman
    Nov 12 '17 at 17:20
  • 1
    you need to tell it what ports to send back to like server fail_timeout=10s;
    – Mike
    Nov 12 '17 at 18:49
  • 2
    Interestingly, the default nginx Docker image does exactly this: "My guess is your include for /etc/nginx/conf.d/*.conf is located in the http {} block and not outside of it.". So in that Docker image, you cannot use /etc/nginx/conf.d/*.conf to add stream directives.
    – javabrett
    Nov 2 '20 at 22:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.