背景
为了方便和协作者共享文件和方便文件统一管理及下载,比如分享API文档,因此搭建一个简易的基于Apache服务的Web文件系统,使用浏览器进行文件访问及下载。
部署Apache服务器
本文的linux开发环境是Ubuntu 18.04
安装
sudo apt install apache2
查看版本
apache2 -version
Server version: Apache/2.4.29 (Ubuntu)
Server built: 2023-03-08T17:34:33
查看是否运行
默认安装完毕后自动启动,Active: active(running)代表正在运行
systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Drop-In: /lib/systemd/system/apache2.service.d
└─apache2-systemd.conf
Active: active (running) since Thu 2023-08-31 14:58:40 CST; 46min ago
Process: 31473 ExecStop=/usr/sbin/apachectl stop (code=exited, status=0/SUCCESS)
Process: 31478 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 31482 (apache2)
Tasks: 55 (limit: 4915)
CGroup: /system.slice/apache2.service
├─31482 /usr/sbin/apache2 -k start
├─31483 /usr/sbin/apache2 -k start
└─31484 /usr/sbin/apache2 -k start
Aug 31 14:58:40 netease-Precision-3630-Tower systemd[1]: Starting The Apache HTTP Server...
Aug 31 14:58:40 netease-Precision-3630-Tower apachectl[31478]: [Thu Aug 31 14:58:40.080095 2023] [so:warn] [pid 31481:tid 140536320043968] AH01574: module rewrite_module is alr
Aug 31 14:58:40 netease-Precision-3630-Tower apachectl[31478]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the
Aug 31 14:58:40 netease-Precision-3630-Tower systemd[1]: Started The Apache HTTP Server
配置
- 默认服务器文档根目录在/var/www/html
- 浏览器访问ip地址,即可访问到index.html, 即/var/www/html/index.html,如下:
自定义文件目录配置
- 在/var/www/html目录创建软链接文件files指向自定义文件目录,如下
[netease@netease-Precision-3630-Tower /var/www/html]$ ls -l
total 12
lrwxrwxrwx 1 root root 41 Aug 31 15:10 files -> /home/netease/working/Apache_File_System/
-rw-r--r-- 1 root root 10918 Aug 31 11:53 index.html
- 游览器访问
http://ip地址/files
即可访问自定义目录/home/netease/working/Apache_File_System/
, 如下
[netease@netease-Precision-3630-Tower ~/working/Apache_File_System]$ ls -l
total 4
-rw-rw-r-- 1 netease netease 0 Aug 31 16:01 README.txt
drwxrwxr-x 3 netease netease 4096 Jul 14 10:34 反垃圾sdk-api-4.4.10.4
重启Web服务
如有需要使用如下指令重启服务,比如修改了apache配置文件等
sudo systemctl restart apache2