The nginx docs and guides show that you can perform ip-based whitelisting/blacklisting inside a stream
block.
However, I cannot find out how to allow
/deny
connections based on ip, for only certain hostnames that are read using ssl preread.
Situation
I have a nginx box that is proxying for many services on a private network. Some of these services should be exposed outside the network, while some should not. This nginx box is proxying both internal and external connections.
# TCP proxying with SSL passthrough & vhosts
stream {
map $ssl_preread_server_name $name {
public.example.com public;
private.example.com private;
default default_upstream;
}
upstream public {
server 10.0.0.2:443;
}
upstream private {
server 10.0.0.3:443;
}
upstream default_upstream {
server 10.0.0.4:443;
}
server {
listen 443;
proxy_pass $name;
ssl_preread on;
}
}
How can I apply ip based blocking to only connections headed for private.example.com
?
I found one simple way how to solve your issue. You should use additional
server
block to filter IPs. So, your config should looks like this one:Try with the below code block.
Tested and working just fine. Telnet on port 443 will successfully establish but on checking through a web browser you'll notice the connection is being closed for unwanted clients.