##
server {
listen 127.0.0.1;
server_name test.com;
access_log /var/www/test.com/log/access_log;
error_log /var/www/test.com/log/error_log;
location ~* ^.+\.(html|htm|jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov)$ {
root /var/www/test.com/html;
}
location / {
set $scriptname "";
if ($fastcgi_script_name = "/") {
set $scriptname "main";
}
if ($fastcgi_script_name ~ ^/(.*)/$) {
set $scriptname $1;
}
gzip off; #gzip makes scripts feel slower since they have to complete before getting gzipped
fastcgi_pass 127.0.0.1:9090;
fastcgi_param SCRIPT_FILENAME $scriptname;
include /etc/nginx/fastcgi_params;
}
}
####
#!/usr/bin/perl
use strict;
use FCGI::ProcManager;
use CGI::Fast;
use POSIX qw(setsid);
my $PROCESSES = 1;
my $SOCKET = "127.0.0.1:9090";
my $cgi;
my $count = 0; # for debug !!!
#&daemonize;
#this keeps the program alive or something after exec'ing perl scripts
BEGIN() { }
END() { }
*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 {
my $proc_manager = new FCGI::ProcManager({ n_processes => $PROCESSES});
my $socket = FCGI::OpenSocket($SOCKET, 100);
my $request = FCGI::Request(\*STDIN, \*STDOUT, \*STDERR, \%ENV, $socket);
$proc_manager->pm_manage();
while($request->Accept() >= 0){
$proc_manager->pm_pre_dispatch();
$cgi = new CGI::Fast;
#$cgi = new CGI; second example !!!
&website();
$proc_manager->pm_post_dispatch();
}
FCGI::CloseSocket($socket);
}
sub website()
{
my $title;
my $description;
my $keywords;
my $script = $ENV{SCRIPT_FILENAME};
if($script eq 'main'){
$title = 'Main';
$description = '';
$keywords = '';
&action_main($title,$description,$keywords);
}
elsif($script eq 'order'){
$title = 'Order';
$description = '';
$keywords = '';
&action_order($title,$description,$keywords);
}
else{
$title = 'Page not found!';
$description = '';
$keywords = '';
&page_not_found($title,$description,$keywords);
}
}
sub header
{ $count++;
print <<"T";
Content-type: text/html\r\n\r
$_[0]
$count
WEB-SITE!!!
Main
Order Online
T
foreach (keys %ENV){ # this is for debug!!!
print "$_: $ENV{$_}
";
}
}
sub end
{
print <<'T';
T
}
sub action_main
{
&header(@_);
print <<'T';
THIS IS MAIN PAGE TEXT
T
&end();
}
sub action_order
{
&header(@_);
my $need = ' *';
my $error = ' *';
my $errorflag = 0;
my $send = 0;
$send = 1 if(defined($cgi->param('send')));
my %hash;
foreach ( qw{mail firstname mobile} ){
$hash{$_}->{title} = '';
if($_ eq 'mobile' or $_ eq 'firstname'){
$hash{$_}->{title} = $need;
if($send and !defined($cgi->param($_))){
$hash{$_}->{title} .= $error;
$errorflag = 1;
}
}
if($send){
$hash{$_}->{value} = $cgi->param($_);
}
else{
$hash{$_}->{value} = '';
}
}
print <<"T";
T
&end();
}
sub page_not_found
{
&header(@_);
print <<'T';
Page not found!!!
T
&end();
}