In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the relevant knowledge of "how to use Nginx as a Perl program server and its Perl module under Linux". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Perl + fastcgi + nginx building
Nginx + fastcgi is the most popular environment under php, so will perl also have fastcgi? of course, today, let's build the fastcgi of perl under nginx. Performance is not inferior to php, but now the popularity of web program php perl is incomparable, no matter how good the performance is in vain, but some small functions can be solved by using perl's fastcgi. Get to the point.
1. Prepare the software environment:
Nginx
Perl: the system comes with
Fastcgi
1.2 perl installation
Generally speaking, linux has its own perl, so you don't need to install it. If you don't have it, execute:
# yum install perl
1.3 perl-fastcgi installation
# cd / usr/local/src# wget http://www.cpan.org/modules/by-module/fcgi/fcgi-0.74.tar.gz# tar-xzvf fcgi-0.74.tar.gz# cd fcgi-0.74# perl makefile.pl # make# make install
2. Nginx virtual host configuration
Server {listen 80; server_name test.jb51.net; # access_log / data/logs/nginx/test.jb51.net.access.log main; index index.html index.php index.html; root / data/site/test.jb51.net; location / {} location ~\. Pl$ {include fastcgi_params; fastcgi_pass 127.0.0.1 virtual 8999; # fastcgi_pass unix:/var/run/jb51.net.perl.sock; fastcgi_index index.pl }}
If you want to change tcp/ip mode to socket mode, you can modify fastcgi-wrapper.pl.
$socket = fcgi::opensocket ("127.0.0.1 VR 8999", 10); # use ip sockets
Change to
$socket = fcgi::opensocket ("/ var/run/jb51.net.perl.sock", 10); # use ip sockets
3. Configuration script
3.1 fastcgi snooping script
File path: / usr/bin/fastcgi-wrapper.pl
#! / usr/bin/perl use fcgi;use socket;use posix qw (setsid); require 'syscall.ph'; & daemonize; # this keeps the program alive or something after exec'ing perl scriptsend () {} begin () {} * core::global::exit = sub {die "fakeexit\ nrc=" .shift (). "\ n";}; eval Q {exit}; if ($@) {exit unless $@ = ~ / ^ fakeexit/;}; & main Sub daemonize () {chdir'/'or die "can't chdir to /: $!"; defined (my $pid = fork) or die "can't fork: $!"; exit if $pid; setsid or die "can't start a new session: $!"; umask 0;} sub main {$socket = fcgi::opensocket ("127.0.0.1 pid; setsid or die 8999", 10) # use ip sockets $request = fcgi::request (\ * stdin,\ * stdout,\ * stderr,\% req_params, $socket); if ($request) {request_loop ()}; fcgi::closesocket ($socket);} sub request_loop {while ($request- > accept () > = 0) {# processing any stdin input from webserver (for cgi-post actions) $stdin_passthrough ='; $req_len = 0 + $req_params {'content_length'} If (($req_params {'request_method'} eq' post') & & ($req_len! = 0)) {my $bytes_read = 0; while ($bytes_read
< $req_len) { my $data = ''; my $bytes = read(stdin, $data, ($req_len - $bytes_read)); last if ($bytes == 0 || !defined($bytes)); $stdin_passthrough .= $data; $bytes_read += $bytes; } } #running the cgi app if ( (-x $req_params{script_filename}) && #can i execute this? (-s $req_params{script_filename}) && #is this file empty? (-r $req_params{script_filename}) #can i read this file? ){ pipe(child_rd, parent_wr); my $pid = open(kid_to_read, "-|"); unless(defined($pid)) { print("content-type: text/plain\r\n\r\n"); print "error: cgi app returned no output - "; print "executing $req_params{script_filename} failed !\n"; next; } if ($pid >0) {close (child_rd); print parent_wr $stdin_passthrough; close (parent_wr); while (my $s =) {print $s;} close kid_to_read; waitpid ($pid, 0);} else {foreach $key (keys% req_params) {$env {$key} = $req_params {$key} } # cd to the script's local directory if ($req_params {script_filename} = ~ / ^ (. *)\ / [^\ /] + $/) {chdir $1;} close (parent_wr); close (stdin); # fcntl (child_rd, f_dupfd, 0); syscall (& sys_dup2, fileno (child_rd), 0); # open (stdin, "
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.