简体   繁体   中英

deploying cgi to psgi converted application in apache

#!C:/perl/bin/perl.exe
use CGI;

my $q = CGI->new;
print $q->header('text/plain'),
    "Hello ", $q->param('name');

#CONVERTED PSGI PAGE

#!C:/perl/bin/perl.exe
use CGI::PSGI;

my $app = sub {
    my $env = shift;
    my $q = CGI::PSGI->new($env);


    return [ 
        $q->psgi_header('text/plain'),
        [ "Hello ", $q->param('name') ],
    ];
};

I run this cgi.pl in apache server as http://localhost/cgi-bin/cgi.pl

but I cant able to run the converted psgi.pl in apache server its displaying please help Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator at admin@example.com to inform them of the time this error occurred, and the actions you performed just before this error. More information about this error may be available in the server error log.

CGI and PSGI are two different specifications of how a web server and an external program communicate.

Under CGI, the web server expects to receive text output from the program, consisting of the HTTP Response headers, a blank line, and the HTML rendered by the program.

The CGI module implements this logic for the apache server, and if the output from the program does not comply, apache reports the 500 error.

Under PSGI, the web server expects the program to return a three element list consisting of the HTTP response code, the HTTP Response headers, and the HTML rendered by the program.

So you can see that a program conforming to the PSGI spec would confuse the mod_cgi.

So you need to install an apache module that implements PSGI, or employ a Perl module (the CGI::PSGI docs suggest CGI::Emulate::PSGI ) that will accept your PSGI list and convert to CGI for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM