安装依赖sudo apt-get install libapache2-mod-fastcgia2enmod fastcgisudo apt-get install libfcgi-dev libfcgi0ldbl 编写FCGI代码代码fcgi-hello.c#include fcgi_stdio.h /* fcgi library; put it first*/#...
安装依赖
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程序了。
原文:http://www.cnblogs.com/alexyang8/p/3542837.html
本文标题为:Apache2 FastCGI C Demo
- IIS搭建ftp服务器的详细教程 2022-11-15
- 教你在docker 中搭建 PHP8 + Apache 环境的过程 2022-10-06
- CentOS_mini下安装docker 之 安装docker CE 2023-09-23
- nginx中封禁ip和允许内网ip访问的实现示例 2022-09-23
- 【转载】CentOS安装Tomcat 2023-09-24
- CentOS7安装GlusterFS集群的全过程 2022-10-10
- 阿里云ECS排查CPU数据分析 2022-10-06
- 利用Docker 运行 python 简单程序 2022-10-16
- 解决:apache24 安装后闪退和配置端口映射和连接超时设置 2023-09-11
- KVM虚拟化Linux Bridge环境部署的方法步骤 2023-07-11