BOA服务器移植——ubuntu16.04

76 阅读1分钟

安装阶段

下载

wget http://www.boa.org/boa-0.94.13.tar.gz

改错 boa-0.94.13/src/compat.h

tar xf boa-0.94.13.tar.gz

cd boa-0.94.13/src

vim compat.h +120

注释120行,新增121行

119 #ifdef HAVE_TM_GMTOFF
120 //#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff
121 #define TIMEZONE_OFFSET(foo) ((foo)->tm_gmtoff)
122 #else
123 #define TIMEZONE_OFFSET(foo) timezone
124 #endif

编译

./configure

make

运行阶段

创建配置目录

sudo mkdir /etc/boa

sudo cp boa.conf /etc/boa

创建日志目录

sudo mkdir /var/log/boa/

创建www目录

sudo mkdir /var/www/

创建cgi-bin目录

sudo mkdir /usr/lib/cgi-bin

新建/var/www/index.html

<html>
        <body>
                <h3>this is a test!</h3><br/>
                        <img src="image.jpg"/>
                <h3>tree picture</h3><br/>
 
                <a href="/cgi-bin/hello.cgi">to cgi page</a>
        </body>
</html>

新建/var/www/image.jpg,随便从网上下载一张图片,命名为image.jpg,放到/var/www/目录下

新建/usr/lib/cgi-bin/hello.c

// hello.c
#include <stdio.h>

int main() {
    printf("Content-type: text/html\n\n");
    printf("<html><body>\n");
    printf("<h1>Hello, World!</h1>\n");
    printf("</body></html>\n");
    return 0;
}
gcc -o hello.cgi hello.c

启动boa服务器

sudo ./boa

报错记录

报错1

gcc  -g -O2 -pipe -Wall -I.   -c -o util.o util.c
In file included from boa.h:50:0,
                 from util.c:26:
util.c: In function ‘get_commonlog_time’:
util.c:100:39: error: pasting "t" and "->" does not give a valid preprocessing token
         time_offset = TIMEZONE_OFFSET(t);
                                       ^
compat.h:120:30: note: in definition of macro ‘TIMEZONE_OFFSET’
 #define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff
                              ^
<builtin>: recipe for target 'util.o' failed
make: *** [util.o] Error 1

解决1

diff --git a/src/compat.h b/src/compat.h
index b3be2e0..9aabc92 100644
--- a/src/compat.h
+++ b/src/compat.h
@@ -117,7 +117,8 @@ char *strdup(char *s);
 #endif

 #ifdef HAVE_TM_GMTOFF
-#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff
+//#define TIMEZONE_OFFSET(foo) foo##->tm_gmtoff
+#define TIMEZONE_OFFSET(foo) ((foo)->tm_gmtoff)
 #else
 #define TIMEZONE_OFFSET(foo) timezone
 #endif

报错2

[06/May/2025:01:50:19 +0000] log.c:73 - unable to dup2 the error log: Bad file descriptor

解决2

#没有创建 /var/log/boa/ 目录、或者没有sudo运行boa 导致的

sudo mkdir /var/log/boa/
sudo ./boa