c 語言寫的fastcgi 程式

來源:互聯網
上載者:User

最近接觸了網頁,聽說c語言能寫網頁,於是鼓搗了一下,掃掃盲 ...

首先安裝 fastcgi 開發包 ...

#wget http://www.fastcgi.com/dist/fcgi-current.tar.gz

#tar -zxvf fcgi-current.tar.gz

#cd fcgi-2.4.0

#./configure --prefix=/usr/local/fastcgi/

#make && make install

寫一個簡單的fcgi 程式

#vim hello.c 

內容如下:

#include </usr/local/fastcgi/include/fcgi_stdio.h>int main(void){    while( FCGI_Accept() >= 0){        printf( "Content-Type: text/html\r\n" );        printf("\r\n");        printf( "Hello world in C\n" );    }}

#gcc -o hello.fcgi hello.c -L /usr/local/fastcgi/lib/ -lfcgi

nginx.conf的配置要修改

server {listen 80;location ~ \.fcgi$ {            root           /srv/www;            fastcgi_pass   127.0.0.1:9002;            include        fastcgi_params;}}

重啟nginx ,然後用fastcgi 啟動程式,同時監聽 9002 連接埠

# /usr/local/fastcgi/bin/cgi-fcgi -start -connect 127.0.0.1:9002 /srv/html/cgi/hello.fcgi

應該可以訪問了 ..

http://qzier.com/cgi/hello.fcgi

還比較弱,建立一個QQ 群裡,希望能聚集相關一起學習交流

linux && c,php,postgresql,nginx,營運,安全

QQ: 213572677

Reference :

http://www.kutukupret.com/2010/08/20/nginx-fastcgi-hello-world-in-c/

進一步最佳化

https://writer.zoho.com/public/6b6a49b6dcbb8205336873dd09e1b3517a451cd1e1176acb55cc7a120224dc4a6db04614eed231e5

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.