We have a rails app that dynamically generates thumbnails on request and saves the result locally to make it faster to serve up the same one again. We use the following url structure:


Where 99999 is the database record the thumb is linked to. The problem is the number of records with thumbnails is maxing out the directory limit.

Any ideas on how to get around this while maintaining the built in automatic cache retrieval that rails gives you with the public folder?

The end goal is to be able to dynamically generate arbitrary thumbnails on demand and cache the result locally.


Use subdirectories, like:


and so on. Create as many subdirectories as you think are necessary for the unique identifier of your image, e.g.,:


You may need to be aware of the inode limits on your filesystem.

  • and how do I then tell nginx to map /thumbnails/99999/large.jpg to /thumbnails/099/999/large.jpg ? Or would you suggest we change it on the web request side too? More tedious than I was hoping, but I guess doable.
    – chrishomer
    Aug 13 '12 at 18:11
  • Well, certainly changing the request so that it hits the physical file would be best, as it removes a complication. It's possible to do a redirect through some regex, but that will be a lot more trouble than it's worth.
    – cjc
    Aug 13 '12 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.