windows apache+cgi 运行c/c++

apache是运用比较广泛的web服务器,大多数是php应用,apache可以启动单独的c/c++进程,为web提供服务,这大大丰富的web内容,当然cgi这种方式不适用于大规模并发的场景. Ngix 据说比apache性能更高,可以考虑

1. apache安装

    windows下直接下载二进制安装文件,下一步即可; Linux下直接下载源码安装

2. 配置

   $APACHE/conf/httpd.conf

   1. 将 LoadModule cgi_module modules/mod_cgi.so 前注释取消

   2. cgi的执行权限

   <Directory "D:/Apache2.2/cgi-bin">

    AllowOverride None

    Options Indexes ExecCGI   # 添加ExecCGI,允许执行cgi程序

    Order allow,deny

    Allow from all

  </Directory>

   3. 添加文件映射

   AddHandler cgi-script .cgi .pl .py 

  

   注: *.html文件默认放在$APACHE/htdocs下,cgi处理程序放在$APACHE_HOME/cgi/bin下; 修改配置文件后,apache服务需要重启; 部署cgi程序,直接拷贝至/cgi-bin,无需重启服务

3. 测试运行

   3.1  安装成功后,直接运行键入http://localhost,会在浏览器在显示 It works! , 实际上执行的是 $APACHE/htdocs/index.html
   3.2  运行C++代码
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
    printf("Content-type:text/html\n\n");
    printf("");
    printf("");
    printf("Hello World - 第一个 CGI \n");
    printf(" ");

   /*
   cout << "Content-type:text/html\r\n\r\n";
   cout << "<html>\n";
   cout << "<head>\n";
   cout << "<title>Hello World - 第一个 CGI 程序</title>\n";
   cout << "</head>\n";
   cout << "<body>\n";
   cout << "<h2>Hello World! 这是我的第一个 CGI 程序</h2>\n";
   cout << "</body>\n";
   */

    return 0;
}

1、编译后生成Hello.exe
2 、启动httpd服务
3 、浏览器输入: http://localhost/cgi-bin/Hello.exe, 我们可以在页面上看到如下内容:
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值