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.为了 ...
随机推荐
- ch.poweredge.ntlmv2-auth
<dependency> <groupId>ch.poweredge.ntlmv2-auth</groupId> <artifactId>ntlmv2- ...
- LeetCode:奇偶链表【328】
LeetCode:奇偶链表[328] 题目描述 给定一个单链表,把所有的奇数节点和偶数节点分别排在一起.请注意,这里的奇数节点和偶数节点指的是节点编号的奇偶性,而不是节点的值的奇偶性. 请尝试使用原地 ...
- UVA - 11954 Very Simple Calculator 【模拟】
题意 模拟二进制数字的位运算 思路 手写 位运算函数 要注意几个坑点 一元运算符的优先级 大于 二元 一元运算符 运算的时候 要取消前导0 二元运算符 运算的时候 要将两个数字 数位补齐 输出的时候 ...
- Database: key
super-key: Any key that has more columns than necessary to uniquely identify each row in the table i ...
- TensorFlow Action(开山使用篇)
1.TensorFlow安装: 使用pip install tensorflow安装CPU版: 或使用pip install tensorflow-gpu==1.2.1指定版本安装GPU版. 2.Te ...
- 跟我一起学Git (十) Patches【转】
本文转载自:http://cs-cjl.com/2014/05/05/learn_git_with_me_10 Git实现了以下三条用于交换patch的命令: git format-patch 用于创 ...
- 三年java软件工程师应有的技技能
摘要:http://blog.csdn.net/jieinasiainfo/article/details/51177729 http://blog.csdn.net/kangqianglong/ar ...
- PHP相关安全配置【转】
PHP是广泛使用的开源服务端脚本语言.通过HTTP或HTTPS协议,Apache Web服务允许用户访问文件或内容.服务端脚本语言的错误配置会导致各种问题.因此,PHP应该小心使用.以下是为系统管理员 ...
- 存储过程IF --ELSE IF -- END IF 使用
CREATE OR REPLACE PROCEDURE BJPJYXK_HF_SD( sqid_p IN VARCHAR2,--申请单ID xkbh_p IN VARCHAR2,--新生成的许可证编号 ...
- centos7在VMware下配置网络连接
安装成功以后,首先更改vmwar的虚拟网络设置 1.参考连接:http://www.cnblogs.com/liongis/p/3265458.html 2.然后将虚拟机的设置里面将网络配置的连接方式 ...