LiteSpeed Technologies
Download Download     Blog Blog     Wiki Wiki     Forum Forum     Store     Contact Contact    

Go Back   LiteSpeed Support Forums > External Applications > Ruby/Rails > Rails Subdomain Caching

Reply
 
Thread Tools Display Modes
  #1  
Old 05-21-2009, 02:05 PM
ideaoforder ideaoforder is offline
Member
 
Join Date: Jul 2008
Posts: 28
Default Rails Subdomain Caching

Hello,

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?

Thanks!
Reply With Quote
  #2  
Old 05-21-2009, 09:35 PM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,583
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.
Reply With Quote
  #3  
Old 05-26-2009, 08:22 AM
ideaoforder ideaoforder is offline
Member
 
Join Date: Jul 2008
Posts: 28
Default Apologies

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.
Reply With Quote
  #4  
Old 05-26-2009, 10:10 AM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,583
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.
Reply With Quote
  #5  
Old 05-27-2009, 08:21 AM
ideaoforder ideaoforder is offline
Member
 
Join Date: Jul 2008
Posts: 28
Default 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?

Thanks!
Reply With Quote
  #6  
Old 05-27-2009, 02:05 PM
mistwang mistwang is offline
LiteSpeed Staff
 
Join Date: May 2003
Location: New Jersey
Posts: 7,583
You need to add a new rule like
RewriteRule ^([^.]+\.css)$ /cache/%{HTTP_HOST}/$1
Reply With Quote
  #7  
Old 02-16-2010, 02:32 PM
ideaoforder ideaoforder is offline
Member
 
Join Date: Jul 2008
Posts: 28
Default 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!
Reply With Quote
  #8  
Old 02-16-2010, 06:04 PM
NiteWave NiteWave is offline
LiteSpeed Staff
 
Join Date: Sep 2009
Posts: 2,216
Sounds this is what you want?

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
Quote:
Search pages in more than one directory
Description:
Sometimes it is necessary to let the webserver search for pages in more than one directory. Here MultiViews or other techniques cannot help.
The example in above URL explain the detail.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 05:01 PM.



- Archive - Top
© Copyright 2003-2011 LiteSpeed Technologies, Inc. All rights reserved. Privacy Policy.