[Catalyst-dev] nginx patch to Engine::FastCGI?

J. Shirley jshirley at gmail.com
Thu Oct 30 20:35:16 GMT 2008


I am working on a new nginx+fastcgi deployment, and this time the
Catalyst app is not at "/" like my previous other deployments.  It
seems that nginx doesn't quite jive with Catalyst out of the box in
this case.

I'm going to just describe the problem, as my solution is far from
elegant, and hope that more Engine-centric folks can chime in with
better ideas.

nginx doesn't distinguish the request path any different than the
subsequent path info (appended to the end of the path).  So,
$env{SCRIPT_NAME} and $env{PATH_INFO} are effectively the same value.
In the case of "/" this doesn't present any problem, but if your
application is at a different path ("/myapp" for example) then it
break.s

The good thing is nginx allows for arbitrary variables to be set in
the FastCGI config space, so you can explicitly set SCRIPT_NAME or
PATH_INFO.  This doesn't help though with PATH_INFO always contains
information for $c->req->base to be built though.

The solution I came up with is to tell nginx to define the variables as such:

fastcgi_param  SCRIPT_NAME        /ems/;
fastcgi_param  PATH_INFO          $fastcgi_script_name; # Effectively
/ems/{PATH_INFO}

And then, in Engine::FastCGI I have this small patch, to remove the duplication:
        if ( $env{SERVER_SOFTWARE} && $env{SERVER_SOFTWARE} =~ /nginx/ ) {
            $env{PATH_INFO} =~ s/^$env{SCRIPT_NAME}//g;
        }

This is the only way I could get the base URI to be constructed
properly.  I'm not that experienced with nginx, but I couldn't find
anything at all in their documentation to help with it.

Hopefully someone has some better thoughts on this...

Thanks,
-J



More information about the Catalyst-dev mailing list