内容简介:Boa+CGI环境搭建笔记
Boa 是一款优秀的轻量级 web 服务器,只有小小的 60KB ,支持 CGI 编程,广泛的应用于嵌入式领域,从诞生之初到现在已经有20多年的历史,不过在2005年停止了维护,稳定版本是 0.94.13
编译
wget https://coding.net/u/sfantree/p/self_use_OSS/git/raw/master/source/boa-0.94.13.tar.gz tar zxvf boa-0.94.13.tar.gz cd boa-0.94.13/src ./configure
修改 Makefile
CC CPP 为你的交叉编译器路径
修改 src/util.c
90 char *get_commonlog_time(void)
91 {
92 struct tm *t;
93 char *p;
94 unsigned int a;
95 static char buf[30];
96 int time_offset;
97
98 if (use_localtime) {
99 t = localtime(¤t_time);
100 //time_offset = TIMEZONE_OFFSET(t);
101 time_offset = 0;
102 } else {
103 t = gmtime(¤t_time);
104 time_offset = 0;
105 }
修改 src/boa.c
207 if (getuid() == 0) {
208 struct passwd *passwdbuf;
209 passwdbuf = getpwuid(server_uid);
210 #if 0
211 if (passwdbuf == NULL) {
212 DIE("getpwuid");
213 }
214 if (initgroups(passwdbuf->pw_name, passwdbuf->pw_gid) == -1) {
215 DIE("initgroups");
216 }
217 if (setgid(server_gid) == -1) {
218 DIE("setgid");
219 }
220 if (setuid(server_uid) == -1) {
221 DIE("setuid");
222 }
223 /* test for failed-but-return-was-successful setuid
224 * http://www.securityportal.com/list-archive/bugtraq/2000/Jun/0101.html
225 */
226 if (setuid(0) != -1) {
227 DIE("icky Linux kernel bug!");
228 }
229 #endif
否则接下来启动 boa 的过程会报错
#boa.c:226 - icky Linux kernel bug!: Success
Boa配置文件
make 过后的 boa 并不能直接使用,会提示缺少配置文件,而且配置文件的路径必须是 /etc/boa/boa.conf
源码最顶层有个 boa.conf 可以拿来做参考
#监听端口 Port 81 #日志信息 AccessLog /root/boa/access.log ErrorLog /root/boa/error.log #站点根目录 DocumentRoot /data/wwwroot/default DirectoryIndex index.html #超时设置 KeepAliveMax 1000 KeepAliveTimeout 10 #这个设置为html 否则浏览器可能不会解析网页 DefaultType text/html MimeTypes /dev/null CGIPath /bin:/usr/bin:/usr/local/bin Alias /doc /usr/doc #CGI文件的路径 访问[host]/cgi-bin 会寻找 /root/boa/cgi-bin/下的cgi文件 ScriptAlias /cgi-bin/ /root/boa/cgi-bin/
有关 MimeTypes 的之前写过一篇解决 lighttpd 无法渲染网页文件的 文章 ,
CGI
移植CGI库
wget https://coding.net/u/sfantree/p/self_use_OSS/git/raw/master/source/cgic205.tar.gz tar zxvf cgic205.tar.gz cd cgic205
修改 Makefike
... CROSS=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux- CFLAGS=-g -Wall CC=$(CROSS)gcc AR=$(CROSS)ar RANLIB=$(CROSS)ranlib ...
make 过后源码根目录会生成 libcgic.a
编译CGI文件
/*********************************************************************************
* Copyright: (C) 2017 popy32 http://sfantree.com
* All rights reserved.
* Filename: test.c
* Description: simple test for cgi programe on Boaweb server
* Version: 1.0.0(05/01/2017~)
* Author: popy32 panlingood@gmail.com
********************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <cgic.h>
int cgiMain()
{
cgiHeaderContentType("text/html");
fprintf(cgiOut, "<html> \
<head> \
</head> \
<body> \
welcome to my blog!</br> \
<a href=\'https://sfantree.com/\'>送你一场樱花雨/</a>\
</body>\
</html>");
return 0;
}
编译
$CC -L ../cgic205/ -lcgic -I ../cgic205/ test.c -o test.cgi
注意这里 ../cgic205/ 改为 libcgic.a 所在的路径
Boa 执行 CGI 的效果
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
C++标准模板库编程实战
Ivor Horton / 郭小虎、程聪 / 2017-1
《C++标准模板库编程实战》介绍最新的C++14标准的API、库和扩展,以及如何将它们运用到C++14程序中。在书中,作者Ivor Horton 则阐述了什么是STL,以及如何将它们应用到程序中。我们将学习如何使用容器、迭代器,以及如何定义、创建和应用算法。此外,还将学习函数对象和适配器,以及它们的用法。 阅读完本书之后,你将能够了解如何扩展STL,如何定义自定义类型的C++组件,你还将能够......一起来看看 《C++标准模板库编程实战》 这本书的介绍吧!