CentOS Apache WebDAV无法上传文件问题解决办法
在CentOS上搭建好WebDAV服务后在使用中发现,MacOS使用Finder连接服务挂载后,可以正常浏览下载文件,但无法上传文件。新建一个测试文件testfile.txt,使用curl进行PUT方法上传,返回代码500 Internal Server Error。
$ curl --user "name:password" -X PUT 'http://XXX.XXX.XXX.XXX/webdav/testfile.txt' testfile.txt
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or misconfiguration and was unable to complete your request.</p>
<p>Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred,
and the actions you performed just before this error.</p>
<p>More information about this error may be available in the server error log.</p>
</body></html>
curl: (3) URL using bad/illegal format or missing URL
查看WebDAV的ErrorLog文件,我的文件目录为/var/log/httpd/error.log,错误内容是:
[Wed Oct 26 23:56:14.200194 2022] [dav:error] [pid 28679] [client XXX.XX.XX.XXX:XXXXX] The locks could not be queried for verification against a possible "If:" header. [500, #0]
[Wed Oct 26 23:56:14.200242 2022] [dav:error] [pid 28679] [client XXX.XX.XX.XXX:XXXXX] Could not open the lock database. [500, #400]
[Wed Oct 26 23:56:14.200247 2022] [dav:error] [pid 28679] (13)Permission denied: [client XXX.XX.XX.XXX:XXXXX] Could not open property database. [500, #1]
如果你遇到如上问题,需要在WebDAV的配置文件,webdav.conf中查找DavLockDB,查看其所指向的文件目录,我的文件目录位置是 /var/www/html/DavLock。所以我在/var/www/html创建了一个名为DavLock的文件,并将其所有用户和用户组改为httpd.conf中设置的User和Group,我的用户和用户组是apache:apache;并将文件权限改为666。
$ touch /var/www/html/DavLock
$ chown apache:apache /var/www/html/DavLock
$ chmod 0666 /var/www/html/DavLock
创建并更改完成后,文件权限应该入下所示。
$ ll /var/www/html/DavLock
-rw-rw-rw- 1 apache apache 0 10月 26 23:41 DavLock
之后重启httpd服务后,Finder可以正常上传文件了,curl进行PUT方法上传也返回正常代码201 Created了。
$ systemctl restart httpd
$ curl --user "name:password" -X PUT 'http://XXX.XXX.XXX.XXX/webdav/testfile.txt' testfile.txt
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>201 Created</title>
</head><body>
<h1>Created</h1>
<p>Resource /webdav-public/testfile.txt has been created.</p>
</body></html>
curl: (3) URL using bad/illegal format or missing URL