# Scgi routing problem not DRY (update to SCGI and caching not

**URL:** <https://www.ruby-forum.com/t/scgi-routing-problem-not-dry-update-to-scgi-and-caching-not/48326>\
**Category:** Rails\
**Created:** [November 16, 2005, 4:38pm UTC](https://www.ruby-forum.com/t/scgi-routing-problem-not-dry-update-to-scgi-and-caching-not/48326 "2005-11-16T16:38:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mortonda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@mortonda](https://www.ruby-forum.com/u/mortonda)\
**Post date:** [November 16, 2005, 4:38pm UTC](https://www.ruby-forum.com/t/scgi-routing-problem-not-dry-update-to-scgi-and-caching-not/48326/1 "2005-11-16T16:38:33Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

I’m attempting to set up typo using the SCGI runner. As near as I can  
tell,  
here’s what happens, please tell me if I’m wrong:

The instructions for scgi and rails:

([Peak Obsession](http://wiki.rubyonrails.com/rails/pages/SCGI+Rails+Runner+with+Apache+2+on+Linux))

seem to indicate to set the scgi base to /scgi-bin/:

SCGIMount /scgi-bin/ 127.0.0.1:9999

and not

SCGIMount / 127.0.0.1:9999

as I would have done on first thought. Thinking about it, I conclude  
that if  
the scgi engine is on / and not /scgi-bin/, then a conditional rewrite  
rule  
isn’t needed/can’t be made, and thus page caching cannot work; apache  
won’t  
bypass running SCGI, which is how caching works.

By placing the scgi engine on /scgi-bin/, we use a conditional rewrite  
to run  
scgi if a cached file is not found:

RewriteRule ^([^.]+)$ $1.html [QSA]  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(.\*)$ /scgi-bin/$1 [QSA,L]

This introduces an ugly sgci-bin into our url, so the workaround is to  
double up  
on the routes:

map.connect ‘:controller/:action/:id’  
map.connect ‘scgi-bin/:controller/:action/:id’

which makes rails recognize the scgi-bin part of the path, and still  
write  
pretty urls too. However, this is kinda repetitive when one uses a  
bunch of  
routes, as typo does.

So, in the end, I think I can get typo running in one of two ways:

1: mount scgi on /, leave routing alone, don’t use a rewriting rule.  
Everything  
works, except no page caching can be done, because there’s no way to  
avoid scgi.

2: mount scgi on /scgi-bin and all taht, and add all the route commands  
to  
rewrite the scgi-bin out of the request. Now routing will work.

In the end, we have a problem that in order to use SCGI, we either  
violate DRY  
or we can’t cache pages.

* * *

David M.  
Maia Mailguard - [http://www.maiamailguard.com](http://www.maiamailguard.com)  
Morton Software Design and Consulting - [http://www.dgrmm.net](http://www.dgrmm.net)  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2 (MingW32)  
Comment: Using GnuPG with Thunderbird - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iD8DBQFDe1HASIxC85HZHLMRAqnMAJ9VYHnuPhp3/j1oG/1C9pYPTzHajQCdEGhI  
3YmE/KhsB+cFLdQ6CaY2UiI=  
=Q1DE  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![mortonda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@mortonda](https://www.ruby-forum.com/u/mortonda)\
**Post date:** [November 16, 2005, 5:26pm UTC](https://www.ruby-forum.com/t/scgi-routing-problem-not-dry-update-to-scgi-and-caching-not/48326/2 "2005-11-16T17:26:45Z")

</div>

If there is a solution to this then I’d be very interested to hear it.  
I spent a while with Kyle in irc trying to work though this issue but  
in the end we settled on the non-DRY doubling up on routes as at least  
it works and allows non-Rails requests to be handled straight by  
apache which to me seems to be the Right Thing.

I think it could be solved but it would require someone with intimate  
routes knowledge to know where to add in the prefix automatically when  
routes are loaded. Kyle tried a number of approaches but he seemed to  
always hit the problem that routes had already been loaded or could  
only be loaded once.

Maybe the new plugin interface exposes some useful stuff?

Paul.

---

<div class="post-metadata">

**Author:** ![mortonda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@mortonda](https://www.ruby-forum.com/u/mortonda)\
**Post date:** [November 16, 2005, 6:27pm UTC](https://www.ruby-forum.com/t/scgi-routing-problem-not-dry-update-to-scgi-and-caching-not/48326/3 "2005-11-16T18:27:07Z")

</div>

Guys,

this didn’t affect me on my OSX box running apache 1 for some reason  
(as in I didn’t need to double up on the connect calls).

However, it _does_ seem to be required on my apache 2 on linux server.

I’ve got the guts of a plugin working 50% to fix this. I’ll ping when  
it’s done.

Regards,  
Trevor

On 16-Nov-05, at 8:25 AM, Paul W. wrote:

> only be loaded once.
> 
> > can tell,
> > 
> > bypass running SCGI, which is how caching works.  
> > to double up
> > 
> > Comment: Using GnuPG with Thunderbird - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Trevor S.  
[http://somethinglearned.com](http://somethinglearned.com)

---

<div class="post-metadata">

**Author:** ![mortonda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@mortonda](https://www.ruby-forum.com/u/mortonda)\
**Post date:** [November 16, 2005, 7:39pm UTC](https://www.ruby-forum.com/t/scgi-routing-problem-not-dry-update-to-scgi-and-caching-not/48326/4 "2005-11-16T19:39:37Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Paul W. wrote:

> I think it could be solved but it would require someone with intimate  
> routes knowledge to know where to add in the prefix automatically when  
> routes are loaded. Kyle tried a number of approaches but he seemed to

This is the route (pun not intended) I was thinking of, but when I  
looked at the  
routing code, I was thoroughly confused. I’m anxious to see what Trevor  
has  
going with his plugin…

* * *

David M.  
Maia Mailguard - [http://www.maiamailguard.com](http://www.maiamailguard.com)  
Morton Software Design and Consulting - [http://www.dgrmm.net](http://www.dgrmm.net)  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.2 (MingW32)  
Comment: Using GnuPG with Thunderbird - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iD8DBQFDe3yBSIxC85HZHLMRAjsMAJ9Yp5eNGKd8g5ODb3Az/oszHorhpQCgmNkO  
YqSkS3XUSp5TmqR53C2M/GU=  
=5HOc  
-----END PGP SIGNATURE-----

---

<div class="post-metadata">

**Author:** ![mortonda](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/a6a055/32.png) [@mortonda](https://www.ruby-forum.com/u/mortonda)\
**Post date:** [November 16, 2005, 11:29pm UTC](https://www.ruby-forum.com/t/scgi-routing-problem-not-dry-update-to-scgi-and-caching-not/48326/5 "2005-11-16T23:29:22Z")

</div>

I’ve completed a plugin that fixes this for me - it works fine on my  
install of typo.

I’d rather not release it before it’s tested by at least one other  
person so if anyone is interested in testing it, please contact me  
off-list.

Regards,  
Trevor

On 16-Nov-05, at 8:25 AM, Paul W. wrote:

> only be loaded once.
> 
> > can tell,
> > 
> > bypass running SCGI, which is how caching works.  
> > to double up
> > 
> > Comment: Using GnuPG with Thunderbird - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Trevor S.  
[http://somethinglearned.com](http://somethinglearned.com)
