Drupal 7 Imagecache and CDN on lighty
The solution to fix your problems after installing the CDN module and having imagecaches not generated.
Our setup is the following:
1 Varnish (cache and loadbalancer)
2 webservers (loadbalanced) running Apache
2 static servers (loadbalanced) running Lightppd
We installed the CDN module to have all the static content rewritten to the static servers.
We configured it like so:
Origin Pull
http://OURSTATICDOMAINS
Whitelist
sites/*/files/*png
sites/*/files/*webm
sites/*/files/*f4v
sites/*/files/*jpg
sites/*/files/*jpeg
sites/*/files/*ogv
sites/*/files/*flv
sites/*/files/*gif
It rewrites all images to the static server.
Which is Great.
But imagecaches stopped working because the static server didnt generate images like the drupal server can.
The solution to this problem consist in a LUA.
At first edit /etc/lighttpd/lighttpd.conf.
Enable in server.modules the
mod_magnet
Add the following line
The path is the path to your images on the static server
magnet.attract-physical-path-to = ( "/var/www/lighttpd/rewrite_drupal.lua" )
In the file /var/www/lighttpd/rewrite_drupal.lua add the following config:
Change DRUPALDOMAIN by the domain of your actual drupal server (not the static domain).
This will allow your drupal to generate imagecaches one time.
The next request (or after a sync) the images will be on the static server and it will not redirect back, but immmediately serve the images.
attr = lighty.stat(lighty.env['physical.path'])if (not attr) then lighty.header["Location"] = "http://DRUPALDOMAIN" .. lighty.env["request.uri"] return 302end
Have Fun!












