前言:毕设是做一个基于WebDAV协议的云盘,所以需要搭建一个支持WebDAV协议的服务器来作为云盘来存储文件。
系统要求:Ubuntu
搭建过程
# 安装Apache2服务器
sudo apt-get install -y apache2
# 开启Apache2中对WebDav协议的支持 (记住最好在用户目录下执行否则报错)
cd ~
sudo a2enmod dav
sudo a2enmod dav_fs
# 创建共享目录并修改权限
sudo mkdir -p /var/www/webdav
sudo chown -R www-data:www-data /var/www/webdav
#创建用户`dev`
sudo htpasswd -c /etc/apache2/webdav.password dev
# 修改用户数据库访问权限
sudo chown root:www-data /etc/apache2/webdav.password
sudo chmod 640 /etc/apache2/webdav.password
# 打开默认配置文件
sudo vim /etc/apache2/sites-available/000-default.conf
# 全部替换为以下内容:
DocumentRoot /var/www/html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
DocumentRoot /var/www/webdav
<Directory /home/ubuntu/webdav>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /webdav /var/www/webdav
<Location /webdav>
Options Indexes
DAV On
AuthType Basic
AuthName "webdav"
AuthUserFile /etc/apache2/webdav.password
Require valid-user
</Location>
</VirtualHost>
# 重启Apache2服务器
sudo systemctl restart apache2
# 或
sudo /etc/init.d/apache2 reload</pre>
此时,在浏览器输入:http://ip/webdav
即可访问
支持WebDav协议的客户端工具有cadaver等,我使用的是Win版的Cyberduck,可以使用客户端工具来验证是否支持GET, PUT, DELETE, COPY等操作。
网友评论