WebDAV可以把http当做一个私人“网盘”来使用,其实是很方便的,而且outlook等应用也支持webdav,真的很不错哟。

现有系统centos7一台,ip192.168.42.15/24,我们测试安装的过程。

yum install httpd

加入开机启动
systemctl enable httpd.service

启动httpd
systemctl start httpd.service

检测是否支持dav模块
httpd -M | grep fs
显示dav_fs_module (shared)表示已安装dav模块

开放端口:

firewall-cmd --permanent --add-service=http
firewall-cmd --reload

建立目录
mkdir /var/www/html/webdav
chown apache:apache /var/www/html/webdav

创建新web用户webdav,并输入用户密码
htpasswd -c /etc/httpd/.htpasswd webdav

保护密码文件:
chown root:apache /etc/httpd/.htpasswd
chmod 640 /etc/httpd/.htpasswd

建个新配置文件:
vim /etc/httpd/conf.d/webdav.conf
内容:

DavLockDB /var/www/html/DavLock
<VirtualHost *:80>
        ServerAdmin xxy@yyshell.com
        DocumentRoot /var/www/html/webdav/
    ErrorLog /var/log/httpd/error.log
    CustomLog /var/log/httpd/access.log combined
        Alias /webdav /var/www/html/webdav
        <Directory /var/www/html/webdav>
            DAV On
            AuthType Basic
            AuthName "webdav"
#           AddDefaultCharset utf-8
            IndexOptions Charset=utf-8
            AuthUserFile /etc/httpd/.htpasswd
            Require valid-user
        </Directory>
</VirtualHost>

重启Apache:
systemctl restart httpd.service

用webdav客户端新建文件夹,发现500 Internal Server Error,查看error.log

[Thu Sep 08 15:47:38.444472 2016] [dav:error] [pid 3267] [client 192.168.42.81:54584] The locks could not be queried for verification against a possible “If:” header. [500, #0]
[Thu Sep 08 15:47:38.444571 2016] [dav:error] [pid 3267] [client 192.168.42.81:54584] Could not open the lock database. [500, #400]
[Thu Sep 08 15:47:38.444580 2016] [dav:error] [pid 3267] (13)Permission denied: [client 192.168.42.81:54584] Could not open property database. [500, #1]

这是因为LockDB的上级目录权限不足导致的,我们设置下权限
chown -R apache:apache /var/www/html/

结果还不行!
设置下selinux
setsebool -P httpd_unified 1

发现可以了。

如果上传文件发现乱码,记得设置传输的时候,采用utf-8编码!

如果你的目录不在默认的/var/www/html目录下,例如,你通过采用不同的端口,在8080端口下,开通了一个webdav虚拟主机,webdav的工作目录再/var/www/webdav目录下,如果按照上述的配置, 你可以会遇到如下的错误:

[autoindex:error] [pid 133095:tid 139787344271104] [client 192.168.42.81:56582] AH01276: Cannot serve directory /var/www/webdav/: No matching DirectoryIndex (index.html,index.php) found, and server-generated directory index forbidden by Options directive

这个错误是由于默认的索引导致的,可以在VirtualHost的配置中,关闭索引即可。

DavLockDB /var/www/DavLock
listen 8080
<VirtualHost *:8080>
        DirectoryIndex disabled
        Options Indexes
        ServerName 192.168.42.15:8080
        ServerAdmin xxy@yyshell.com
        DocumentRoot /var/www/webdav/
    ErrorLog /var/log/httpd/error.log
    CustomLog /var/log/httpd/access.log combined
        Alias /webdav /var/www/webdav
        <Directory /var/www/webdav>
            DAV On
            AuthType Basic
            AuthName "webdav"
#           AddDefaultCharset utf-8
            IndexOptions Charset=utf-8
            AuthUserFile /etc/httpd/.htpasswd
            Require valid-user
        </Directory>
</VirtualHost>

这样,就可以通过不同的端口进行访问了。

linux命令行下,有一个webdav客户端挺好用,名字叫cadaver,喜欢的用户可以再epel源中直接yum安装下。
连接方法:cadaver http://192.168.42.15/webdav/
输入用户名和密码进入后,里面的大部分操作和ftp命令行客户端很像,相信你会使用ftp的话,就会使用,非常方便。查看帮助直接输入help。

Windows下客户端的连接:

因为windows自带的webclient功能有点怪异,我个人推荐使用total commander下的webdav插件来管理,这个管理起来有点像ftp客户端,非常好用。Windows vista及以上的较新的系统,如果你的webdav不启用ssl,默认是拒绝连接的,需要改下注册表。更改HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\WebClient\Parameters\BasicAuthLevel 的值为2,重启系统,这时候一般就能连接不加密的webdav地址了。

不过,如果你涉及的资料涉密,博主个人还是推荐启用ssl加密链接,防止被网络窃听。

 

CentOS7下安装Apache WebDAV教程
Tagged on:         

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注