Ubuntu安装Web服务器Boa和CGIC

陈拓 2020/08/21-2020/10/25

相关文档:

《Ubuntu设置Nginx支持CGI》https://blog.csdn.net/chentuo2000/article/details/109205483

《树莓派安装Web服务器Boa和CGIC》https://blog.csdn.net/chentuo2000/article/details/108535232

1. 用putty或Win10自带ssh登录Ubuntu

2. 安装和测试Boa

2.1 换源

  • ubuntu版本查看

cat /etc/issue

  • 备份原始源文件source.list

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

  • 修改source.list

sudo nano /etc/apt/sources.list

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

  • 更新软件源

sudo apt update或者sudo apt-get update

sudo apt upgrade或者sudo apt-get upgrade

2.2 安装Boa

  • root权限操作

sudo su root

进入我的工作目录:

cd ct

  • 从官方下载boa源码

http://www.boa.org/

下载链接地址:

http://www.boa.org/boa-0.94.14rc21.tar.gz

下载:

wget -c http://www.boa.org/boa-0.94.14rc21.tar.gz

  • 解压缩

tar zxvf boa-0.94.14rc21.tar.gz

  • 安装依赖包,编译需要

apt-get install bison flex byacc m4

  • 进入源码目录

cd boa-0.94.14rc21

  • 生成Makefile文件

./configure

  • 编译

make

  • 安装

1) 创建/etc/boa目录

mkdir /etc/boa

2) 将生成的可执行程序以及配置文件复制到/etc/boa/目录下

cp src/boa src/boa_indexer /etc/boa

cp examples/boa.conf /etc/boa/

  • 创建日志文件目录

mkdir /var/log/boa/

  • 创建网站目录

mkdir /var/www/

mkdir /var/www/cgi-bin

2.3 Boa服务器的配置

  • boa配置文件boa.conf的位置

nano /etc/boa/boa.conf

  • 查看我的所有配置

cat /etc/boa/boa.conf | grep -v "^#"

Port 8080

User root

Group root

ErrorLog /var/log/boa/error_log # 调试完可以注释掉

AccessLog /var/log/boa/access_log # 调试完可以注释掉

DocumentRoot /var/www

UserDir public_html

DirectoryIndex index.html

KeepAliveMax 1000

KeepAliveTimeout 10

MimeTypes /etc/mime.types

DefaultType text/plain

CGIPath /bin:/usr/bin:/usr/local/bin

Alias /doc /usr/doc

ScriptAlias /cgi-bin/ /var/www/cgi-bin/

2.4 测试Boa

  • 创建index.html文件

在/var/www/目录下创建简单的index.html文件。

nano /var/www/index.html

<html>
<body>
<h1>Hello Pi BOA.</h1>
</body>
</html>
  • 运行boa 服务器

sudo /etc/boa/boa

  • 查看boa进程

ps -ef | grep boa

  • 显示网页

在浏览器地址栏输入http://192.168.1.8:8080/

  • 查看错误日志

  • 加网页图标

复制一个名为favicon.ico的图标文件到/var/www/目录

刷新浏览器。

3. 安装和测试CGIC

3.1 安装CGIC

CGIC是一个C语言cgi库,最新版本2.08,可以从github下载。

Github网址:https://github.com/boutell/cgic

  • 克隆cgic

退出root,在普通用户账户下操作。

git clone https://github.com/boutell/cgic.git

  • 查看cgic目录

3.2 测试CGIC

  • 建一个测试目录

mkdir cgic_test

  • 把cgic.c和cgic.h复制到测试目录

  • 进入测试目录

cd cgic_test

  • 写测试程序

nano test.c

#include <stdio.h>

int main(void)
{
    printf("Content-Type:text/plain;charset=us-ascii\n\n");
    printf("Hello World\n\n");
    return 0;
}
  • 编译test.c

gcc -o test.cgi test.c

  • 在本地运行测试

./test.cgi

将test.cgi复制到/var/www/cgi-bin

sudo cp test.cgi /var/www/cgi-bin

  • 在PC端浏览器运行测试

http://192.168.1.8:8080/cgi-bin/test.cgi

4. 开机启动boa

  • 修改rc-local.service文件

先找到rc-local.service文件

编辑rc-local.service

sudo nano /lib/systemd/system/rc-local.service

添加

[Install]
WantedBy=multi-user.target
Alias=rc-local.service

  • 创建/etc/rc.local文件

Ubuntu18.04没有/etc/rc.local,建立一个

sudo nano /etc/rc.local

#!/bin/sh -e

# startup boa
/etc/boa/boa

exit 0
  • 修改权限

sudo chmod 755 /etc/rc.local

  • 重启系统

sudo reboot

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

晨之清风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值