There is a folder with images

/images/35/ 

35 is the number of the photo album.

Inside it are the original photos and miniatures:

 /images/35/thumbs/ /images/35/medium/ /images/35/image.jpg 

Is it possible to prescribe deny all for original images in the nginx config, but so that the images from the thumbs / and medium / folders are available?

  • Isn't it easier to shift the originals outside the images folder? - Alexey Ten

2 answers 2

Try this, it should work:

 location ~ /images/35/thumbs/.*\.(jpe?g|png|gif|ico)$ { allow all; } location ~ /images/35/medium/.*\.(jpe?g|png|gif|ico)$ { allow all; } location /images/35/.*\.(jpe?g|png|gif|ico)$ { deny all; } 

nginx seems to be watching the rules before the first match.

  • this method doesn't work either - webkostya
  • Well, sorry, I did not check. - KAGG Design

This is how it should work in one line, and immediately for all albums.

 location ~ ^/images/[0-9]+/[^/]+\.(jpe?g|png|gif)$ { deny all; } 
  • no, it did not work - webkostya
  • after making changes, restarted nginx? - Denis Ostrovsky
  • Yes, I reboot. This method works with location ~ * ^. + \. (Jpg | jpeg | gif | png) $ {deny all; } But this way we block all the pictures in general, but with the indication of folders nothing is blocked - webkostya
  • I understood, it is possible then, but the best way is to write the full path to the images folder, from the root location ~ images / [0-9] + / [^ /] + \. (Jpe? G | png | gif) $ {deny all; } - Denis Ostrovsky
  • location ~ ^ / public / images / [0-9] + / [^ /] + \. (jpe? g | png | gif) $ {deny all; } This with a full path from the root of the site does not help as soon as I have not tried it - webkostya