Apache服务器开启webDAV模块

本文主要介绍Centos6.x系统Apache服务器开启webDAV模块。

1.安装Apache

1
2
# yum -y install httpd apr apr-util httpd-devel			安装
# chkconfig httpd on 开机启动

2.配置WebDAV模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# vim /etc/httpd/conf.d/webdav.conf				在Apache的子配置文件目录新建文件
<IfModule mod_dav.c>
LimitXMLRequestBody 131072
Alias /webdav "/var/www/webdav"
<Directory /var/www/webdav>
Dav On
Options +Indexes
IndexOptions FancyIndexing
AddDefaultCharset UTF-8
AuthType Basic
AuthName "WebDAV Server"
AuthUserFile /etc/httpd/webdav.users.pwd
Require valid-user
Order allow,deny
Allow from all
</Directory>
</IfModule>

# mkdir -p /var/www/webdav
# chown apache:apache /var/www/webdav
# htpasswd -c /etc/httpd/webdav.users.pwd test 根据提示输入密码,切记一定要设置密码,否则会有安全问题
# service httpd restart 重启apache服务

3.测试

通过浏览器访问:访问本机 , 访问远程:http://ip/webdav

4.将webdav映射成本地磁盘

在windows上映射成本地磁盘,需要注意:
WIN7以上版本的操作系统微软禁用了http形式的基本WebDAV验证形式(KB841215),此时我们需要修改注册表来实现。修改HKEY_LOCAL_MACHINE>>SYSTEM>>CurrentControlSet>>Services>>WebClient>>Parameters>>BasicAuthLevel
把这个值从1改为2,然后进控制面板,服务,把WebClient服务重启(没有启动的就启动它)。

具体操作如下:
在桌面上【我的电脑】图标上点击【右键】,选择【映射网络驱动器】,在弹出框中填入上面的地址,比如:http://192.168.0.215/webdav/ ,勾选【登录时重新连接】和【使用其他凭据连接】,然后点击【完成】。输入【账号和密码】就可以进入了。

5.将webdav挂载到linux上

linux系统上有多个办法来使用webdav服务。
(1) davfs2工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# yum install epel-release -y							安装epel源
# yum install davfs2 -y 安装davfs

# mkdir /mnt/webdav 创建用于挂载的目录
# mount -t davfs http://192.168.0.215/webdav /mnt/webdav/ 挂载
Please enter the username to authenticate with server
http://192.168.0.215/webdav or hit enter for none.
Username: test 用户名
Please enter the password to authenticate user test with server
http://192.168.0.215/webdav or hit enter for none.
Password: 密码

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root 50G 19G 29G 40% /
tmpfs 3.9G 0 3.9G 0% /dev/shm
/dev/sda1 485M 39M 421M 9% /boot
/dev/mapper/VolGroup-lv_home 435G 199M 413G 1% /home
http://192.168.0.215/webdav 26G 13G 13G 50% /mnt/webdav

(2) cadaver工具

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# yum install cadaver -y

# cadaver http://192.168.0.215/webdav
Authentication required for WebDAV Server on server `192.168.0.215':
Username: test
Password:
dav:/webdav/> ls
Listing collection `/webdav/': collection is empty.
dav:/webdav/> help
Available commands:
ls cd pwd put get mget mput
edit less mkcol cat delete rmcol copy
move lock unlock discover steal showlocks version
checkin checkout uncheckout history label propnames chexec
propget propdel propset search set open close
echo quit unset lcd lls lpwd logout
help describe about
Aliases: rm=delete, mkdir=mkcol, mv=move, cp=copy, more=less, quit=exit=bye

(3) curl命令

1
2
3
4
上传:
# curl -v --user test:123456 -T install.log http://192.168.0.215/webdav/
下载:
# curl --user test:123456 http://192.168.0.215/webdav/install.log > install.txt

---------------- The End ----------------