Kyle Maxwell | 27 Sep 12:16

SCGI + apache solution

The following fixes caching, etc in Apache + SCGI.  It would be nice
to not have to repeat oneself in the routes file, but I'm sure someone
can come up with a solution for that.  Doubling up the routes lets the
first route generate a clean url_for, and the second one handles the
actual redirected url.

Kyle Maxwell

#in httpd.conf
SCGIMount /scgi-bin/ 127.0.0.1:9999

#in .htaccess, replace the dispatch.(f)cgi line with:
RewriteRule ^(.*)$ /scgi-bin/$1 [QSA,L]

#in routes.rb, double up *each* of your routes as so:
map.connect ':controller/:action/:id'
map.connect 'scgi-bin/:controller/:action/:id'
yufan shi | 27 Sep 15:31

Re: SCGI + apache solution

Hi Kyle, now I understand your solution very well. It's good enough to
fix the url handling issue.
It's better if we could avoid config for this in rails application's directory.
Nice job!

2005/9/27, Kyle Maxwell <kyle@...>:
> The following fixes caching, etc in Apache + SCGI.  It would be nice
> to not have to repeat oneself in the routes file, but I'm sure someone
> can come up with a solution for that.  Doubling up the routes lets the
> first route generate a clean url_for, and the second one handles the
> actual redirected url.
>
> Kyle Maxwell
>
> #in httpd.conf
> SCGIMount /scgi-bin/ 127.0.0.1:9999
>
> #in .htaccess, replace the dispatch.(f)cgi line with:
> RewriteRule ^(.*)$ /scgi-bin/$1 [QSA,L]
>
> #in routes.rb, double up *each* of your routes as so:
> map.connect ':controller/:action/:id'
> map.connect 'scgi-bin/:controller/:action/:id'
> _______________________________________________
> Rails mailing list
> Rails@...
> http://lists.rubyonrails.org/mailman/listinfo/rails
>

--
(Continue reading)

Curt Hibbs | 27 Sep 15:56

Re: SCGI + apache solution

Yikes! Isn't there a better way?

I'm no apache expert, so maybe this is as good as it gets. But I'd sure like to find something better if anyone has any ideas... esepcially, as Yufan says, if we can avoid any configuration in the rails application's directories.

Curt

On 9/27/05, yufan shi <yufanshi <at> gmail.com> wrote:
Hi Kyle, now I understand your solution very well. It's good enough to
fix the url handling issue.
It's better if we could avoid config for this in rails application's directory.
Nice job!


2005/9/27, Kyle Maxwell < kyle-FOSOgQihYpQjo0HpFSRKWA@public.gmane.org>:
> The following fixes caching, etc in Apache + SCGI.  It would be nice
> to not have to repeat oneself in the routes file, but I'm sure someone
> can come up with a solution for that.  Doubling up the routes lets the
> first route generate a clean url_for, and the second one handles the
> actual redirected url.
>
> Kyle Maxwell
>
> #in httpd.conf
> SCGIMount /scgi-bin/ 127.0.0.1:9999
>
> #in .htaccess, replace the dispatch.(f)cgi line with:
> RewriteRule ^(.*)$ /scgi-bin/$1 [QSA,L]
>
> #in routes.rb, double up *each* of your routes as so:
> map.connect ':controller/:action/:id'
> map.connect 'scgi-bin/:controller/:action/:id'
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Regards.

Yufan
===========================
Feed-Tank.com : Easy to use online feeds aggregator and reader.
FT80off: Use this code to get up to $80 off for any dreamhost hosting plan.
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/r74wrMN1lrk@public.gmane.orgg
http://lists.rubyonrails.org/mailman/listinfo/rails

_______________________________________________
Rails mailing list
Rails@...
http://lists.rubyonrails.org/mailman/listinfo/rails
Kyle Maxwell | 27 Sep 22:45

Re: SCGI + apache solution

The problem with Apache is that there is no way to detect whether a
location maps directly to a file in the filesystem using a <Location>
directive.  The only directive that I know of that will do that is
RewriteCond.  So you have to use RewriteCond to check for the file,
then RewriteRule to push the request to a different location, then
<Location> to handle the new location.  It could be worse.

The main problem with this solution, in my eyes, is that it requires
you to double up the routes.  While this has no side effects in, say,
a webrick development server, its ugly and violates DRY.  It would be
great if someone who really knows the rails source were to write a
module to automatically duplicate the routes.  Then you could
potentially just insert that module into your environment.

If you don't use caching, and just want a better <Location> match,
don't worry about the .htaccess and routes.rb use the below in your
httpd.conf.  It tells scgi to ignore any urls in the images,
javascripts, or stylesheets folders, as well as any file in the
public/ root folder that has a period in the middle.

SCGIMount / 127.0.0.1:9999
<Location ~^/(images|javascript|stylesheets|[^/]+\.[^/]+$)>
SCGIHandler Off
</Location>

Zed, of course you can post this on your site.

Kyle Maxwell

On 9/27/05, Curt Hibbs <curt.hibbs@...> wrote:
> Yikes! Isn't there a better way?
>
>  I'm no apache expert, so maybe this is as good as it gets. But I'd sure
> like to find something better if anyone has any ideas... esepcially, as
> Yufan says, if we can avoid any configuration in the rails application's
> directories.
>
>  Curt
>
>
> On 9/27/05, yufan shi <yufanshi@...> wrote:
> >
> > Hi Kyle, now I understand your solution very well. It's good enough to
> > fix the url handling issue.
> > It's better if we could avoid config for this in rails application's
> directory.
> > Nice job!
> >
> >
> > 2005/9/27, Kyle Maxwell < kyle@...>:
> > > The following fixes caching, etc in Apache + SCGI.  It would be nice
> > > to not have to repeat oneself in the routes file, but I'm sure someone
> > > can come up with a solution for that.  Doubling up the routes lets the
> > > first route generate a clean url_for, and the second one handles the
> > > actual redirected url.
> > >
> > > Kyle Maxwell
> > >
> > > #in httpd.conf
> > > SCGIMount /scgi-bin/ 127.0.0.1:9999
> > >
> > > #in .htaccess, replace the dispatch.(f)cgi line with:
> > > RewriteRule ^(.*)$ /scgi-bin/$1 [QSA,L]
> > >
> > > #in routes.rb, double up *each* of your routes as so:
> > > map.connect ':controller/:action/:id'
> > > map.connect 'scgi-bin/:controller/:action/:id'
> > > _______________________________________________
> > > Rails mailing list
> > > Rails@...
> > > http://lists.rubyonrails.org/mailman/listinfo/rails
> > >
> >
> >
> > --
> > Regards.
> >
> > Yufan
> > ===========================
> > Feed-Tank.com : Easy to use online feeds aggregator and reader.
> > FT80off: Use this code to get up to $80 off for any dreamhost hosting
> plan.
> > _______________________________________________
> > Rails mailing list
> > Rails@...
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>
>
> _______________________________________________
> Rails mailing list
> Rails@...
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
Curt Hibbs | 27 Sep 23:36

Re: SCGI + apache solution

Thanks!

On 9/27/05, Kyle Maxwell <kyle-FOSOgQihYpQjo0HpFSRKWA@public.gmane.org> wrote:
The problem with Apache is that there is no way to detect whether a
location maps directly to a file in the filesystem using a <Location>
directive.  The only directive that I know of that will do that is
RewriteCond.  So you have to use RewriteCond to check for the file,
then RewriteRule to push the request to a different location, then
<Location> to handle the new location.  It could be worse.

The main problem with this solution, in my eyes, is that it requires
you to double up the routes.  While this has no side effects in, say,
a webrick development server, its ugly and violates DRY.  It would be
great if someone who really knows the rails source were to write a
module to automatically duplicate the routes.  Then you could
potentially just insert that module into your environment.

If you don't use caching, and just want a better <Location> match,
don't worry about the .htaccess and routes.rb use the below in your
httpd.conf.  It tells scgi to ignore any urls in the images,
javascripts, or stylesheets folders, as well as any file in the
public/ root folder that has a period in the middle.

SCGIMount / 127.0.0.1:9999
<Location ~^/(images|javascript|stylesheets|[^/]+\.[^/]+$)>
SCGIHandler Off
</Location>

Zed, of course you can post this on your site.

Kyle Maxwell

On 9/27/05, Curt Hibbs <curt.hibbs-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> Yikes! Isn't there a better way?
>
>  I'm no apache expert, so maybe this is as good as it gets. But I'd sure
> like to find something better if anyone has any ideas... esepcially, as
> Yufan says, if we can avoid any configuration in the rails application's
> directories.
>
>  Curt
>
>
> On 9/27/05, yufan shi <yufanshi <at> gmail.com> wrote:
> >
> > Hi Kyle, now I understand your solution very well. It's good enough to
> > fix the url handling issue.
> > It's better if we could avoid config for this in rails application's
> directory.
> > Nice job!
> >
> >
> > 2005/9/27, Kyle Maxwell < kyle-FOSOgQihYpQjo0HpFSRKWA@public.gmane.org>:
> > > The following fixes caching, etc in Apache + SCGI.  It would be nice
> > > to not have to repeat oneself in the routes file, but I'm sure someone
> > > can come up with a solution for that.  Doubling up the routes lets the
> > > first route generate a clean url_for, and the second one handles the
> > > actual redirected url.
> > >
> > > Kyle Maxwell
> > >
> > > #in httpd.conf
> > > SCGIMount /scgi-bin/ 127.0.0.1:9999
> > >
> > > #in .htaccess, replace the dispatch.(f)cgi line with:
> > > RewriteRule ^(.*)$ /scgi-bin/$1 [QSA,L]
> > >
> > > #in routes.rb, double up *each* of your routes as so:
> > > map.connect ':controller/:action/:id'
> > > map.connect 'scgi-bin/:controller/:action/:id'
> > > _______________________________________________
> > > Rails mailing list
> > > Rails <at> lists.rubyonrails.org
> > > http://lists.rubyonrails.org/mailman/listinfo/rails
> > >
> >
> >
> > --
> > Regards.
> >
> > Yufan
> > ===========================
> > Feed-Tank.com : Easy to use online feeds aggregator and reader.
> > FT80off: Use this code to get up to $80 off for any dreamhost hosting
> plan.
> > _______________________________________________
> > Rails mailing list
> > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
>
>
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails

_______________________________________________
Rails mailing list
Rails@...
http://lists.rubyonrails.org/mailman/listinfo/rails
Zed A. Shaw | 27 Sep 14:40
Favicon

Re: SCGI + apache solution

Thanks Kyle, do you mind if I include this in my SCGI documentation for
the next release?  I'll give you credit of course.

Zed A. Shaw
http://www.zedshaw.com/

On Tue, 27 Sep 2005 03:16:43 -0700
Kyle Maxwell <kyle@...> wrote:

> The following fixes caching, etc in Apache + SCGI.  It would be nice
> to not have to repeat oneself in the routes file, but I'm sure someone
> can come up with a solution for that.  Doubling up the routes lets the
> first route generate a clean url_for, and the second one handles the
> actual redirected url.
> 
> Kyle Maxwell
> 
> #in httpd.conf
> SCGIMount /scgi-bin/ 127.0.0.1:9999
> 
> #in .htaccess, replace the dispatch.(f)cgi line with:
> RewriteRule ^(.*)$ /scgi-bin/$1 [QSA,L]
> 
> #in routes.rb, double up *each* of your routes as so:
> map.connect ':controller/:action/:id'
> map.connect 'scgi-bin/:controller/:action/:id'
> _______________________________________________
> Rails mailing list
> Rails@...
> http://lists.rubyonrails.org/mailman/listinfo/rails

Gmane