专业的编程技术博客社区

网站首页 > 博客文章 正文

Nginx L4 stream Solution white list map

baijin 2024-12-19 10:11:07 博客文章 9 ℃ 0 评论

nginx 正向透明代理

nginx 正向透明代理 安全方面的一些限制

对于代理而已,有时候可能还不够安全,而且这个是基于4层的,所以想要在http上,或者所谓的http头上做限制还是比较难实现了。所以变通一个map实现:

TCP has no concept of server names, so this is not possible. It only works

in HTTP because the client sends the hostname it is trying to access as

TCP没有服务器名称的概念,所以这是不可能的。它只在HTTP中工作,因为客户端发送它试图访问的主机名作为请求的一部分,允许nginx将其与特定的服务器块匹配。

part of the request, allowing nginx to match it to a specific server block.

现在的需求是,限制进入L4的域名比如仅仅是www.baidu.com其他域名进来也不转发。

stream {
    resolver 114.114.114.114;
    server {
        listen 443;
        ssl_preread on;
        proxy_connect_timeout 5s;
        proxy_pass $ssl_preread_server_name:$server_port;
        allow 192.168.128.0/17;
        deny all;
    }
}

如上所示,现在仅仅能在allow这里做部分限制。当如如果是Linux主机话的,还可以在

iptables中做很多限制。但如果我的Nginx L4是一个Pod,那限制的难度就增加了。变通实现,比如我现在仅仅允许某个域名能走这个L4的透明代理

stream {
    resolver 114.114.114.114;
    map $ssl_preread_server_name $name {
               www.baidu.com backend;
                       }
    upstream backend {
               server www.baidu.com:443;
                }
    server {
        listen 443;
        ssl_preread on;
        proxy_connect_timeout 5s;
        #proxy_pass $ssl_preread_server_name:$server_port;
        proxy_pass $name;
        allow 192.168.128.0/17;
        deny all;
    }
}

其实就是变相的upstream 仅仅允许对应的域名能够upstream backend

其他的域名不做处理。

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表