FCGI Perl

I’m trying to use the script at NameBright - Coming Soon
to serve .pl in /cgi-bin/ (like awstats) as FastCGI. Attempting to run
the script gives an error. I’ve tried with Perl 5.8.8 and 5.10.1. Both
result in the same error.

Can’t locate unistd_64.ph in @INC (did you run h2ph?) (@INC contains:
/etc/perl /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux
/usr/lib64/perl5/vendor_perl/5.8.8 /usr/lib64/perl5/vendor_perl
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux
/usr/lib64/perl5/site_perl/5.8.8 /usr/lib64/perl5/site_perl
/usr/lib64/perl5/5.8.8/x86_64-linux /usr/lib64/perl5/5.8.8
/usr/local/lib/site_perl .) at
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux/asm/unistd.ph line 8.
Compilation failed in require at
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux/sys/syscall.ph line 7.
Compilation failed in require at
/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux/syscall.ph line 5.
Compilation failed in require at fastcgi-wrapper.pl line 9.

Is this error something that is simple to fix, or is there some other
method for serving Perl with nginx?

On Fri, 2009-10-02 at 16:47 -0500, Gordon Pettey wrote:

I’m trying to use the script at NameBright - Coming Soon
to serve .pl in /cgi-bin/ (like awstats) as FastCGI. Attempting to run
the script gives an error. I’ve tried with Perl 5.8.8 and 5.10.1. Both
result in the same error.

Can’t locate unistd_64.ph in @INC (did you run h2ph?) (@INC contains:

Well… did you?

Personally I just proxy to thttpd for the rare occasion I need CGI.

Cliff

On Fri, Oct 2, 2009 at 5:02 PM, Cliff W. [email protected] wrote:

On Fri, 2009-10-02 at 16:47 -0500, Gordon Pettey wrote:

Can’t locate unistd_64.ph in @INC (did you run h2ph?) (@INC contains:

Well… did you?

Personally I just proxy to thttpd for the rare occasion I need CGI.

Cliff

The file is definitely there. I’ll looking at thttpd, but I’d prefer
to just run it through FastCGI if at all possible.

May have found my problem.

/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux/unistd.ph requires
asm/unistd.ph checks arch and then requires either
unistd_32.ph OR unistd_64.ph

I placed “asm/” before unistd_64.ph and the script runs fine. Is this
a normal file layout for Perl, or is Gentoo screwing around?

Look at fcgiwrap. It might work. But yes a nice fastcgi gateway that
can be managed like php-fpm would be awesome.

Sent from my iPhone

I encountered the same issue on fedora core 9

Posted at Nginx Forum:

Plz describe the full process of configuring fcgi on nginx for using
perl

[email protected]
Content-Type: text/plain; charset=“big5”
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0

Dear all:

When I use this variable in log_format directive ,it can print the
request_body in the log file

but somewhere else it can’t!

if i use the $request_body at log_format and somewhere else( such as
“proxy_pass”) at the same time .there is no output in the log file!

http{

log_format main '$remote_addr - $remote_user [$time_local] $request ’
'“$status” $body_bytes_sent “$http_referer” ’
‘“$http_user_agent” “$http_x_forwarded_for”
“$request_body”’;

server {
listen 80;
server_name my.test.com;
root /opt/test;
include vhost/alias.conf;
include vhost/proxy.conf;
if (-d $request_filename) {
rewrite ^/(.*)([^/])$ http://$host/$1$2/
permanent;
}
set $mytest $request_body;
log_format test '$remote_addr - $remote_user
[$time_local] $request ’
'“$status” $body_bytes_sent “$http_referer” ’
‘“$http_user_agent” “$http_x_forwarded_for”
“$mytest”’;
location / {
root /opt/test;
index index.html index.htm;
}
error_log /usr/local/nginx/logs/my_error.log;
access_log /usr/local/nginx/logs/my_access.log main;
include vhost/prox.conf;
}
}
}

My Nginx Version is
nginx version: nginx/0.8.15

that wiki not clear enough… i don’t know why there is “:” mark in most
beginning of statement in the code? is it correct? i use spawn-fcgi…
maybe
you could try it too… ^^

On Sat, 2009-10-17 at 15:18 +0700, Kiswono P. wrote:

that wiki not clear enough… i don’t know why there is “:” mark in
most beginning of statement in the code? is it correct?
i use spawn-fcgi… maybe you could try it too… ^^

The code was messed up from our transition from MoinMoin to MediaWiki
some time ago. It’s fixed now. Funny how the extraneous “:”
characters could so easily be mistaken for valid Perl :wink:

In any case, that Perl hack is only for running CGI, not FCGI and I’d
recommend using thttpd (possibly proxied to by Nginx) rather than that
script if you really needed to use CGI.

Regards,
Cliff

On Sat, 2009-10-17 at 15:18 +0700, Kiswono P. wrote:

that wiki not clear enough… i don’t know why there is “:” mark in
most beginning of statement in the code? is it correct?
i use spawn-fcgi… maybe you could try it too… ^^

The code was messed up from our transition from MoinMoin to MediaWiki
some time ago. It’s fixed now. Funny how the extraneous “:”
characters could so easily be mistaken for valid Perl :wink:

In any case, that Perl hack is only for running CGI, not FCGI and I’d
recommend using thttpd (possibly proxied to by Nginx) rather than that
script if you really needed to use CGI.

Regards,
Cliff

On Sam 17.10.2009 15:18, Kiswono P. wrote:

that wiki not clear enough… i don’t know why there is “:” mark in most
beginning of statement in the code? is it correct? i use
spawn-fcgi… maybe you could try it too… ^^

Sorry but as I have understand the OP right he need the last section of
the wikipage.

Maybe this will help you to:

http://wiki.nginx.org/NginxHttpFcgiModule

As I have understand right he want to know how to setup nginx for fcgi
with a perl backend, Johnny fox Ucklenberg right?

If you,Johnny fox Ucklenberg, also need to know how to use fcgi in perl
then please take a look into:

Myabe this will help you too.

BR & hth

Aleks

What is unclear on
http://wiki.nginx.org/NginxSimpleCGI

Of course, i read wiki. Its unclear how to modify nginx.conf

I need to run wakaba(imageboard script) on my nginx which was written in
perl.

I’ve got nginx/0.7.62:

–prefix=/nginx
–sbin-path=/nginx/nginx
–conf-path=/nginx/conf/nginx.conf
–error-log-path=/nginx/log/nginx-error.log
–pid-path=/nginx/nginx.pid
–lock-path=/nginx/nginx.lock
–user=nobody >–group=nobody

–with-http_ssl_module
–with-http_realip_module
–with-http_flv_module
–with-http_gzip_static_module
–with-http_random_index_module
–with-http_secure_link_module
–with-http_stub_status_module

–with-perl_modules_path=/nginx/mod
–with-perl=/usr/bin/perl

–http-log-path=/nginx/log/nginx-access.log

–http-client-body-temp-path=/nginx/tmp/client
–http-proxy-temp-path=/nginx/tmp/proxy
–http-fastcgi-temp-path=/nginx/tmp/fastcgi

–without-mail_pop3_module
–without-mail_imap_module
–without-mail_smtp_module

–with-cpu-opt=pentium4
–with-md5-asm
–with-sha1-asm
–with-zlib-asm=pentiumpro

Also i installed fcgi, perl, perl-fcgi and procmanager packages. I
generated syscall.pm:

cd /usr/include
h2pm -r -l syscall.h

cgiwrap-fcgi.pl is located in /nginx (do i need to modify
it(path-to-socket, line 35)?)

[root@theycrawl ~]# /nginx/cgiwrap-fcgi.pl
FastCGI: manager (pid 5284): initialized
FastCGI: manager (pid 5284): server (pid 5285) started
FastCGI: server (pid 5285): initialized
FastCGI: server (pid 5286): initialized
FastCGI: manager (pid 5284): server (pid 5286) started
FastCGI: manager (pid 5284): server (pid 5287) started
FastCGI: server (pid 5287): initialized
FastCGI: server (pid 5288): initialized
FastCGI: manager (pid 5284): server (pid 5288) started
FastCGI: server (pid 5289): initialized
FastCGI: manager (pid 5284): server (pid 5289) started

What i need to add to nginx.conf?
In which order i must run nginx and other stuff?

PS also i’ve got gnosek-fcgiwrap, may be its better to use it?

On Sam 17.10.2009 17:49, Johnny fox Ucklenberg wrote:

What is unclear on
http://wiki.nginx.org/NginxSimpleCGI

Of course, i read wiki. Its unclear how to modify nginx.conf

I need to run wakaba(imageboard script) on my nginx which was written in
perl.

I’ve got nginx/0.7.62:

[snipp]

cgiwrap-fcgi.pl is located in /nginx (do i need to modify
it(path-to-socket, line 35)?)

Do you have used this one:

http://trac.aumi.ru/hanataba/browser/nginx/cgiwrap-fcgi.pl

Then you have adopted it a little bit right ;-O

[root@theycrawl ~]# /nginx/cgiwrap-fcgi.pl
FastCGI: manager (pid 5284): initialized

[snipp]

What i need to add to nginx.conf?

http://trac.aumi.ru/hanataba/browser/nginx/nginx_chan.conf

The key is:

fastcgi_pass unix:/var/run/nginx/perl_cgi-dispatch.sock;

The rest is descibed in:

http://wiki.nginx.org/NginxHttpFcgiModule

Hth

Aleks

Dear Johnny fox Ucklenberg,

On Sam 17.10.2009 00:59, Johnny fox Ucklenberg wrote:

Plz describe the full process of configuring fcgi on nginx for using
perl

What is unclear on

http://wiki.nginx.org/NginxSimpleCGI

Maybe you can help to improve the wiki?

Cheers

Aleks

On Sam 17.10.2009 20:14, Johnny Fox Ucklenberg wrote:

My old cgiwrap-fcgi.pl, more heavy(with additional dependencies)
0x000BLAh - Pastebin.com

Alternative binary wrapper, dont know how to use, i suppose it opens
new port GitHub - gnosek/fcgiwrap: Simple FastCGI wrapper for CGI scripts

Yes I would prefer to use this handy nice tool with the FastCGI launcher
:wink:

BR

Aleks

Alternative binary wrapper, dont know how to use, i suppose it opens
new port GitHub - gnosek/fcgiwrap: Simple FastCGI wrapper for CGI scripts

Project page http://nginx.localdomain.pl/wiki/FcgiWrap

Its the only one working solution(for me of course)
It uses script which creates socket(but dont set access rights for it!!)

ive get what i want, thanks to everybody!

My old cgiwrap-fcgi.pl, more heavy(with additional dependencies)

Alternative binary wrapper, dont know how to use, i suppose it opens new
port GitHub - gnosek/fcgiwrap: Simple FastCGI wrapper for CGI scripts

With new wrapper script & some modification of nginx.conf i ve got

The page you are looking for is temporarily unavailable.
Please try again later.

This message is shown the wrapper is running whether or not.

nginx error log says:

2009/10/18 01:50:42 [error] 3172#0: *1 FastCGI sent in stderr: “Undefined subroutine &main::SYS_dup2 called at /nginx/cgiwrap-fcgi.pl line 88” while reading response header from upstream, client: 127.0.0.1, server: theycrawl, request: “GET /test.pl HTTP/1.1”, upstream: “fastcgi://unix:/nginx/fcgi/perl_cgi-dispatch.sock:”, host: “theycrawl”
2009/10/18 01:50:42 [error] 3172#0: *1 upstream closed prematurely FastCGI stdout while reading response header from upstream, client: 127.0.0.1, server: theycrawl-pc.swamp.ru, request: “GET /test.pl HTTP/1.1”, upstream: “fastcgi://unix:/nginx/fcgi/perl_cgi-dispatch.sock:”, host: “theycrawl”\

On Mon, Oct 5, 2009 at 7:08 PM, dennis cao [email protected]
wrote:

When I use this variable in log_format directive ,it can print the request_body in the log file

but somewhere else it can’t!

The $request_body variable only has values when the underlying content
handler or upstream handler or anything else has actually read the
request body from the tcp connection and stored it into
r->request_body slot.

The variable itself merely reads that buffered data and will never
read from socket itself. See the ngx_http_variable_request_body
function in src/http/ngx_http_variables.c in the Nginx source tree.

It can be easily demonstrated by means of my echo module [1]:

  location /echo_body {
    echo [$request_body];
}

Accessing /echo from the client side gives

$ echo "my body" | lwp-request -m POST 

http://localhost:8080/echo_body
[]

As we can see, it’s empty, because the “echo” module does NOT read the
client request body [2]. Now let’s use something that actually reads
the body, like the standard proxy module:

location /echo_body2 {
    proxy_pass $scheme://127.0.0.1:$server_port/dummy;
    echo_after_body [$request_body];
}
location /dummy { echo_duplicate 0 ''; }

Accessing /echo_body2 gives the desired results:

$ echo "my body" | lwp-request -m POST 

http://localhost:8080/echo_body2
[my body
]

Hope this helps :slight_smile:

Cheers,
-agentzh

References
[1] echo-nginx-module wiki page:
http://wiki.nginx.org/NginxHttpEchoModule
[2] On the C level, it’s usually the ngx_http_read_client_request_body
function that does the body reading work, but can be also done by any
other code (as in the “upload” module).

On Thu, Oct 22, 2009 at 3:57 PM, agentzh [email protected] wrote:

The $request_body variable only has values when the underlying content
handler or upstream handler or anything else has actually read the
request body from the tcp connection and stored it into
r->request_body slot.

Sorry, forgot to mention that for POST data that has well exceeded
“client_body_buffer_size”, Nginx will write the data into temporary
files on the disk. In this case, the $request_body variable is also
evaluated to an empty string (“”).

To help demonstrating this, I’ve added the “read_request_body”
directive to my “echo” module (released as v0.14), which calls the
“ngx_http_read_client_request_body” function, just as the “proxy”
module and many others. The following example clearly shows the
situation described above.

In the nginx.conf:

location /echobody {
client_body_buffer_size 2;
echo_read_request_body;
echo $request_body;
}

On the client side:

$ perl -e ‘print "a"x2’ | lwp-request -m POST
http://localhost:8080/echobody
aa

$ perl -e ‘print "a"x1024’ | lwp-request -m POST
http://localhost:8080/echobody

As we can see, the second request feeds 1KB POST request body, well
above the 2 bytes “client_body_buffer_size” setting and $request_body
yields empty.

I’m guessing this is more likely in your situation but I could be wrong
:slight_smile:

Cheers,
-agentzh