minihttp安装配置ssl和c语言实现cgi
概述:参考了大牛们的方法,结合自己的环境做了修改,主要是讲: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的更多相关文章
- 我是如何将网站全站启用Https的?-记录博客安装配置SSL证书全过程
评论» 文章目录 为什么要Https 如何选择Https 安装部署SSL证书 平滑过渡Https 搜索引擎的响应 启用Https小结 正如大家所看到的,部落全站已经启用了Https访问了,连续几天 ...
- CentOS服务器下安装配置SSL
https是一个安全的访问方式,数据在传输过程中是加密的,https基于SSL. 一.安装apache和ssl模块 1.安装apache #yum install httpd 2.安装ssl模块 #y ...
- Apache安装及配置ssl
目录 1.windows安装 软件准备 安装apache 开启ssl(Https访问) 打开httpd.conf,解除下面配置的注释 查看ssl模块使用哪一个配置文件 配置https虚拟主机 简单配置 ...
- Git安装配置和提交本地代码至Github,修改GitHub上显示的项目语言
1. 下载安装git Windows版Git下载地址: https://gitforwindows.org/ 安装没有特别要求可以一路Next即可,安装完成后可以看到: 2. 创建本地代码仓库 打开G ...
- (转)python中调用R语言通过rpy2 进行交互安装配置详解
python中调用R语言通过rpy2 进行交互安装配置详解(R_USER.R_HOME配置) 2018年11月08日 10:00:11 luqin_ 阅读数:753 python中调用R语言通过r ...
- 【Nginx】之安装使用和配置SSL支持
本文采用的是nginx源码安装 1.下载nginx源码包 wget http://nginx.org/download/nginx-1.8.0.tar 或者登录nginx官网下载更高版本 2.ngin ...
- 在Ubuntu 16.04安装 Let’s Encrypt并配置ssl
1.安装前准备 1)要确保python的默认版本为2.7及以上版本. 2)需要配置的apache.nginx需要提前配置绑定域名. 2.安装ssl 在这个https://certbot.eff.org ...
- centos安装配置nginx,ssl生产和配置教程
[一]nginx安装nginx安装带ssl扩展: cd /usr/local/src #进入用户目录wget http://nginx.org/download/nginx-1.15.0.tar.gz ...
- 阿里云万网虚拟主机安装配置Https(SSL)教程
太多太多的用户咨询阿里云虚拟主机是否可以安装SSL数字证书?万网空间是否可以支持HTTPS协议访问网站?答案只有一个:目前阿里云虚拟主机都不支持安装SSL证书!但是,但是,可以曲线实现目标! 1.为了 ...
随机推荐
- activemq 搭建--集群
linux activmemq 集群安装,配置和高可用测试 从 ActiveMQ 5.9 开始,ActiveMQ 的集群实现方式取消了传统的Master-Slave 方式,增加了基于Z ...
- share初始化
要看懂share先看与map的交互以及跨地图的交互 share初始化 void Share::ShareInit(I_DataLayer* data_layer) { // 加载xls表 if(!Lo ...
- 1930: [Shoi2003]pacman 吃豆豆
1930: [Shoi2003]pacman 吃豆豆 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1969 Solved: 461[Submit][ ...
- COGS410. [NOI2009] 植物大战僵尸
410. [NOI2009] 植物大战僵尸 ★★★ 输入文件:pvz.in 输出文件:pvz.out 简单对比时间限制:2 s 内存限制:512 MB [问题描述] Plants vs ...
- hdu 4667 Building Fence < 计算几何模板>
//大白p263 #include <cmath> #include <cstdio> #include <cstring> #include <string ...
- js实现随机选取[10,100)中的10个整数,存入一个数组,并排序。 另考虑(10,100]和[10,100]两种情况。
1.js实现随机选取[10,100)中的10个整数,存入一个数组,并排序. <!DOCTYPE html> <html lang="en"> <hea ...
- 题解 P3372 【【模板】线段树 1】
发一篇不需要O2就能过的分块. 基本思路: 分块的思路,大段维护,小段朴素. 维护几个数组: 区块\(block[maxn]\) 懒标记\(tag[maxn]\) 真实数据\(data[maxn]\) ...
- quick-cocos2d-x教程11:实现http通信,并与站点php对接,可实现登录等常见功能
手机游戏眼下是弱联网居多,http登录是经常使用功能.我们如今就来实现. 在启动时候.自己主动请求http. function MainScene:ctor() local url = &qu ...
- 【shell】获取第10+个位置参数
转载自:http://www.cnblogs.com/sheldonxu/archive/2012/06/25/2560770.html 在Shell脚本中,可以用$n的方式获取第n个参数,例如,一个 ...
- Kattis - cardhand Card Hand Sorting 【暴力枚举】
题意 给出 一个扑克牌的序列 求排成一个"有序"序列 最少的插入次数 有序是这样定义的 同一个花色的 必须放在一起 同一花色中的牌 必须是 升序 或者是 降序 然后 A 是最大的 ...