这个东西配置cgi的路径要一次配置出来,不要安装完再配置,否则容易出现cgi的跳转404的现象。

Boa介绍

其可执行代码只有大约60KB左右,Boa是一个单任务的HTTP服务器,Boa只能依次完成用户的请求,而不会fork出新的进程来处理并发连接请求。Boa支持CGI。Boa的设计目标是速度和安全。(CGI只是一个进程,用来提供接口),自动目录生成和自动文件枪支进行拼接。
Boa的主要设计目标是速度和安全性。安全性在“不能被恶意用户破坏”的意义上,不是“细粒度访问控制和加密通信”。

特点:可靠性和可移植性,Boa不是作为功能强大的服务器。
开发平台:GNU / Linux是目前的开发平台。

下载源码http://www.boa.org/

1
2
tar -xvf boa-0.94.13.tar.gz
cd ./boa-0.94.13/src/

更改文件

在boa-0.94.13/src目录下,新建install.mk文件,使用Makefile命令install和uninstall安装和卸载软件及软件配置信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
.PHONY: all install uninstall test

SRC_PWD = $(PWD)
SUDO = sudo
MKDIR = mkdir -p
CP = cp -rf
RM = rm -rf

BIN_BOA = boa
BIN_INDEX = boa_indexer

CONF_FILE = ../boa.conf

DIR_CONF = /etc/boa
DIR_LOG = /var/log/boa
DIR_ROOT = /var/wwwBoa
DIR_MAKER = /usr/lib/boa
DIR_CGI = /var/wwwBoa/cgi-bin

all:install

install:
@echo "Install boa."
$(SUDO) $(MKDIR) $(DIR_CONF) $(DIR_LOG) $(DIR_ROOT) $(DIR_MAKER) $(DIR_CGI) && \
$(SUDO) $(CP) $(SRC_PWD)/$(CONF_FILE) $(DIR_CONF) && \
$(SUDO) $(CP) $(SRC_PWD)/$(BIN_BOA) /usr/bin && \
$(SUDO) $(CP) $(SRC_PWD)/$(BIN_INDEX) $(DIR_MAKER) && \
$(SUDO) $(CP) $(SRC_PWD)/../examples/index.html $(DIR_ROOT)

uninstall:
@echo "Uninstall boa."
$(SUDO) $(RM) /usr/bin/boa
$(SUDO) $(RM) $(DIR_CONF)
$(SUDO) $(RM) $(DIR_LOG)
$(SUDO) $(RM) $(DIR_ROOT)
$(SUDO) $(RM) $(DIR_MAKER)

test:
@echo "-------This is a Test.---------"
@echo $(SRC_PWD)

更改boa.conf文件

1
2
3
4
User 0
Group 0
DocumentRoot /var/www
ScriptAlias /cgi-bin/ /var/www/cgi-bin/

之后进行编译

1
2
3
4
cd src
./configure
make
make -f install.mk install

之后在/var/www文件夹下面写html网页文件,写的内容就是你显示的内容。

1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Flyer</title>
</head>
<body>
<h1>hello world.</h1>
<p>how are you.</p>
</body>
</html>

如果加上cgi的跳转,请加上一句话

1
2
3
4
5
6
7
8
9
10
11
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Flyer</title>
</head>
<body>
<h1>hello world.</h1>
<p><a href="./cgi-bin/hello.cgi">cgi int the boa server</p>
</body>
</html>

之后就要写跳转的cgi文件,cgi就是C语言文件就行编译连接生成.cgi格式

1
2
3
4
5
6
7
8
9
10
#include<stdio.h>
int main()
{
printf("Content - Type:text/html\n\n");
printf("<title> cgi </title> \n ");
printf("<h1> hello world! </h1> \n");
printf("<p> this is a demo of cgi's program in the boa server </p > \n ");

return 0;
}
1
2
3
4
5
gcc hello.c -o hello.cgi
cp hello.cgi /var/www/cgi-bin/
cd
cd boa-0.94.13
sudo boa

以上是显示结果,地址为当前主机的ip地址,可以通过使用ifconfig进行查询。