c 语言写的fastcgi 程序

6 篇文章 0 订阅
4 篇文章 0 订阅

最近接触了网页,听说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


  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值