这不是用于 Web 服务器;我只想设置一些简单的东西,以便我可以通过 HTTP PUT 上传文件。我不是 Apache 专家,可能有些东西我明显遗漏了。
编辑:
DavLockDB "/var/DavLock/DavLock"
<Directory "/var/www/html">
Options Indexes FollowSymLinks
AllowOverride AuthConfig Limit
Dav On
AuthType Basic
AuthName "DAV"
AuthBasicProvider file
AuthUserFile /var/www/passwd/passwords
<Limit GET HEAD POST PUT DELETE OPTIONS>
Require user test
</Limit>
</Directory>
首先使用错误密码进行测试,以确认身份验证有效。
$ curl --include --upload-file ./uploadTest.txt http://test:bad@*.*.*.*/
HTTP/1.1 401 Unauthorized
Date: Tue, 28 May 2019 17:13:52 GMT
Server: Apache/2.4.6 (CentOS)
WWW-Authenticate: Basic realm="DAV"
Content-Length: 381
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>
现在正确的密码是:
$ curl --include --upload-file ./uploadTest.txt http://test:test@*.*.*.*/
HTTP/1.1 403 Forbidden
Date: Tue, 28 May 2019 17:00:53 GMT
Server: Apache/2.4.6 (CentOS)
Content-Length: 216
Connection: close
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /uploadTest.txt
on this server.</p>
</body></html>
大概设置“chmod 777 /var/www/html”还不够?(这只是一个 QA 项目的单元测试工具,而不是真正的服务器,所以我并不担心不良做法。)