内容简介: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 的效果
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- Hyperledger Fabric环境搭建及环境测试(Mac环境)
- CV 环境很重要,各种环境搭建大全
- Openstack Queens 环境搭建(一)环境准备
- Python 环境搭建
- 1 - 搭建开发环境
- 搭建 Android 内核环境
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Clojure编程
Chas Emerick、Brian Carper、Christophe Grand / 徐明明、杨寿勋 / 电子工业出版社 / 2013-3-26 / 99.00元
Clojure是一种实用的通用语言,它是传奇语言LISP的方言,可与Ruby、Python等动态语言相媲美,更以无缝Java库、服务,以及拥有JVM系统得天独厚的资源优势而胜出。本书既可以用来熟悉Clojure基础知识与常见例子,也可了解其相关的实践领域与话题,更可以看到这一JVM平台上的LISP如何帮助消除不必要的复杂性,为大家在编程实践中解决最具挑战性的问题开辟新的选择——更具灵活性,更适于W......一起来看看 《Clojure编程》 这本书的介绍吧!
JSON 在线解析
在线 JSON 格式化工具
html转js在线工具
html转js在线工具