安装依赖

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. 在Linux系统里安装Virtual Box的详细步骤

    今天我试图在Linux 服务器上安装Kyma时,遇到如下错误消息: E1009 23:51:37.685891 358 start.go:174] Error starting host: Error ...

  2. 【UML】类图Class diagram(转)

    http://blog.csdn.net/sds15732622190/article/details/48860711 前言 说到UML,相信大家就能立刻反应出其中的类图,为什么这么说呢,类图和用例 ...

  3. Core Data stack

    https://developer.apple.com/library/content/documentation/DataManagement/Devpedia-CoreData/coreDataS ...

  4. centos7 python3 Saltstack配置

    Python安装完毕后,提示找不到ssl模块 pip is configured with locations that require TLS/SSL, however the ssl module ...

  5. Mysql command line

    show databasename; use databasename; show tables; desc tablename;

  6. java基础—equals方法

    一.equals方法介绍 1.1.通过下面的例子掌握equals的用法 1 package cn.galc.test; 2 3 public class TestEquals { 4 public s ...

  7. HTML5<article>元素

    HTML5<article>元素用来定义页面文档的独立内容. 实例: <article class="pageArticle"> <h2>art ...

  8. mysql5.7.24 解压版安装步骤以及遇到的问题

    1.下载 https://dev.mysql.com/downloads/mysql/ 2.解压到固定位置,如D:\MySQL\mysql-5.7.24 3.添加my.ini文件 跟bin同级 [my ...

  9. Unity3d 判断物体是否在可见范围内

    unity中自带两个回调函数: void OnBecameVisible()//当物体可见时,回调一次. void OnBecameInvisible()//当物体不可见时,回调一次. 在untiy编 ...

  10. 【思维题 集合hash 树上差分】11.5撸树

    要注重问题的转化和一些结论的推断 题目描述 要致富,先撸树. 一棵树的形状可以简化为一张 $N$ 个点 $M$ 条边的图,由于装备条件限制,你只有撸两次,也就是删去两条边,当这张图不联通时,就意味着树 ...