![Apache がユーザー名とパスワードによる URL の認証を必要とするのはなぜですか?](https://rvso.com/image/726830/Apache%20%E3%81%8C%E3%83%A6%E3%83%BC%E3%82%B6%E3%83%BC%E5%90%8D%E3%81%A8%E3%83%91%E3%82%B9%E3%83%AF%E3%83%BC%E3%83%89%E3%81%AB%E3%82%88%E3%82%8B%20URL%20%E3%81%AE%E8%AA%8D%E8%A8%BC%E3%82%92%E5%BF%85%E8%A6%81%E3%81%A8%E3%81%99%E3%82%8B%E3%81%AE%E3%81%AF%E3%81%AA%E3%81%9C%E3%81%A7%E3%81%99%E3%81%8B%3F.png)
Apache で基本認証を構築します。1 行のみです/var/www/html/remote.html
。
<p>it is a test </p>
次に、curl を使用してユーザー名とパスワードを確認します。
curl -u xxxx:xxxx -v http://111.111.111.111/remote.html
* Trying 111.111.111.111...
* TCP_NODELAY set
* Connected to 111.111.111.111 (111.111.111.111) port 80 (#0)
* Server auth using Basic with user 'xxxx'
> GET /remote.html HTTP/1.1
> Host: 111.111.111.111
> Authorization: Basic dGVzdHBhc3M6MTIzNDU2Nzg=
> User-Agent: curl/7.52.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Fri, 07 Sep 2018 03:32:42 GMT
< Server: Apache/2.4.6 (CentOS)
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS
< Access-Control-Allow-Credentials: true
< Access-Control-Allow-Headers: Authorization,DNT,User-Agent,Keep-Alive,Content-Type,accept,origin,X-Requested-With
< Last-Modified: Fri, 07 Sep 2018 03:22:41 GMT
< ETag: "b2-5753f8537e26c"
< Accept-Ranges: bytes
< Content-Length: 178
< Content-Type: text/html; charset=UTF-8
<
<p>it is a test </p>
* Curl_http_done: called premature == 0
* Connection #0 to host 111.111.111.111 left intact
ブラウザに入力するとhttp://111.111.111.111/remote.html?username=xxxx&password=xxxx
、認証ウィンドウがポップアップ表示されます。
URL には curl によって検証された正しいユーザー名とパスワードが含まれていますが、remote.html を直接表示できないのはなぜですか?
URL がhttp://111.111.111.111/remote.html?username=xxxx&password=xxxx
Apache サーバーに認証情報を提供できないのはなぜですか?
答え1
基本認証のURLは
http://testpass:[email protected]/remote.html
答え2
HTTP Basic Auth認証情報は、特定のヘッダーでクライアントからサーバーに送信されます。ないURLにこのように追加されます。これを確認するには、
curl http://111.111.111.111/remote.html?username=xxxx&password=xxxx
また、動作しません --u
フラグはそれを別の方法で送信することを知っており、ブラウザもそうします提供されたフォームに認証情報を入力すると。
答え3
以下を使用してチェックしてくださいその他の回答そしてログインCLIの入力方法
curl --user user:pass http://myweb.com/hello.html