Apache2 FastCGI C Demo
安装依赖
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的更多相关文章
- apache添加fastcgi支持
A,安装apache服务器和fastcgi模块支持(ubuntu测试) sudo apt-get install apache2 sudo apt-get install libapache2-mod ...
- ubuntu12.04下 安装虚拟主机
Ubuntu Linux 方法一 一.修改/etc/apache2/sites-available/ 1. 打开目录 /etc/apache2/sites-available/, 发现 default ...
- Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布
FastCGI编程包括四部分:初始化编码.接收请求循环.响应内容.响应结束循环. FCGX_Request request; FCGX_Init(); ); FCGX_InitRequest(& ...
- 【入门篇】Nginx + FastCGI 程序(C/C++) 搭建高性能web service的Demo及部署发布
http://blog.csdn.net/allenlinrui/article/details/19419721 1.介绍 Nginx - 高性能web server,这个不用多说了,大家都 ...
- ubuntu上安装apache2+mysql+php5-fpm(PHP5 - FastCGI Process Manager)
1: 安装mysql apt-get install mysql-server mysql-client 安装过程中会被问到设置mysql root的密码 New password for t ...
- Windows里配置Apache2.2+PHP5.3+mod_fcgid运行高效的FastCGI模式
日发现win平台的Apache也可以跑FastCGI模式了,就折腾了一会.FastCGI模式是经实践证明了比传统的模块模式运行效率高很多.记录如下: 一.mod_fcgid配置说明 1.首先下载mod ...
- Nginx + FastCGI 程序(C/C++)搭建高性能web service的demo
http://blog.csdn.net/chdhust/article/details/42645313 Nginx + FastCGI 程序(C/C++)搭建高性能web service的Demo ...
- Apache2 CGI demo
1. 修改 httpd.conf 配置 <IfModule alias_module> ScriptAlias /cgi-bin/ "/usr/local/apache2/cg ...
- CGI与FastCGI nginx+PHP-FPM
本文转载自CGI与FastCGI 1.当我们在谈到cgi的时候,我们在讨论什么 最早的Web服务器简单地响应浏览器发来的HTTP请求,并将存储在服务器上的HTML文件返回给浏览器,也就是静态html. ...
随机推荐
- MySql5.7主从配置
记录 环境:ubuntu16.04,mysql5.7 主机:192.168.1.240,192.168.1.241:241为Salve 1.安装mysql sudo apt-get install m ...
- xcdatamodel的实质
修改后缀名为zip或者其它,可以查看到xcdatamodel是一个描述文件 <?xml version="1.0" encoding="UTF-8" st ...
- Java 集合框架_下
Map接口 特点: [1]Map接口称为键值对集合或者映射集合,其中的元素(entry)是以键值对(key-value)的形式存在. [2]Map 容器接口中提供了增.删.改.查的方式对集合进行操作. ...
- Dungeon Master的两种方法
Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...
- 在DataGridView控件中验证数据输入
实现效果: 知识运用: DataGridView控件的公共事件CellValidating //将System.Windows.Forms.DataGridViewCellValidatingEven ...
- 剑指offer18 树的子结构
另一种写法 class Solution { public: bool HasSubtree(TreeNode* pRoot1, TreeNode* pRoot2) { bool result = f ...
- Bootstrap历练实例:向列表组添加链接
向列表组添加链接 通过使用锚标签代替列表项,我们可以向列表组添加链接.我们需要使用 <div> 代替 <ul> 元素.下面的实例演示了这点: <!DOCTYPE html ...
- 使用jsp读取某个目录下的所有文件名,并保存在json文件中
<%@page import="java.io.File"%> <%@page import="java.io.FileWriter"%> ...
- 有重复元素的排列(DFS)
题目描述: 设R={ r1, r2 , …, rn}是要进行排列的n个元素.其中元素r1, r2 , …, rn均为小写字母并且可能相同.试设计一个算法,列出R的所有不同排列. 给定n 以及待排列的n ...
- sphinx中文入门指南 (转自sphinx中文站)
Sphinx中文入门指南 wuhuiming<blvming在gmail.com>,转载请注明来源和作者 最后修改:2010年1月23日 1.简介 1.1.Sphinx是什么 1.2.Sp ...