4

I am trying to get a C::A app work in nginx fastcgi environment (debian 6.0) and using spawn-fcgi.

C::A route is configured using $self->mode_param( path_info=> 1, param => 'rm' );

the problem is that whatever C::A app urls (example.com/cities, example.com/profile/99 etc ) I am requesting, it always displays the homepage which is what the example.com/index.pl does.

my nginx setup is

server {
    listen   80;
    server_name example.com;
    root /var/www/example.com/htdocs;
    index  index.pl index.html;

    location / {
        try_files $uri $uri/ /index.pl;
    }

    location ~ .*\.pl$ {
            include fastcgi_params;   # this is the stock fastcgi_params file supplied in debian 6.0
            fastcgi_index index.pl;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PERL5LIB "/var/www/example.com/lib";
            fastcgi_param CGIAPP_CONFIG_FILE "/var/www/example.com/conf/my.conf";
            fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }

}

I have successfully setup few php apps in similar fashion.

in this case, however, I suspect that I am not passing essential fastcgi_param down to C::A which is required by it.

what's your thoughts?

perlwle
  • 353
  • 2
  • 5
  • 17

2 Answers2

2

I maintain CGI::Application and also use Nginx. I have not done the same thing, but I would try this:

fastcgi_split_path_info ^(/index.pl)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;

This is supposed to capture and forward the PATH_INFO that you need.

References:

Mark Stosberg
  • 12,961
  • 6
  • 44
  • 49
  • thanks for the reply. but i am getting 500 internal error and bunch of recursively redirect like "/index.pl/index.pl/cities" with debug turned on for nginx error log. – perlwle Aug 02 '12 at 16:10
  • Thanks for trying my original idea. I've now revised the question with a completely different suggestion. – Mark Stosberg Aug 02 '12 at 17:47
  • I think that is on the right track. however, for some reason the path_info part seems not being passed along from nginx to my app. I have manually set the path_info to something else but still not seeing it show up in C::A app. – perlwle Aug 03 '12 at 05:50
  • for the time being, I am setting path_info manually with request_uri as a workaround... – perlwle Aug 03 '12 at 06:58
  • I think the problem was that the split_path_info regex may have been wrong, since "/index.pl" is not in the request URI, then it would be: `fastcgi_split_path_info ^()(.*)$;` ... However, I think that's equivalent to your idea of passing of $request_uri as PATH_INFO. So, you have it working now? – Mark Stosberg Aug 03 '12 at 13:03
  • yes. I have it working by doing something like `$self->query->path_info($ENV{request_uri})` in my C::A app. – perlwle Aug 04 '12 at 01:33
1

I ended up solving the problem with a workaround in my C::A app. And I am documenting it here.

So I didn't managed to have nginx pass along the PATH_INFO down to my C::A app. To work around this, I set the PATH_INFO with the value of REQUEST_URI in my C::A app so it picks up the correct runmode.

Also, nginx isn't passing QUERY_STRING either so I had to append $query_string to the catch all route in order to pass along QUERY_STRING down as well.

my nginx config ends up like this:

server {
    listen   80;
    server_name example.com;
    root /var/www/example.com/htdocs;
    index  index.pl index.html;

    location / {
        try_files $uri $uri/ /index.pl?$query_string;
    }

    location ~ .*\.pl$ {
            include fastcgi_params;   # this is the stock fastcgi_params file supplied in debian 6.0
            fastcgi_index index.pl;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param PERL5LIB "/var/www/example.com/lib";
            fastcgi_param CGIAPP_CONFIG_FILE "/var/www/example.com/conf/my.conf";
            fastcgi_pass unix:/var/run/fcgiwrap.socket;
    }

}
perlwle
  • 353
  • 2
  • 5
  • 17