14

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 {
                least_conn;
                server 172.31.9.51 fail_timeout=10s;
                server 172.31.20.140 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. – Richard Smith Nov 12 '17 at 17:06
25

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

| improve this answer | |
  • 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 "172.31.9.51". 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 172.31.9.51:4500 fail_timeout=10s; – Mike Nov 12 '17 at 18:49

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.