nginx: [emerg] "stream" directive is not allowed here
53,231
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
Related videos on Youtube
Author by
Houman
Updated on September 18, 2022Comments
-
Houman 8 monthsI 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:3This is my config in
/etc/nginx/conf.d/load-balancer.confstream { 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; } }-
Mike over 5 yearsis that the whole file? -
Houman over 5 yearsYes Mike. This is the whole file. -
Richard Smith over 5 yearsThenginxconfiguration file is located at/etc/nginx/nginx.conf. Thestreamblock is a top-level block. Ensure that files located in theconf.ddirectory are included into the top-level.
-
-
Houman over 5 yearsI'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 over 5 yearsSorry 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... -
Mike over 5 yearsyou need to tell it what ports to send back to likeserver 172.31.9.51:4500 fail_timeout=10s; -
javabrett over 2 yearsInterestingly, the defaultnginxDocker 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/*.confto addstreamdirectives.