安装依赖

sudo apt-get install libapache2-mod-fastcgi
a2enmod fastcgi
sudo apt-get install libfcgi-dev libfcgi0ldbl
 

编写FCGI代码

代码fcgi-hello.c

#include "fcgi_stdio.h" /* fcgi library; put it first*/
#include <stdlib.h> int count; void initialize(void)
{
count=0;
} void main(void)
{
/* Initialization. */
initialize(); /* Response loop. */
while (FCGI_Accept() >= 0) {
char *host = getenv("SERVER_HOSTNAME");
printf("Content-type: text/html\r\n"
"\r\n"
"<title>FastCGI Hello! (C, fcgi_stdio library)</title>"
"<h1>FastCGI Hello! (C, fcgi_stdio library)</h1>"
"Request number %d running on host <i>%s</i>\n",
++count, (host == NULL)?"unknow":host);
}
}

编译

gcc fcgi-hello.c -o fcgi-hello.fcgi -lfcgi
 

配置Apache

编辑/etc/apache2/mods-available/fastcig.conf, 在AddHandler处添加.fcgi

<IfModule mod_fastcgi.c>
AddHandler fastcgi-script .fcgi
FastCgiIpcDir /var/lib/apache2/fastcgi
</IfModule>

编辑/etc/apache2/sites-available/fcgi-demo.conf

<VirtualHost *:8081>
ServerName localhost
ServerAdmin you@local.com
DocumentRoot /var/www
ErrorLog /var/log/apache2/error.log
CustomLog /var/log/apache2/access.log combined
ServerSignature Off <IfModule mod_fastcgi.c>
<Directory /var/www>
Options +ExecCGI
AllowOverride All
SetHandler fastcgi-script
Order allow,deny
Allow from all
AuthBasicAuthoritative Off
</Directory>
</IfModule>
</VirtualHost>

编辑/etc/apache2/ports.conf,添加8081端口的监听

Listen 80
Listen 8081

启用fcgi-demo站点

a2ensite fcgi-demo.conf

重载apache

sudo service apache2 reload

确保防火墙的8081端口是打开的,然后就可以通过浏览器或curl访问这个fastcgi程序了。

Apache2 FastCGI C Demo的更多相关文章

  1. apache添加fastcgi支持

    A,安装apache服务器和fastcgi模块支持(ubuntu测试) sudo apt-get install apache2 sudo apt-get install libapache2-mod ...

  2. ubuntu12.04下 安装虚拟主机

    Ubuntu Linux 方法一 一.修改/etc/apache2/sites-available/ 1. 打开目录 /etc/apache2/sites-available/, 发现 default ...

  3. Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布

       FastCGI编程包括四部分:初始化编码.接收请求循环.响应内容.响应结束循环. FCGX_Request request; FCGX_Init(); ); FCGX_InitRequest(& ...

  4. 【入门篇】Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布

    http://blog.csdn.net/allenlinrui/article/details/19419721 1.介绍     Nginx - 高性能web server,这个不用多说了,大家都 ...

  5. ubuntu上安装apache2+mysql+php5-fpm(PHP5 - FastCGI Process Manager)

    1: 安装mysql apt-get install mysql-server mysql-client 安装过程中会被问到设置mysql root的密码     New password for t ...

  6. Windows里配置Apache2.2+PHP5.3+mod_fcgid运行高效的FastCGI模式

    日发现win平台的Apache也可以跑FastCGI模式了,就折腾了一会.FastCGI模式是经实践证明了比传统的模块模式运行效率高很多.记录如下: 一.mod_fcgid配置说明 1.首先下载mod ...

  7. Nginx + FastCGI 程序(C/C++)搭建高性能web service的demo

    http://blog.csdn.net/chdhust/article/details/42645313 Nginx + FastCGI 程序(C/C++)搭建高性能web service的Demo ...

  8. Apache2 CGI demo

    1. 修改 httpd.conf  配置 <IfModule alias_module> ScriptAlias /cgi-bin/ "/usr/local/apache2/cg ...

  9. CGI与FastCGI nginx+PHP-FPM

    本文转载自CGI与FastCGI 1.当我们在谈到cgi的时候,我们在讨论什么 最早的Web服务器简单地响应浏览器发来的HTTP请求,并将存储在服务器上的HTML文件返回给浏览器,也就是静态html. ...

随机推荐

  1. 洛谷 P1855 榨取kkksc03

    题目描述 洛谷2的团队功能是其他任何oj和工具难以达到的.借助洛谷强大的服务器资源,任何学校都可以在洛谷上零成本的搭建oj并高效率的完成训练计划. 为什么说是搭建oj呢?为什么高效呢? 因为,你可以上 ...

  2. 如何处理错误消息Please install the Linux kernel header files

    Please install the Linux kernel "header" files matching the current kernel 当我启动minilkube时遇 ...

  3. 【UML】协作图Collaboration diagram(交互图)(转)

    http://blog.csdn.net/sds15732622190/article/details/49402269 前言         学完UML时序图,就要看一下UML协作图,因为两张图是相 ...

  4. Android(java)学习笔记122:BroadcastReceiver之 有序广播和无序广播(BroadcastReceiver优先级)

    之前我们在Android(java)学习笔记178中自定义的广播是无序广播,下面我们要了解一下有序广播: 1. 我们首先了解一下有序广播和无序广播区别和联系? (1)有序广播> 接受者有优先级, ...

  5. WINDOWS-API:关于线程CreateThread,_beginthead(_beginthreadex),AfxBeginThread

    [转]windows多线程编程CreateThread,_beginthead(_beginthreadex)和AfxBeginThread的区别 在Windows的多线程编程中,创建线程的函数主要有 ...

  6. OO作业第一单元总结

    一.第一单元作业回顾 ​ 系列一作业分为三周进行,都是表达式求导,难度渐进. ​ 第一次实现的是简单幂函数的求导,第二次加入了sin和cos两种三角函数,第三次实现了三角函数内的嵌套以及引入了表达式因 ...

  7. mongo 副本集+分片 配置

    服务器规划如下: 副本集名称|服务器IP 192.168.56.111 192.168.56.112 192.168.56.113 shard1 3201 3201 3201 shard2 3202 ...

  8. JS - encodeURI与encodeURIComponent的区别

    encodeURI(String)主要用于整个URI(例如,http://www.jxbh.cn/illegal value.htm),而encodeURIComponent(String)主要用于对 ...

  9. python入门:UTF-8转换成GBK编码

    #!/usr/bin/env python # -*- coding:utf-8 -*- #UTF-8转换成GBK编码 #temp(临时雇员,译音:泰坡) #decode(编码,译音:迪口德) #en ...

  10. linux中怎样关闭ICMP回应功能

    引用自:http://blog.csdn.net/qq844352155/article/details/49700121 linux中怎样关闭ICMP回应功能   输入:   echo 1 > ...