TheBlackBenzKid
TheBlackBenzKid

Reputation: 27107

How to disable Nginx index directory to only allow MaxCDN / NetDNA CDN?

I have a very large CDN purge server. It is structured like so

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

and so on.. there are large directories. I was wondering if I can disable ALL access to the directory listings /assets/, /products/, /3424/ - so basically the only people that can see the directories are the CDN purge bot. I want the CDN to be able to cache all the index folders and directories. Users would see forbidden on the directory but obviously they can see files..

Upvotes: 2

Views: 3484

Answers (1)

Jimmy Zelinskie
Jimmy Zelinskie

Reputation: 1575

I believe this can be accomplished by simply adding lines similar to this in the virtual server's config file:

server {
  listen 80; # look familiar?

  ...

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

Check out the configuration wiki on nginx's site for more about syntax and working with the config files to get them just how you want them.

Upvotes: 4

Related Questions