linux nginx 配置 fcgi

來源:互聯網
上載者:User
 FastCGI開發學習

先安裝nginx

1. 下載fastcgi 開發包,編譯安裝

       tar zvzf fcgi -current.tar.gz
       cd fcgi -current
       ./configure

        make

       make install 

2. 下載spawn-fcgi ,編譯安裝

       tar zxvf spawn-fcgi -1.6.0.tar.gz
       cd spawn-f
 cgi -1.6.0

       ./conifgure

       make
       make install
 

3. 編寫測試的c fast cgi 代碼,存為 hello.c


      #include <fcgi_stdio.h>
int main( int argc, char *argv[] )
{
while( FCGI_Accept() >= 0 ) {
printf( "Content-Type: text/plain\n\n" );

printf( "Hello FastCGI\n" );
}
return 0;
}



編譯c源檔案,運行時有可能會報找不到lib包,這裡我複製了一份,也可以做一個軟連結。我這裡用的是64位的機器,所以複製到了:/usr/lib64,32位的用:/usr/lib。 

gcc -o hello hello.c -lfcgi 

4. 修改nginx.conf設定檔,重新啟動nginx

 

       server {
listen 80;
server_name _;
location / {
root /home/user/www;
index index.html;
fast cgi _pass 127.0.0.1:9000;
}
}

5. 啟動hello

  

 spawn-fcgi -a127.0.0.1 -p9000 -n ./hello

6. 訪問nginx伺服器 ,瀏覽器 就會輸出:Hello FastCGI

一個nginx c 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.