【问题标题】:Nginx: Restrict access by IP with exception on some routesNginx:通过IP限制访问,某些路由例外
【发布时间】:2017-09-04 15:58:14
【问题描述】:

我想知道是否可以通过 IP 限制某些资源: 我想允许每个人都使用根模式,并且我想将所有根限制为某个 IP 和子网。

在我的 nginx conf 中,我放了这个:

#1 allow pdf files access to all
location ~* /\.pdf$ {
  allow all;
}

#2 restrict to these networks
  allow <ip1>;
  allow <network1>/22;
  allow <network2>/23;

#3 deny all other network
  deny  all;

当我尝试从与块 #2 不同的 ips 进行连接时,我收到拒绝访问。 如何从块 #2 的不同 IP 访问 pdf 文件?

【问题讨论】:

    标签: nginx configuration


    【解决方案1】:

    您的方法很好,但是正则表达式错误。您当前正在匹配以 /.pdf 结尾的 URI,但您可能的意思是匹配以 .pdf 结尾的 URI。

    试试:

    location ~* \.pdf$ {
        allow all;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-30
      • 1970-01-01
      • 2022-11-02
      • 2021-12-16
      • 2017-05-08
      • 2015-03-12
      • 2015-10-21
      • 1970-01-01
      相关资源
      最近更新 更多