概述:参考了大牛们的方法,结合自己的环境做了修改,主要是讲:minihttp安装配置ssl和c语言实现cgi接收字符串并且保存
系统环境:centos6.5 开发版

依赖软件包:

mini_httpd-1.19.tar.gz  

cgic206.tar.gz

openssl

openssl-devel

说明:前面因需要已经安装过openssl和openssl-devel了,这里没有做openssl的安装说明。

1.   安装mini_httpd:

tar zxf mini_httpd-1.19.tar.gz 

cd mini_httpd-1.19

//我在安装的时候这里不修改会报错误,说是原来的getline和系统的函数有冲突

vim htpasswd.c +    修改函数名称 getline, 改为 my_getline

vim htpasswd.c + 修改函数名称 getline, 改为 my_getline

make make install

2.   建立存放网页和cgi的目录:

mkdir /root/mini/

mkdir /root/mini/wwwroot

mkdir /root/mini/wwwroot/cgi-bin

3.  创建配置文件

touch /root/mini/mini_httpd.pid

touch /root/mini/wwwroot/mini_httpd.log

vim /root/mini/mini_httpd.conf  //添加以下内容
port=
  dir=/root/mini/wwwroot
  cgipat=cgi-bin/*
  user=nobody
  pidfile=/root/mini/mini_httpd.pid
  logfile=/root/mini/wwwroot/mini_httpd.log

4.  把网页放在wwwroot目录下

touch /root/mini/wwwroot/index.html
echo mymini_httpd > /root/mini/wwwroot/index.html

5.  启动mini_httpd

/usr/local/sbin/mini_httpd -C /root/mini/mini_httpd.conf

6.  测试是否成功,在客户端浏览器中访问mini_httpd服务器,在浏览器地址栏中输入:

//ip地址:8080
例如:192.168.1.120:
//显示出 mymini_httpd就是成功了

===============================================================

下面是配置SSL的步骤:
1.配置ssl

//进入到mini_httpd的目录:
cd mini_httpd-1.19 //编辑Makefile , 去掉17-20行的注释
SSL_TREE = /usr/local/ssl
SSL_DEFS = -DUSE_SSL
SSL_INC = -I${SSL_TREE}/include
SSL_LIBS = -L${SSL_TREE}/lib -lssl -lcrypto //修改67-69行365改为3650
cert: mini_httpd.pem
mini_httpd.pem: mini_httpd.cnf
openssl req -new -x509 -days -nodes

2.编译安装mini_httpd源码

make
make install
//如果出错,再次编译需要 make clean

3. 生成ssl证书

make cert
cp ./mini_httpd.pem /etc/

4. 修改mini_httpd.conf配置文件,没有就自己新建一个,下面是我的mini_httpd.conf内容:

#mini_httpd configuration file
data_dir=/root/mini/wwwroot/
#太关键了,前面没有加,结果就是在程序中写不进去内容。
user=root
port=
host=0.0.0.0
cgipat=cgi-bin/*.cgi
logfile=/var/log/mini_httpd
pidfile=/var/run/mini_httpd.pid
charset=GB2312
ssl
certfile=/etc/mini_httpd.pem
//启动mini_http
/usr/local/sbin/mini_httpd -C ./mini_httpd.conf

5.  安装cgic206.tar.gz

tar zxf cgic206.tar.gz 

cd cgic206

make 

//生成的是测试的.cgi程序

下面是自己编写一个.cgi程序

vim test.c

 #include <stdio.h>
#include "cgic.h"
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h> extern char *cgiQueryString;

int file_w(char *filename, char *buf)
{
int size, fd;
fd = open (filename, O_CREAT | O_RDWR | O_TRUNC, );
size = write (fd, buf, strlen(buf));
if (size < )
{
return -;
}
close (fd);
return ;
} int cgiMain()
{
int res;
res = file_w ("/root/tang.log", cgiQueryString);
if (res == -)
{
perror ("file_w");
}
#if 1   //将要发送的内容回显在网页
cgiHeaderContentType("text/html");
fprintf(cgiOut, "<HTML><HEAD>\n");
fprintf(cgiOut, "<TITLE>My CGIC</TITLE></HEAD>\n");
fprintf(cgiOut, "<BODY>");
fprintf(cgiOut, "<H1>%s</H1>",cgiQueryString);
fprintf(cgiOut, "</BODY>\n");
fprintf(cgiOut, "</HTML>\n");
#endif
return ;
}

修改Makefile,做修改前记得备份

cp Makefile Makefilebak
vim Makefile

//vim命令行模式下,替换cgictest:
:%s/cgictest/test/g

编辑完成后保存退出

 make

产生一个test.cgi的文件,拷贝到/root/mini/wwwroot/cgi-bin/目录下

测试:

  在地址栏里面输入:https://ip地址:8080/cgi-bin/test.cgi?测试内容

  回车,记得别忘了test.cgi后面的问号(?),我在测试的时候测试内容前面没有加问号结果测试不出来

结束minihttpd:退出的时候老是退不干净,需要手动的杀死,还没有找到原因,如果哪位大哥知道了麻烦告诉一声,现在用的这种方法杀死进程的:

//查询进程号
ps -ef | grep mini_httpd
kill - 进程号

参考http://joyquitelarge.blog.163.com/blog/static/179062171201241165644255/
        http://www.cnblogs.com/liuyangriver/archive/2012/10/31/2748576.html
        http://deepfuture.iteye.com/blog/1435339

minihttp安装配置ssl和c语言实现cgi的更多相关文章

  1. 我是如何将网站全站启用Https的?-记录博客安装配置SSL证书全过程

    评论»   文章目录 为什么要Https 如何选择Https 安装部署SSL证书 平滑过渡Https 搜索引擎的响应 启用Https小结 正如大家所看到的,部落全站已经启用了Https访问了,连续几天 ...

  2. CentOS服务器下安装配置SSL

    https是一个安全的访问方式,数据在传输过程中是加密的,https基于SSL. 一.安装apache和ssl模块 1.安装apache #yum install httpd 2.安装ssl模块 #y ...

  3. Apache安装及配置ssl

    目录 1.windows安装 软件准备 安装apache 开启ssl(Https访问) 打开httpd.conf,解除下面配置的注释 查看ssl模块使用哪一个配置文件 配置https虚拟主机 简单配置 ...

  4. Git安装配置和提交本地代码至Github,修改GitHub上显示的项目语言

    1. 下载安装git Windows版Git下载地址: https://gitforwindows.org/ 安装没有特别要求可以一路Next即可,安装完成后可以看到: 2. 创建本地代码仓库 打开G ...

  5. (转)python中调用R语言通过rpy2 进行交互安装配置详解

    python中调用R语言通过rpy2 进行交互安装配置详解(R_USER.R_HOME配置) 2018年11月08日 10:00:11 luqin_ 阅读数:753   python中调用R语言通过r ...

  6. 【Nginx】之安装使用和配置SSL支持

    本文采用的是nginx源码安装 1.下载nginx源码包 wget http://nginx.org/download/nginx-1.8.0.tar 或者登录nginx官网下载更高版本 2.ngin ...

  7. 在Ubuntu 16.04安装 Let’s Encrypt并配置ssl

    1.安装前准备 1)要确保python的默认版本为2.7及以上版本. 2)需要配置的apache.nginx需要提前配置绑定域名. 2.安装ssl 在这个https://certbot.eff.org ...

  8. centos安装配置nginx,ssl生产和配置教程

    [一]nginx安装nginx安装带ssl扩展: cd /usr/local/src #进入用户目录wget http://nginx.org/download/nginx-1.15.0.tar.gz ...

  9. 阿里云万网虚拟主机安装配置Https(SSL)教程

    太多太多的用户咨询阿里云虚拟主机是否可以安装SSL数字证书?万网空间是否可以支持HTTPS协议访问网站?答案只有一个:目前阿里云虚拟主机都不支持安装SSL证书!但是,但是,可以曲线实现目标! 1.为了 ...

随机推荐

  1. python 基础 7.4 os 模块

    #/usr/bin/python #coding=utf8 #@Time   :2017/11/11 3:15 #@Auther :liuzhenchuan #@File   :os 模块.py im ...

  2. 【BZOJ4653】[Noi2016]区间 双指针法+线段树

    [BZOJ4653][Noi2016]区间 Description 在数轴上有 n个闭区间 [l1,r1],[l2,r2],...,[ln,rn].现在要从中选出 m 个区间,使得这 m个区间共同包含 ...

  3. 关于TransactionScope 使用

    在去年的项目中使用了TransactionScope,现在总结下TransactionScope的使用说明 一.TransactionScope是.Net Framework 2.0之后,新增了一个名 ...

  4. 《Linux 鸟哥私房菜》 第一部分 Linux文件、目录与磁盘格式

    1.Linux就是内核层与系统调用接口层这2层.

  5. 谷歌postman插件的安装与使用

    下载地址:http://pan.baidu.com/s/1kTh1g4B 安装方法: 1.下载并解压 2.解压后.打开谷歌浏览器.选择很多其它工具→扩展程序,如图 3.勾选开发人员模式 4.选择载入正 ...

  6. 卸载apache服务

    卸载服务,管理员身份运行命令行程序,输入 sc delete apache2.2

  7. 在maven 中部署SSM项目找不 Spring ContextLoaderListener 的解决办法

    1.项目使用技术:maven的项目使用了Spring MVC+Spring +Mybatis+Tomcat搭建一个项目. 2.报错信息: Error configuring application l ...

  8. Java for LeetCode 108 Convert Sorted Array to Binary Search Tree

    Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 解题 ...

  9. Android 普通okhttp、okhttp utils执行 post get请求,文件上传下载、请求图片

    public class OKHttpActivity extends Activity implements View.OnClickListener { public static final M ...

  10. 登录令牌 Token 介绍

     Token值介绍 token 值: 登录令牌.利用 token 值来判断用户的登录状态.类似于 MD5 加密之后的长字符串. 用户登录成功之后,在后端(服务器端)会根据用户信息生成一个唯一的值.这个 ...