34

I'm trying to get Plack::App::CGIBin to work using Apache2 and FastCGI on FreeBSD 8.2. The eventual aim is to be able to use this setup to serve a whole bunch of legacy CGI scripts via Plack, in order to take advantage of its middleware capabilities, but I haven't been able to get even a simple example working.

I've followed the CPAN documentation on Plack::Handler::FCGI and Plack::App::CGIBin itself, but I'm not sure if I'm missing something or doing something wrong which isn't covered by those docs.

This is the Apache config I've added:

# Set up external server
FastCgiExternalServer /tmp/placktest.fcgi -socket /tmp/fcgi.socket

# URL to be handled by FastCGI
Alias /plack/ /tmp/placktest.fcgi/

Command to run external server:

plackup -s FCGI --listen /tmp/fcgi.socket /data/www/psgi/app.psgi

The server starts successfully, returning the following:

FastCGI: manager (pid <pid>): initialized
FastCGI: manager (pid <pid>): server (pid <pid>) started
FastCGI: server (pid <pid>): initialized

This is app.psgi:

#!/usr/bin/env plackup -s FCGI

use Plack::App::CGIBin;
use Plack::Builder;

my $app = Plack::App::CGIBin->new(
    root => '/data/www/plack',
)->to_app;

builder {
    mount "/plack" => $app;
};

I then have a simple CGI script at /data/www/plack/test.cgi (this file runs fine under CGI.pm).

What I'd expect is that a request to http://<domain>/plack/test.cgi/ (including the trailing slash) would return the test script, but I always get the following 404 error in the Apache error log, which I think is coming back from the FastCGI server:

FastCGI: server "/tmp/placktest.fcgi" stderr: <IP address/date>; "GET /plack/test.cgi HTTP/1.1" 404 9 "-" <User agent string>;

I've got FastCGI working on its own, using mod_fastcgi and a simple example script in a directory with SetHandler fastcgi-script applied, so at least that worked :-).

Has anyone got Plack::App::CGIBin working under a similar scenario? I'd greatly appreciate any insight!

Thanks

  • Maybe it helps if you use a TCP server instead of the socket file, e.g. in the FastCgiExternalServer directive `-host 127.0.0.1:5001` and in the plackup cmdline `-listen 127.0.0.1:5001`. – Slaven Rezic Oct 18 '13 at 13:05
  • Thanks for your reply Slaven - unfortunately I still get the same error, which suggests that the socket connection, however it's established, is OK, and it's the FCGI server which has the problem. –  Oct 21 '13 at 08:47
  • Don't know if you ever got anywhere with this, but the logged GET request is for `/plack/placktest/`, and I don't see where else you use the string placktest other than in the thing you alias /plack/ to -- which makes me think it doesn't belong in the GET request. – James Green Jan 03 '14 at 19:43
  • 2
    Can you confirm that the app runs correctly via Plack::App::CGIBin using a perl-based webserver like Starman or HTTP::Server::PSGI? – nebulous Jan 30 '14 at 14:52
  • 3
    Hi nebulous - I've tried Starman and the page works! To confirm this, I've added Plack::Middleware::CSRFBlock (my original aim) and the hidden text field which that adds is appearing correctly in a plain CGI page served using Plack::App::CGIBin. It seems that it's an Apache/FastCGI problem then. –  Feb 13 '14 at 10:41

1 Answers1

1

I'd guess you need to change

builder {
    mount "/plack" => $app;
};

to

builder {
    mount "/" => $app;
};

because your alias is removing /plack/

or just change

# URL to be handled by FastCGI
Alias /plack/ /tmp/placktest.fcgi/

to

# URL to be handled by FastCGI
Alias /plack/ /tmp/placktest.fcgi/plack/

After all it does not appear to be a Perl question, but a System Administrator one, about Apache configuration.

lnrdo
  • 396
  • 1
  • 13