web(五)---spawn-fastcgi

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   ar   color   os   使用   

一. spawn_fastcgi的安裝、部署與配置.

    1. 下載spawn_fastcgi.    https://github.com/lighttpd/spawn-fcgi       這裡使用的是1.6.3的版本 https://github.com/lighttpd/spawn-fcgi/releases/tag/v1.6.3        2. 解壓並安裝(請記得看README).     (1) 如果沒有configure,請先執行./autogen.sh,產生configure       (2) ./configure       (3) make 注意: 如果通過上面安裝不成功, 試試直接  sudo apt-get install spawn_fastcgi     3. 編譯好以後,將可執行檔移動到nginx的sbin目錄下.       cp ./src/spawn-fcgi /usr/local/nginx/sbin/ (cp到nginx的安裝目錄下) 注意: 1. 第3步, 如果拷貝過程中提示找不到./src/spawn-fcgi,  則用which spawn-fcgi找到該二進位拷貝;        2. 第3步, 如果拷貝過程中提示找不到/usr/local/nginx/sbin/, 則手動建立目錄. 二. fastcgi庫的安裝. 1. 下載 http://www.fastcgi.com/dist/fcgi.tar.gz(從這下載的可能有問題, 最好用本文給出的.)         2.  $./configure        $make        $make install 注意: 1. 安裝過程中如果出現如下錯誤,  則在fcgio.cpp中添加標頭檔 #include <stdio.h>, 重新編譯即可.           參考http://stackoverflow.com/questions/8833718/installing-fastcgi-dev-kit        2. 如果make通過, 但是make install有錯, 嘗試用本文給的檔案, 不用步驟1連結中的.

fcgio.cpp: In destructor ‘virtual fcgi_streambuf::~fcgi_streambuf()‘:
fcgio.cpp:50:14: error: ‘EOF‘ was not declared in this scope
fcgio.cpp: In member function ‘virtual int fcgi_streambuf::overflow(int)‘:
fcgio.cpp:70:72: error: ‘EOF‘ was not declared in this scope
fcgio.cpp:75:14: error: ‘EOF‘ was not declared in this scope
fcgio.cpp: In member function ‘virtual int fcgi_streambuf::sync()‘:
fcgio.cpp:86:18: error: ‘EOF‘ was not declared in this scope
fcgio.cpp:87:41: error: ‘EOF‘ was not declared in this scope
fcgio.cpp: In member function ‘virtual int fcgi_streambuf::underflow()‘:
fcgio.cpp:113:35: error: ‘EOF‘ was not declared in this scope
make[2]: *** [fcgio.lo] Error 1
make[2]: Leaving directory `/home/lucasysfeng/workspace/web/download/nginx_spawn_fcgi_install_package/fcgi-2.4.1-SNAP-0311112127/libfcgi‘
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/home/lucasysfeng/workspace/web/download/nginx_spawn_fcgi_install_package/fcgi-2.4.1-SNAP-0311112127‘
make: *** [all] Error 2

 三. Demo程式.     1. demo.cc如下所示:
#include <fcgi_stdio.h>#include <stdlib.h>#include <unistd.h>int main() {    int count = 0;    while (FCGI_Accept() >= 0) {        printf("Content-type: text/html\r\n"                "\r\n"                ""                "FastCGI Hello!"                "Request number %d running on host%s "                "Process ID: %d\n", ++count, getenv("SERVER_NAME"), getpid());    }    return 0;}

  2. 編譯.

       g++ demo.cc -o demo  -lfcgi?  

注意:1. 如果編譯不通過, 可能是庫-lfcgi? 沒找到, 那就是<二. fastcgi庫的安裝.>有問題 2. 直接運行可執行檔,看看能否正常運行。如果出現缺少庫libfcgi.so.0,    則自己需要手動把/usr/local/lib/libfcgi.so.0庫建立一個連結到/usr/lib/目錄下:       ln -s /usr/local/libfcgi.so.0 /usr/lib/(或者把so的庫路徑添加到/etc/ld.so.conf,並執行ldconfig更新一下) 四. demo發布.  1)將CGI可執行程式移動到nginx的安裝目錄下 /usr/local/nginx/cgibin (檔案夾不存在則自己建立)          cp ***/demo  /usr/local/nginx/cgibin        2)啟動spawn-fcgi管理進程,並綁定server IP和連接埠(不要跟nginx的監聽連接埠重合)       /usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 8088 -f /usr/local/nginx/cgibin/demo
          查看一下8088連接埠是否已成功:netstat -na | grep 8088?       3)更改nginx.conf設定檔(或者是/etc/nginx/sites-available/default),讓nginx轉寄請求
        在http節點的子節點-"server節"點中下添加配置    location ~ \.cgi$ {
        fastcgi_pass 127.0.0.1:8088;
        fastcgi_index index.cgi;
        fastcgi_param SCRIPT_FILENAME fcgi$fastcgi_script_name;

        include fastcgi_params;    }     4)重啟nginx或者重新載入設定檔    sudo service nginx restart
     5)開啟瀏覽器訪問一下吧    http://localhost/demo.cgi

web(五)---spawn-fastcgi

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.