【发布时间】:2019-10-12 10:00:10
【问题描述】:
我在 nginx 后面的 WebSphere 上有一个 Java Spring 应用程序。
我有my_website.com/private_urlmy_website.com/public_url
目前这两个地址都可以从任何 IP 访问。告诉 nginx 只接受来自白名单子网列表的 my_website.com/private_url 的请求的正确方法是什么?
【问题讨论】:
我在 nginx 后面的 WebSphere 上有一个 Java Spring 应用程序。
我有my_website.com/private_urlmy_website.com/public_url
目前这两个地址都可以从任何 IP 访问。告诉 nginx 只接受来自白名单子网列表的 my_website.com/private_url 的请求的正确方法是什么?
【问题讨论】:
要拒绝除某些地址以外的所有人访问特定目录或请求添加此位置块
location ^~ /private_url {
allow x.x.x.x/32;
allow x.y.x.x/16;
deny all;
}
从上到下依次检查规则,直到找到第一个匹配项。
你应该在 nginx.conf 中添加这个,但是你不想每次添加新 ip 时都编辑这个文件。因此,改为将所有 ip 地址写入 nginx 主目录的 whitelist.conf 中,并将此文件包含在 location 块中。
whitelist.conf
allow x.x.x.x/32;
allow x.y.x.x/16;
nginx.conf
location ^~ /private_url {
include whitelist.conf;
deny all;
}
【讨论】: