uri_for() not working under lighttpd fastcgi

View: New views
4 Messages — Rating Filter:   Alert me  

uri_for() not working under lighttpd fastcgi

by Carl Franks :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I've got a Cat app working under lighttpd with fastcgi.

The app should be served from the address:
    http://my-domain/amazon

If I create a url with $c->uri_for('/books/search'), then instead of getting:
    http://my-domain/amazon/books/search
I get:
    http://my-domain/books/search

I've just transfered the app from an apache/fastcgi server where it
was working correctly, so it must be either the environment or my
lighttpd/fastcgi config, but I've never used lighttpd before, and am
stuck.

I'm using the following lighttpd config:

fastcgi.server = ( "/amazon" =>
  ( "Amazon" =>
    (
      "check-local" => "disable",
      "bin-path" => "/srv/www/amazon/script/amazon_fastcgi.fcgi",
      "socket" => "/tmp/amazon.socket",
      "max-procs" => 2,
    )
  )
)

Here is the 'request' key of my dumped $context:

bless( {
  'protocol' => 'HTTP/1.1',
  'headers' => bless( {
    'user-agent' => 'Mozilla/5.0 (X11; U; Linux i686; en-GB;
rv:1.8.1.5) Gecko/20070718 Fedora/2.0.0.5-1.fc7 Firefox/2.0.0.5',
    'connection' => 'keep-alive',
    'keep-alive' => '300',
    'cache-control' => 'max-age=0',
    'accept' =>
'text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5',
    'accept-language' => 'en-gb,en-us;q=0.7,en;q=0.3',
    'accept-encoding' => 'gzip,deflate',
    'host' => '69.56.173.124',
    'accept-charset' => 'ISO-8859-1,utf-8;q=0.7,*;q=0.7'
  }, 'HTTP::Headers' ),
  '_context' => $VAR1,
  'body_parameters' => {},
  'secure' => 0,
  'hostname' => undef,
  'uploads' => {},
  'user' => undef,
  '_body' => 0,
  'method' => 'GET',
  'address' => '134.36.224.37',
  'base' => bless( do{\(my $o = 'http://69.56.173.124/')}, 'URI::http' ),
  'cookies' => {},
  'match' => '',
  'path' => 'amazon',
  'uri' => bless( do{\(my $o = 'http://69.56.173.124/amazon')}, 'URI::http' ),
  'query_parameters' => {},
  'parameters' => {},
  'action' => 'default',
  'arguments' => [
    'amazon'
  ],
  'captures' => []
}, 'Catalyst::Request' )


Any pointers?
Carl

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: uri_for() not working under lighttpd fastcgi

by Carl Franks :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I discovered that if instead of hitting:
    http://my-domain/amazon
I hit:
    http://my-domain/amazon/

... then uri_for() started working as expected.

I added a rewrite rule to my lighttpd config:
    url.rewrite = ( "^/amazon$" => "/amazon/" )
and everything is now working again.

I don't know if this is the best solution though.

Cheers,
Carl

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: Re: uri_for() not working under lighttpd fastcgi

by jspath :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Carl Franks wrote:

> I discovered that if instead of hitting:
>     http://my-domain/amazon
> I hit:
>     http://my-domain/amazon/
>
> ... then uri_for() started working as expected.
>
> I added a rewrite rule to my lighttpd config:
>     url.rewrite = ( "^/amazon$" => "/amazon/" )
> and everything is now working again.
>
> I don't know if this is the best solution though.
>
> Cheers,
> Carl

I have run into this same issue... on our development lighttpd server
the Catalyst application is accessible through URLs like:

   http://domain/~user/myapp/

If you didn't include the trailing slash, Catalyst would set
$c->request->base incorrectly.

Our solution was simply to force trailing slashes (although I am having
trouble finding this configuration option), which really just works
around the core Catalyst issue.  I'll see if I can dig up more on this.

- Jim

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/

Re: Re: uri_for() not working under lighttpd fastcgi

by Kieren Diment-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

This was a major pain when I was getting WIAB out the door and into
the wild.  The solution for non-root deployment on lighttpd is to add
the following rewrite rule into the lighttpd config:

url.rewrite = ( "fastcgi\$" => "fastcgi/" )
\$HTTP["url"] =~ "/fastcgi" {

(assuming deployment on http://mydomain/fastcgi)

Essentially it's caused by not-quite-a-bug-but-almost in lighttpd
(i.e. non identical behaviour to apache) which I believe is something
to do with env variables.  Catalyst doesn't know the web server
details in front of the fast cgi process so there's not much we can do
to work around the problem, except fix the Engine::FastCGI docs, which
I'm going to do right now before I go to bed...


some nice little test harnesses for testing for these <sarcasm> fun,
rewarding and fulfilling </sarcasm> issues here:

http://websiteinabox.googlecode.com/svn/trunk/WIAB/t/optional_lighttpd-fastcgi-non-root.pl
http://websiteinabox.googlecode.com/svn/trunk/WIAB/t/optional_apache-fastcgi.pl
http://websiteinabox.googlecode.com/svn/trunk/WIAB/t/optional_lighttpd-fastcgi.pl


On 15/09/2007, Jim Spath <jspath@...> wrote:

> Carl Franks wrote:
> > I discovered that if instead of hitting:
> >     http://my-domain/amazon
> > I hit:
> >     http://my-domain/amazon/
> >
> > ... then uri_for() started working as expected.
> >
> > I added a rewrite rule to my lighttpd config:
> >     url.rewrite = ( "^/amazon$" => "/amazon/" )
> > and everything is now working again.
> >
> > I don't know if this is the best solution though.

Should have read the rest of the message.  Yes this is the best solution.

> >
> > Cheers,
> > Carl
>
> I have run into this same issue... on our development lighttpd server
> the Catalyst application is accessible through URLs like:
>
>    http://domain/~user/myapp/
>
> If you didn't include the trailing slash, Catalyst would set
> $c->request->base incorrectly.
>
> Our solution was simply to force trailing slashes (although I am having
> trouble finding this configuration option), which really just works
> around the core Catalyst issue.  I'll see if I can dig up more on this.
>
> - Jim
>
> _______________________________________________
> List: Catalyst@...
> Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@.../
> Dev site: http://dev.catalyst.perl.org/
>

_______________________________________________
List: Catalyst@...
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@.../
Dev site: http://dev.catalyst.perl.org/