I'm deploying a Drupal 7 application in an environment where the web server's DocumentRoot is mounted read-only (so Drupals root directories and all directories below are not writable). For storing files a separate directory outside of DocumentRoot is provided which is mounted read/write. This directory is accessible from a separate web server instance (which only serves static files without executing PHP code, e.g. static.example.com).
What I did:
- setting file_public_path to said writabke directory
- implementing hook_file_url_alter to modify URIs in the public scheme to point to the separate web server instance
Everything seems to work fine (CSS, ...), except for delivering images. Drupal's concept for delivering images is whenever a requested image resolution isn't found on disk, the thumbnailing mechanism is invoked instead. The thumbnailer creates a new image, which is delivered to the requesting browser and stored below sites/default/files. Subsequent requests deliver the image directly from the disk (using Apache's rewrite rules, so PHP isn't involved any more).
Since we are using varnish in front of the web server, I'd prefer a different way of handling images:
- images are served from a different virtual host (e.g. image.example.com)
- thumbnailed images are never written to disk
- instead a Cache-Control header is sent using a reasonable long max-age value, so varnish's LRU expiration mechanism can keep the often used images in memory and discard unused images
Any ideas how to accomplish this?
/sites/*/files/images
and then mount a share from image.example.com to that directories. The rest is minor and can be accomplished at theming level, for example.