Rewrite before reverse proxy?

#1
I'm using LSWS 2.1.9 and love it. You've got a great product, please keep up the good work.

In my experimentation with Ruby and Rails, I've decided I want to use SCGI clustering to run my Rails app and have LSWS set up as a reverse proxy for lighttpd. This works quite well and I'm able to access everything as expected simply by setting up the lighttpd in the vhost External Apps section and creating a context of '/' that proxies to it.

However, I'd like to do some URL re-writing before my Rails app (Typo) gets the request (I'm migrating from a different blogging package with a different, but similar enough to use rewriting, pretty-URL scheme). However, turning on re-writing at the vhost level doesn't seem to pass the re-written URL on through the reverse proxy. I have logging turned up and I know that my rewrite rules are generating the URL I want, but it doesn't seem to ever give that new URL to my '/' proxy context.

Any pointers on how I'd accomplish this? I know Apache rewrite rules much better than lighttpd's scheme and so would like to do them in LSWS before the lighttpd server even sees them.

Here is exactly what I'm trying to do:

Rewrite Rules (at vhost level):
RewriteCond %{REQUEST_URI} ^\/archives\/\d{4}/.+\.html
RewriteRule ^\/archives\/(\d{4})/(.+)\.html \/articles\/$1\/99\/01\/$2 [QSA]

Log output is:
2006-01-18 14:49:27.755 [INFO] [72.224.120.167:44429-0#typo] [REWRITE] Cond: Match '/archives/2005/i-feel-like-im-floating.html' with pattern '^\/archives\/\d{4}/.+\.html', result: 1
2006-01-18 14:49:27.755 [INFO] [72.224.120.167:44429-0#typo] [REWRITE] Source URI: '/archives/2005/i-feel-like-im-floating.html' => Result URI: '/articles/2005/99/01/i-feel-like-im-floating'

Looking at my logs in Rails, it appears that the URI is getting passed to the proxy first, and then when the proxy is returning a 404, LSWS is rewriting it to the URI I want. Can this order be reversed so the rewrite happens first? If I visit the Result URI manually (by typing it into the address bar so that it doesn't get rewritten), it gives me the resulting page that I want. But how do I get this to work using the rewrite engine?

Thanks for your help and for your great product.

-Jason
 

mistwang

LiteSpeed Staff
#2
Thank you for your praise.

Unfortunately, our current reverse proxy interface just pass the original request though, the rewritten URL cannot be applied to it yet.

Instead of using lighttpd with SCGI, maybe you can try Rails on LSWS via FCGI interface on the backend, just make sure to turn off the persistent connection in the FCGI configuration, as Ruby's FCGI interface does not support persistent connection yet. Just a recommendation. :)
 
Top