Ubuntu 10.04 Nginx Perl-FastCGI 配置

设置 Hostname:

hostname
hostname -f

第一个命令是现实短hostname, 第二个名字显示全机器名(FQDN).

安装必需的软件包

安装nginx 和spawn-fcgi

apt-get update
apt-get upgrade
apt-get install nginx spawn-fcgi libfcgi0ldbl

安装 fcgiwrap ( 32-bit Ubuntu)

wget http://mirrors.us.kernel.org/ubuntu//pool/universe/f/fcgiwrap/fcgiwrap_1.0.3-1_i386.deb
dpkg -i fcgiwrap_1.0.3-1_i386.deb

安装 fcgiwrap (64-bit Ubuntu)

wget http://mirrors.us.kernel.org/ubuntu//pool/universe/f/fcgiwrap/fcgiwrap_1.0.3-1_amd64.deb
dpkg -i fcgiwrap_1.0.3-1_amd64.deb

配置Virtual Hosting

新建目录

mkdir -p /srv/www/www.bitbi.biz/public_html
mkdir /srv/www/www.bitbi.biz/logs
chown -R www-data:www-data /srv/www/www.bitbi.biz

UNIX Sockets 配置

文件:/etc/nginx/sites-available/www.bitbi.biz

server {
    listen   80;
    server_name www.bitbi.biz bitbi.biz;
    access_log /srv/www/www.bitbi.biz/logs/access.log;
    error_log /srv/www/www.bitbi.biz/logs/error.log;
    root   /srv/www/www.bitbi.biz/public_html;
    location / {
        index  index.html index.htm;
    }
    location ~ \.pl$ {
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/run/fcgiwrap.socket;
        fastcgi_index index.pl;
        fastcgi_param SCRIPT_FILENAME /srv/www/www.bitbi.biz/public_html$fastcgi_script_name;
    }
}

TCP Sockets 配置:

文件:/etc/nginx/sites-available/www.bitbi.biz

server {
    listen   80;
    server_name www.bitbi.biz bitbi.biz;
    access_log /srv/www/www.bitbi.biz/logs/access.log;
    error_log /srv/www/www.bitbi.biz/logs/error.log;
    root   /srv/www/www.bitbi.biz/public_html;
    location / {
        index  index.html index.htm;
    }
    location ~ \.pl$ {
        gzip off;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass  127.0.0.1:8999;
        fastcgi_index index.pl;
        fastcgi_param SCRIPT_FILENAME /srv/www/www.bitbi.biz/public_html$fastcgi_script_name;
    }
}

如果你选择TCP sockets 替换UNIX sockets, 你要修改 fcgiwrap init 脚本.

文件:/etc/init.d/fcgiwrap

# FCGI_APP Variables
FCGI_CHILDREN="1"
FCGI_SOCKET="/var/run/$NAME.socket"
FCGI_USER="www-data"
FCGI_GROUP="www-data"

修改成以下脚本:

文件:/etc/init.d/fcgiwrap

# FCGI_APP Variables
FCGI_CHILDREN="1"
FCGI_PORT="8999"
FCGI_ADDR="127.0.0.1"
FCGI_USER="www-data"
FCGI_GROUP="www-data"

启用站点:

cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/www.bitbi.biz

启动nginx 和 fcgiwrap :

/etc/init.d/fcgiwrap start
/etc/init.d/nginx start

测试 :

新建"test.pl" 文件:

文件:/srv/www/www.bitbi.biz/public_html/test.pl

#!/usr/bin/perl

print "Content-type:text/html\n\n";
print <<EndOfHTML;
<html><head><title>Perl Environment Variables</title></head>
<body>
<h1>Perl Environment Variables</h1>
EndOfHTML
foreach $key (sort(keys %ENV)) {
    print "$key = $ENV{$key}<br>\n";
}
print "</body></html>";

修改成可执行属性:

chmod a+x /srv/www/www.bitbi.biz/public_html/test.pl 

当你访问http://www.bitbi.biz/test.pl , 你的Perl的环境变量会显示出来. 恭喜, 你配置成功!