2

これは私のVirtualHost構成です:

<VirtualHost *:80>

     ServerName example.com
     DocumentRoot /var/www/example.com/public

     <Directory /var/www/example.com/public>
             Options +FollowSymLinks
             AllowOverride All
             Require user user1 user2
     </Directory>

     <Location /error/401>
             Require all granted
     </Location>

     ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
     LogLevel warn
     CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined

     ErrorDocument 500 /error/500
     ErrorDocument 404 /error/404
     ErrorDocument 401 /error/401

</VirtualHost>

それでも、意図的に認証に失敗した場合 (または /error/401 を直接開いた場合)、次のようになります。

Unauthorized

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.

Additionally, a 401 Unauthorized error was encountered while trying to use an ErrorDocument to handle the request.

私は何を間違っていますか?以下にリンクされているドキュメントによると、後でLocation処理する必要があるDirectoryため、これは機能するはずです。

http://httpd.apache.org/docs/current/sections.html#merging

編集:

明らかなように、これが問題の部分です。

Additionally, a 401 Unauthorized error was encountered while trying to use an ErrorDocument to handle the request.
4

1 に答える 1

1

私は非常によく似た問題に遭遇しました。実際の主な問題は、サイトの DocumentRoot レベルで認証に失敗すると、DocumentRoot の下にあるカスタム エラー ページ (つまり、/error/401) にアクセスできず、代わりにデフォルトの Apache エラー メッセージが発行されることです。

私が行った解決策は、html を ErrorDocument 401 ディレクティブに組み込むことでした。たとえば、

ErrorDocument 401 "INSERT MARKUP HERE"

(マークアップを引用符で囲むことが不可欠であることに注意してください)。

確かに、これは非常に回避策です。

于 2020-01-26T22:21:21.950 に答える