CentOS 6.4平台下C++(cgi-bin)开发Web Server(Hello world)
2017-12-11 20:59
561 查看
服务器配置:
httpd.conf文件中所有和cgi-bin相关的内容:
/var/www/cgi-bin目录下文件如下:
其中,a.cgi是server.cpp编译后生成的文件。
server.cpp代码如下:
执行效果如下:
sh.cgi 代码如下:
效果如下:
index.html代码如下:
执行效果如下:
yum install httpd vim /etc/httpd/conf/httpd.conf
httpd.conf文件中所有和cgi-bin相关的内容:
Listen 80 DocumentRoot "/var/www/cgi-bin" <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory "/var/www/cgi-bin"> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all </Directory> ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" <Directory "/var/www/cgi-bin"> AllowOverride None Options ExecCGI Order allow,deny Allow from all </Directory> <Directory /var/www/cgi-bin/> Options Indexes FollowSymLinks ExecCGI AllowOverride None allow from all </Directory>
/var/www/cgi-bin目录下文件如下:
# tree . |-- a.cgi |-- index.html |-- server.cpp `-- sh.cgi
其中,a.cgi是server.cpp编译后生成的文件。
g++ server.cpp -o a.cgi
server.cpp代码如下:
#include <iostream> using namespace std; int main () { 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"; cout << "</html>\n"; return 0; }
执行效果如下:
sh.cgi 代码如下:
#!/bin/bash echo "Content-type: text/html" echo "" echo "Hello world"
效果如下:
index.html代码如下:
<title>test </title>
执行效果如下:
相关文章推荐
- Centos搭建C/C++开发平台
- 开发人员学Linux(10):CentOS7安装配置代码质量管理平台SonarQube6.4
- Ubuntu 13.04/CentOS 6.4 下C++开发时的相关设置
- 开发人员学Linux(10):CentOS7安装配置代码质量管理平台SonarQube6.4
- Ubuntu13.04/CentOs 6.4 下C++开发时的相关设置
- centos6.4 搭建c++eclipse环境
- 100个windows平台C++开发错误之十类
- 100个windows平台C++开发错误之指针
- codeblocks+wxwidgets+boost搭建c++开发平台步骤||如何在CodeBlock中添加boost库文件
- 【转】初识linux平台C++开发
- 在centos (linux) 搭建 eclipse c++开发分环境
- Linux开发---usr/bin/c++ :not found
- codeblocks+wxwidgets+boost搭建c++开发平台步骤
- linux平台eclipse开发c/c++
- 100个windows平台C++开发错误之十七数组
- 用 Eclipse 平台进行 C/C++ 开发
- Linux下搭建c、c++开发平台--Eclipse3.3+CDT4.0 (2007-09-18 10:12)
- CentOS 6.5平台使用CLion开发程序,编译器支持C++11的方法
- Code::Blocks 是一个开放源码的全功能的跨平台C/C++集成开发环境.
- 问题合集 ------- 用 Eclipse 平台进行 C/C++ 开发