https://blog.csdn.net/WAN_EXE/article/details/77428460
第一步 :
下载源码www.boa.org
下载之后进行解压
wang@wang:~/Desktop/boa-0.94.13$
修改 src/compat.h 两处地方 ,否则会出现错误提示
找到#define TIMEZONE_OFFSET(foo)foo##->tm_gmtoff
修改成#defineTIMEZONE_OFFSET(foo)(foo)->tm_gmtoff
有两个配置文件,有几个地方容易出错
编译的时候不要把生成的文件放在root目录下,需要改以下几点
修改boa.conf文件
62 ErrorLog /home/wang/test/boa/error_log
63 # Please NOTE: Sending the logs to a pipe ('|'), as shown below,
64 # is somewhat experimental and might fail under heavy load.
65 # "Usual libc implementations of printf will stall the whole
66 # process if the receiving end of a pipe stops reading."
67 #ErrorLog "|/usr/sbin/cronolog --symlink=/var/log/boa/error_log /var/log/boa/error-%Y%m%d.log"
68
69 # AccessLog: The location of the access log file. If this does not
70 # start with /, it is considered relative to the server root.
71 # Comment out or set to /dev/null (less effective) to disable
72 # Access logging.
73
74 AccessLog /home/wang/test/boa/access_log
这两个是错误的目录,不要放在根目录下,搞不好容易引起权限问题。
注意需要在这个文件夹中建立这两个文件。
打开src/defines.h
27 /***** Change this, or use -c on the command line to specify it *****/
28
29 #ifndef SERVER_ROOT
30 #define SERVER_ROOT "/home/wang/test/boa/"
31 #endif
服务器的根目录,修改这个目录为本地的目录,主要目的是找到boa.conf文件,
所以需要将boa.conf文件copy到这个目录下面
cp boa.conf /home/wang/test/boa/
然后make
生成boa可执行文件,
需要sudo ./boa运行,因为要绑定监听80端口,这是个很重要的端口。
通过ps -aux | grep boa查看运行情况。
wang@wang:~/Desktop/boa-0.94.13/src$ ps -aux | grep boa
wang 2053 0.0 0.1 740160 15128 ? Sl 08:42 0:00 /usr/lib/x86_64-linux-gnu/indicator-keyboard-service --use-gtk
nobody 13973 0.0 0.0 12856 788 pts/7 S 13:42 0:00 ./boa
wang 14131 0.0 0.0 15964 944 pts/7 S+ 14:06 0:00 grep --color=auto boa
然后使用ldconfig查看电脑的ip,如果是都是在本机进行操作的话也可以直接用localhost代替
http://localhost/index.html
这个时候进去的话,会报404错误,因为boa服务器找不到index.html,所以还要做下面的事情。
新建一个文件index.html
<html>
<head>
</head>
<body>
<h2>This is boa index.html</h2>
</body>
</html>
就打印一句话,记得还要修改配置文件,因为我把index.html放在/home/wang/test/boa/www/目录下面
108 # DocumentRoot: The root directory of the HTML documents.
109 # Comment out to disable server non user files.
110
111 DocumentRoot /home/wang/test/boa/www
然后再在浏览器中输入网址就可以看到下面的内容了。
第二步 :
通过cgi建立动态网站
这个实例的内容是通过网页输入用户名和密码,网页通过server再获取用于名和密码。
当然也可以做个简单的计算器使用,主要修改相关的程序。
先修改boa.conf的配置
cgi配置和cgi文件的配置
172 # Uncomment the next line if you want .cgi files to execute from anywhere
173 AddType application/x-httpd-cgi cgi
190 # ScriptAlias: Maps a virtual path to a directory for serving scripts
191 # Example: ScriptAlias /htbin/ /www/htbin/
192
193 ScriptAlias /cgi-bin/ /home/wang/test/boa/cgi-bin/
码上代码
index.html文件
<html>
<head>
<title>CGI login</title>
</head>
<body>
<form name="login" action="cgi-bin/login.cgi" method="get">
loginname: <input type="text" name="name" /> </br>
password: <input type="password" name="pwd" /> </br>
comform: <input type="submit" value="login" />
</form>
<h2>This is boa index.html</h2>
</body>
</html>
login.cgi文件
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *data;
char name[50], pwd[20];
printf("content-type:text/html;charset=gb2312\n\n");
printf("<title>output</title>");
printf("<h2>output</h2>");
data = getenv("QUERY_STRING");
if (data == NULL) {
printf("<p>There is no input.</p>");
} else {
sscanf(data, "name=%[^&]&pwd=%s", name, pwd);
printf("<p>name = %s</p>", name);
printf("<p>pwd = %s</p>", pwd);
printf("%s",data);
}
return 0;
}
需要建立在cgi-bin/目录下面
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
char *data;
char name[50], pwd[20];
printf("content-type:text/html;charset=gb2312\n\n");
printf("<title>output</title>");
printf("<h2>output</h2>");
data = getenv("QUERY_STRING");
if (data == NULL) {
printf("<p>There is no input.</p>");
} else {
sscanf(data, "name=%[^&]&pwd=%s", name, pwd);
printf("<p>name = %s</p>", name);
printf("<p>pwd = %s</p>", pwd);
printf("%s",data);
}
return 0;
}
编译 gcc login.c -o login.cgi
最后的输出
output
name = hello
pwd = world
name=hello&pwd=world