跳至內容
阿里BaBa電腦筆記
使用者工具
登入
網站工具
工具
顯示頁面
舊版
反向連結
最近更新
多媒體管理器
網站地圖
登入
最近更新
多媒體管理器
網站地圖
足跡:
linux:web:nginx_cgi
本頁是唯讀的,您可以看到原始碼,但不能更動它。您如果覺得它不應被鎖上,請詢問管理員。
======利用spawn-fcgi管理服務執行cgi程式====== spawn-fcgi是管理CGI程序的程式,它本來是[[wp>Lighttpd]](Web Server)其中一部分,現在它獨立出來可以供其他Web Server使用。 若要知道其他更多cgi差異可以看這篇[[http://cecilyen.blogspot.com/2011/11/cgifastcgiphp-cgiphp-fpmspawn-fcgi.html|什麼是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?]] =====需要套件===== 本實作是搭配Nginx Web服務(Nginx是編譯安裝)。 * fcgi * fcgi-devel * fcgiwrap * spawn-fcgi =====安裝===== * 安裝fcgi 、 fcgi-devel及spawn-fcgi<code 1>#yum install fcgi fcgi-devel spawn-fcgi</code> * 安裝fcgiwrap<code 1>#cd /usr/local/src/ #git clone git://github.com/gnosek/fcgiwrap.git #cd fcgiwrap #autoreconf -i #./configure #make && make install </code> =====spawn-fcgi設定檔配置===== <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> =====Nginx 設定檔配置===== <code 1>#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; } ~略~ } </code><code 1> #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"; </code><code 1>#chown -R nginx:nginx /usr/local/nginx/html/cgi-bin/ #chmod -R 755 /usr/local/nginx/html/cgi-bin/ </code> =====啟動或重啟 Nginx及Spawn-fcgi 並測試cgi網頁===== <code 1>#/usr/local/nginx/sbin/nginx -t -->測試設定檔語法OK #/usr/local/nginx/sbin/nginx -s reload </code> <code 1>#/etc/init.d/spawn-fcgi start</code> <code1>#links http://your IP/cgi-bin/</code> ======在cgi上使用其他程式====== 以上步驟都焦點在Perl在CGI上,現在換一個php互動網頁程式來玩玩看。 安裝及配置與以上的步驟都大致相同。 =====安裝套件===== 與以上套件一樣。只另外加裝php相關套件 * php-common * php-cli * php =====spawn-fcgi設定檔配置===== <code>#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" </code> =====Nginx 設定檔配置===== <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><code>#cd /usr/local/nginx/html/ #vim index.php</code> <code php 1> <?php phpinfo(); ?> </code> <code>#chown nginx:nginx index.php && chmod 755 index.php</code> 之後,再仿照前一節步驟啟動或重啟 Nginx及Spawn-fcgi 並測試php網頁即可。 ======參考資料====== - [[http://www.howtoforge.com/serving-cgi-scripts-with-nginx-on-centos-6.0-p2|Serving CGI Scripts With Nginx On CentOS 6.0]] - [[http://nginx.localdomain.pl/wiki/FcgiWrap|Simple CGI support for Nginx (fcgiwrap)]]
linux/web/nginx_cgi.txt
· 上一次變更: 2013/07/06 01:28 (外部編輯)
頁面工具
顯示頁面
舊版
反向連結
回到頁頂