文件存储服务器 之 httpd


支持原创,转载请附上原文链接


keywords

  1. ubuntu httpd 安装
  2. 文件存储服务器

0 引言

需求搭建一个简单的文件存储服务器。下面介绍方案之一httpd

1 httpd安装

这里选择的是经过源码编译安装的方式,可能个人比较喜欢简洁明了,不喜欢引入一大堆依赖,所以放弃apt install。安装的脚本比较简单,代码如下:

#!/bin/bash

if [[ $# -ne 1 ]];then
  cat << EOF
Usage: bash $0 absolute_dir(where you want to install)
EOF
  exit 1
fi
PWD_DIR=$PWD
INSTALL_DIR=$1

# 并行编译任务数量
cores=8
if which nproc &> /dev/null; then
  cores=$(nproc)
fi
cores=$((cores-1))
[ $cores -gt 32 ] && cores=32
[ $cores -lt 0 ] && cores=2

# install ARR
cd /tmp
wget -O /tmp/apr-1.4.5.tar.gz "http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz"
tar -xvf apr-1.4.5.tar.gz
cd apr-1.4.5
./configure --prefix=${INSTALL_DIR}/apr
make -j ${cores} && make -j ${cores} install


# install apr-util
cd /tmp
wget -O /tmp/apr-util-1.3.12.tar.gz "http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz"
tar -xvf apr-util-1.3.12.tar.gz
cd apr-util-1.3.12
./configure --prefix=${INSTALL_DIR}/apr-util --with-apr=${INSTALL_DIR}/apr
make -j ${cores} && make -j ${cores} install

# install pcre
cd /tmp
wget -O /tmp/pcre-8.10.zip "http://jaist.dl.sourceforge.net/project/pcre/pcre/8.10/pcre-8.10.zip"
unzip -o pcre-8.10.zip
cd pcre-8.10
./configure --prefix=${INSTALL_DIR}/pcre
make -j ${cores} && make -j ${cores} install

# install httpd
cd /tmp
wget -O /tmp/http-2.4.54.tar.bz2 "https://dlcdn.apache.org/httpd/httpd-2.4.54.tar.gz"
tar -xvf http-2.4.54.tar.bz2
cd httpd-2.4.54
./configure --prefix=${INSTALL_DIR}/httpd --with-apr=${INSTALL_DIR}/apr --with-apr-util=${INSTALL_DIR}/apr-util --with-pcre=${INSTALL_DIR}/pcre --enable-ssl --with-ssl=/usr/local/openssl
make -j ${cores} && make -j ${cores} install

cd ${PWD_DIR}

echo "httpd install succ with pwd_dir:$PWD, install_dir:$INSTALL_DIR, cores=${cores}"

1.1 httpd编译错误

上面脚本编译httpd会存在如下错误:

Did not find working script at pcre-config

但是其实是安装了pcre的,错误的原因是:
上面pcre不是安装在系统路径,因此添加pcre的bin到系统PATH环境变量即可

2 简单测试

先来看看效果


httpd 效果图

2.1 启动

到上面安装的目录,执行

sudo ./httpd/bin/httpd

即可启动httpd。

2.2 配置文件

源码安装的配置文件,与网上说的不同,是在安装路径下面,目录结构为

bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

其中:

  • conf就是存放配置文件的位置
  • htdocs就是网页默认启动的位置

对于httpd.conf的具体配置,可以参考httpd配置,我这里直接使用默认的数据

2.3 简单测试

下面就开始测试,在htdocs下面创建一个目录demo,存放文件如下:

.
├── 0-readme.md
├── file1
└── file2

现在可以开始访问了,访问方式:

ip:80/demo
ip/demo

其中,ip是你运行httpd机器的地址

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容