当前位置:首页 » 文件传输 » nginx过滤内网访问
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

nginx过滤内网访问

发布时间: 2023-08-04 16:10:08

A. nginx怎么设置指定目录ip访问限制

nginx中针对目录进行IP限制 ,这里以phpmyadmin目录只能让内网IP访问,而外网不能访问的配置方法。

nginxphpmyadmin针对内网ip用户开放、外网ip用户关闭(在前面的配置中,location ~ ^/目录/使用正则, 优先级高于location /的配置,所以nginx无法对首页进行解析)

代码如下:

server{
listen80;
server_nameexample.com;
access_loglogs/access.logmain;
location/{
roothtml;
indexindex.phpindex.htmlindex.htm;
}
location~^/phpmyadmin/{
allow192.168.1.0/24;
denyall;
location~.*.(php|php5)?${
root/var/mailapp/nginx/html;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
includefastcgi_params;
}
}
location~.*.(php|php5)?${
root/opt/nginx/html;
fastcgi_pass127.0.0.1:9000;
fastcgi_indexindex.php;
includefastcgi_params;
}
}

B. nginx 配置限制源地址访问

F5要设置一下,把真实的IP地址透传给后端,不然的话,后端的设备获取的是内网地址。
查了一下F5设置透传的功能,不知道在是否有效,你可以验证一下。

具体步骤
1:Local Traffic-Profiles-Http-改“Insert XForwarded For”为Enable
2:Local Traffic-Virtual servers-点击需要改动的VS-将Type选项更改为Standard-将HTTP Profile 选项更改为Http

C. nginx怎么禁止指定网站来源的用户访问

楼上说的确实是使用if和$http_referer进行判断,但是说的不够详细。

举个例子,你不想让来自site.ru的流量访问的话,nginx规则可以这么写

if ($http_referer ~* "http://site.ru") {
return 444;
}

将其添加到HTTP段落或者SERVER段落都行。

当然这里还有详细的教程你可以看一下:网页链接

设置完之后别忘了 nginx -s reload 重载入配置文件,否则不生效。