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 almost 2 years
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; } }
-
Mike over 6 yearsis that the whole file?
-
Houman over 6 yearsYes Mike. This is the whole file.
-
Richard Smith over 6 yearsThe
nginx
configuration file is located at/etc/nginx/nginx.conf
. Thestream
block is a top-level block. Ensure that files located in theconf.d
directory are included into the top-level.
-
-
Houman over 6 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 6 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 6 yearsyou need to tell it what ports to send back to like
server 172.31.9.51:4500 fail_timeout=10s;
-
javabrett over 3 yearsInterestingly, 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 addstream
directives.