【问题标题】:How to disable Nginx index directory to only allow MaxCDN / NetDNA CDN?如何禁用 Nginx 索引目录只允许 MaxCDN / NetDNA CDN?
【发布时间】:2012-02-15 17:22:05
【问题描述】:

我有一个非常大的 CDN 清除服务器。它的结构是这样的

site.com/
site.com/assets/
site.com/assets/products/3424/imgs/large.jpg
site.com/assets/products/3424/imgs/med.jpg
site.com/assets/products/3424/imgs/small.jpg
site.com/assets/products/3424/xml/xml.xml
site.com/assets/products/3424/swf/swfvideo.jpg
site.com/assets/products/3424/html5/video.ogg
site.com/assets/products/3424/mp3/mp3.jpg

等等..有很大的目录。我想知道是否可以禁用对目录列表 /assets/、/products/、/3424/ 的所有访问 - 所以基本上唯一可以看到目录的人是 CDN 清除机器人。我希望 CDN 能够缓存所有索引文件夹和目录。用户会在目录中看到禁止,但显然他们可以看到文件..

【问题讨论】:

标签: nginx cdn directory-structure


【解决方案1】:

我相信这可以通过在虚拟服务器的配置文件中简单地添加类似的行来完成:

server {
  listen 80; # look familiar?

  ...

  # something similar to this
  if ($remote_addr != cdnIP) {
    location /assets {
      deny  all;
    }
  }
}

查看 nginx 网站上的 configuration wiki 以了解有关语法和使用配置文件以获取所需的更多信息。

【讨论】:

  • 如果他们不只是一个 IP.. 它是 44.444.33.** 或 package.bucketbot.netdna.com - 我认为他们使用不同的拉区机器人怎么办?
  • 看起来你可以使用类似 $http_host 的东西来代替 $remote_addr。查看available variables,您可以在 nginx 配置中进行操作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-09-03
  • 1970-01-01
  • 1970-01-01
  • 2015-09-14
  • 2018-10-16
  • 1970-01-01
  • 2016-06-19
相关资源
最近更新 更多