spawn-fcgi是管理CGI程序的程式,它本來是Lighttpd(Web Server)其中一部分,現在它獨立出來可以供其他Web Server使用。 若要知道其他更多cgi差異可以看這篇什麼是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?
本實作是搭配Nginx Web服務(Nginx是編譯安裝)。
#yum install fcgi fcgi-devel spawn-fcgi
#cd /usr/local/src/ #git clone git://github.com/gnosek/fcgiwrap.git #cd fcgiwrap #autoreconf -i #./configure #make && make install
<code1>#vim /etc/sysconfig/spawn-fcgi
FCGI_SOCKET=/var/run/fcgiwrap.socket FCGI_PROGRAM=/usr/local/sbin/fcgiwrap FCGI_USER=nginx FCGI_GROUP=nginx FCGI_EXTRA_OPTIONS=“-M 0700” OPTIONS=“-u $FCGI_USER -g $FCGI_GROUP -s $FCGI_SOCKET -S $FCGI_EXTRA_OPTIONS -F 1 -P /var/run/spawn-fcgi2.pid – $FCGI_PROGRAM” </code>
#vim /usr/local/nginx/conf/nginx.conf server { ~略~ location /cgi-bin/ { gzip off; root /usr/local/nginx/html; fastcgi_pass unix:/var/run/fcgiwrap.socket; include fastcgi_params; fastcgi_index index.cgi; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } ~略~ }
#mkdir -p /usr/local/nginx/html/cgi-bin/ #cd /usr/local/nginx/html/cgi-bin/ #vim index.cgi ~內容~ #!/usr/bin/perl -w # Tell perl to send a html header. # So your browser gets the output # rather then <stdout>(command line # on the server.) print "Content-type: text/html\n\n"; # print your basic html tags. # and the content of them. print "<html><head><title>Hello World!! </title></head>\n"; print "<body><h1>Hello world</h1></body></html>\n";
#chown -R nginx:nginx /usr/local/nginx/html/cgi-bin/ #chmod -R 755 /usr/local/nginx/html/cgi-bin/
#/usr/local/nginx/sbin/nginx -t -->測試設定檔語法OK #/usr/local/nginx/sbin/nginx -s reload
#/etc/init.d/spawn-fcgi start
<code1>#links http://your IP/cgi-bin/</code>
以上步驟都焦點在Perl在CGI上,現在換一個php互動網頁程式來玩玩看。 安裝及配置與以上的步驟都大致相同。
與以上套件一樣。只另外加裝php相關套件
#vim /etc/sysconfig/spawn-fcgi SOCKET=/var/run/php-cgi.socket OPTIONS="-u nginx -g nginx -s $SOCKET -S -M 0600 -C 32 -F 1 -P /var/run/spawn-fcgi.pid -- /usr/bin/php-cgi"
<code1> #vim /usr/local/nginx/conf/nginx.conf server {
~略~ location ~ \.php$ { root /usr/local/nginx/html; fastcgi_pass unix:/var/run/php-cgi.socket; include fastcgi_params; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; } ~略~
} </code>
#cd /usr/local/nginx/html/ #vim index.php
#chown nginx:nginx index.php && chmod 755 index.php
之後,再仿照前一節步驟啟動或重啟 Nginx及Spawn-fcgi 並測試php網頁即可。