转自:https://www.sfantree.com/boa_web_cgi/?utm_source=tuicool&utm_medium=referral
BOA看了 , CGI 原理也大概了解。
现在要两个配合起来才能666啊!
里面的下载了连接似乎没法下载了,自己去网上找了下载后放在百度云:http://pan.baidu.com/s/1mip3ZNq
里面还有一个readme是步骤!
具体实验还没做过所以不知道是对是错!!
********************************************开始摘抄**************************************************************
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
为你的交叉编译器路径
CROSS=/opt/buildroot-2012.08/arm920t/usr/bin/arm-linux-
CC = $(CROSS)gcc
CPP = $(CROSS)gcc -E
修改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
的效果:
***************************************************************************摘抄完成***********