nginx 结合 perl
Configure Nginx to execute Perl script. |
安装一些辅助软件包!
# yum –enablerepo=epel -y install spawn-fcgi fcgi-devel
# yum -y groupinstall "Development Tools"
安装fcgiwrap
# wget http://github.com/gnosek/fcgiwrap/tarball/master -O fcgiwrap.tar.gz
# tar zxvf fcgiwrap.tar.gz
# cd gnosek-fcgiwrap-*
gnosek-fcgiwrap-4b2151e]# autoreconf -i
gnosek-fcgiwrap-4b2151e]# ./configure
gnosek-fcgiwrap-4b2151e]# make
gnosek-fcgiwrap-4b2151e]# make install
install -d -m 755 /usr/local/sbin
install -m 755 fcgiwrap /usr/local/sbin
install -d -m 755 /usr/local/man/man8
install -m 644 fcgiwrap.8 /usr/local/man/man8
配置nginx
# vim /etc/sysconfig/spawn-fcgi
# 在最后添加
OPTIONS="-u nginx -g nginx -a 127.0.0.1 -p 9001 -P /var/run/spawn-fcgi.pid — /usr/local/sbin/fcgiwrap"
# vim /etc/nginx/conf.d/default.conf
# 在server部分添加
location ~ \.pl|cgi$ { fastcgi_pass 127.0.0.1:9001; fastcgi_index index.cgi; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include /etc/nginx/fastcgi_params; } 这个看起来是不是和php的有点像呢??
# /etc/rc.d/init.d/nginx restart
Stopping nginx: [ OK ]
Starting nginx: [ OK ]
# /etc/rc.d/init.d/spawn-fcgi start
Starting spawn-fcgi: [ OK ]
# chkconfig spawn-fcgi on
创建一个cgi的脚本
# vim /usr/share/nginx/html/index.cgi
#!/usr/bin/perl print "Content-type: text/html\n\n"; print "<html>\n<body>\n"; print "<div style=\"width: 100%; font-size: 40px; font-weight: bold; text-align: center;\">\n"; print "CGI Test Page"; print "\n
\n"; print "</body>\n</html>\n";
# chmod 705 /usr/share/nginx/html/index.cgi 、