Rails Subdomain Caching


I'm running a Rails app that uses subdomains for accounts--so each subdomain needs its own cache. I have Rails setup to cache like so:

http://subdomain.myapp.com/ -> /public/cache/subdomain/

How do I setup Litespeed to serve these cached pages?

In nginx, this would look something like:

if (-f $document_root/cache/$host/$uri/index.html) {
rewrite .? /cache/$host/$uri/index.html break;

if (-f $document_root/cache/$host/$uri.html) {
rewrite .? /cache/$host/$uri.html break;

if (-f $document_root/cache/$host/$uri) {
rewrite .? /cache/$host/$uri break;

How would this look in Litespeed? And where would I go to change this setting?



LiteSpeed Staff
Just use the rewrite rule you would use for Apache.

extract subdomain from %{HTTP_HOST} with rewrite condition, then use %1, back reference to subdoamin as part of the destination url.

Sorry--I don't entirely follow (my fault, not yours)--can you be more explicit here? What settings do I need to adjust in Litespeed to make this work? Can you give me an example of a rewrite rule?

I have set Enable Cache to yes.

I am using the following rewrite rules:

RewriteRule ^/$ /cache/%{HTTP_HOST}/index.html [QSA]
RewriteRule ^([^.]+)$ /cache/%{HTTP_HOST}$1.html [QSA]

(I actually just switched to using the entire domain as the folder, i.e. /cache/full.domain.com/CACHED_STUFF)

Will those rules work?

What else do I need to do?

Does caching work in the free edition?

Again, the rails app is producing the proper cached pages, so things should be working on that end.

Thanks in advance.


LiteSpeed Staff
If you use those rule at vhost level, rules look correct. if you use those rule at context level, you need to get rid of the leading "/" as RewriteBase has been removed from URL before matching the Rule.

Enable rewrite log and check the error.log if rules does not work as expected.

Rails page cache works with the free edition.
Cache Stylesheets and Images

Okay--it looks like this is working fine for pages. I'd also like to cache stylesheets, js, and images on a per subdomain basis. Each element is processed by the Rails app right now, but I'd like it to be cached. So:

http://my.domain.com/stylesheets/style.css > cache/my.domain.com/stylesheets/style.css

Is this possible? What do I need to change?

Caching hierarchy

So I've gotten this working perfectly--so far. Is there a way to specify a cache hierarchy? I would like the system to check the subdomain folder first, then the root folder if the asset isn't in the subdomain folder. Thanks!