我希望限制从外部IP访问ngnix位置。我将以下配置添加到ngnix配置文件中,但我不确定这样做是否正确。是否有更好的选择来限制外部IP访问某个位置?
map $proxy_add_x_forwarded_for $remote_ip {
default $proxy_add_x_forwarded_for;
"" $http_x_real_ip;
}
map $remote_ip $isinternal {
~^127\. 1;
~^10\. 1;
~(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.) 1;
~^192\.168\. 1;
default 0;
}
...
location /app/sniper {
if ($isinternal != 1) { return 403; }
...
}提前谢谢..。
发布于 2021-08-26 06:06:38
您应该使用nginx 地理位置模块进行IP地址映射。您的配置如下所示:
geo $internal {
default 0;
127.0.0.0/8 1;
10.0.0.0/8 1;
172.16.0.0/20 1;
192.168.0.0/24 1;
}
location /app/sniper {
if ($internal != 1) {
return 403;
}
}https://serverfault.com/questions/1075674
复制相似问题