c 語言寫的fastcgi 程序

最近接觸了網頁,聽說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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章