I have the following NGINX config file:
worker_processes 4; worker_rlimit_nofile 40000; events { worker_connections 8192; } stream { upstream rancher_servers_http { least_conn; server <IP_NODE_1>:80 max_fails=3 fail_timeout=5s; server <IP_NODE_2>:80 max_fails=3 fail_timeout=5s; server <IP_NODE_3>:80 max_fails=3 fail_timeout=5s; } server { listen 80; proxy_pass rancher_servers_http; } upstream rancher_servers_https { least_conn; <IP_NODE_1>:443 max_fails=3 fail_timeout=5s; <IP_NODE_2>:443 max_fails=3 fail_timeout=5s; <IP_NODE_3>:443 max_fails=3 fail_timeout=5s; } server { listen 443; proxy_pass rancher_servers_https; } }
And I would like to whitelist certain IPs for the subdomain *.dev.mydomain.com
.
I tried to add this to the server block:
if ($host ~ *.dev.mydomain.com) { allow: <ip1>,<ip2> deny: all; }
But I have the following error:
nginx: [emerg] "if" directive is not allowed here
I then tried to add a map
. Under the server block I also have a directive not allowed here
but I can add the map inside the stream block.
When I add the map on the stream block as follow:
map $hostname $deny_ips { default all; ~*.dev.mydomain.com all; }
I can't use the deny_ips
variable in server block, I get a
[emerg] invalid parameter "deny_ips" in /etc/nginx/nginx.conf:35
Note also that I can't map $host
but I can only map $hostname
or I got a
nginx: [emerg] unknown "host" variable
Can someone please help me to whitelist certain ips based on the subdomain ?
Thank you.
http
instead ofstream
."server_name"
variable that nginx can interpret and act upon. But if you're using nginx to expose services from your kubernetes cluster I'm guessing you will only expose HTTP/S services so you can give the solution below a try.