WordPress のサイトヘルスに表示される「Authorization ヘッダーがありません」を解消する方法

WordPress のサイトヘルスに Authorization ヘッダーがありません というメッセージが表示されていることに気付いた。

原因と対応

【WordPress】「Authorizationヘッダーがありません」に関する対処方法 | ブログBOX」の情報によれば、件のメッセージは CGI 版の PHP を使用している環境で表示される模様。

件のメッセージが表示されている環境を確認すると、案の定、 CGI 版の PHP (7.4) が使用されていた。さっそく、レンタルサーバーのコントロールパネルから、使用する PHP をモジュール版の PHP (8.1) に変更したところ、件のメッセージは表示されなくなった。

PHP のバージョンが 7.4 から 8.1 に上がっているのは、レンタルサーバー上で PHP のモジュール版は 8.1 しか選択できなかったため。モジュール版の 7.4 で何かしらのトラブルが発生した等ではない。

余談 : Authorization ヘッダーとは?

Authorization – HTTP | MDN」によると、

HTTP の Authorization リクエストヘッダーは、ユーザーエージェントがサーバーから認証を受けるための証明書を保持し、ふつうは、必ずではありませんが、サーバーが 401 Unauthorized ステータスと WWW-Authenticate ヘッダーを返した後に使われます。

とのことだが、いまいちピンとこなかったので、原文をあたってみたところ、

The HTTP Authorization request header can be used to provide credentials that authenticate a user agent with a server, allowing access to a protected resource.

The Authorization header is usually, but not always, sent after the user agent first attempts to request a protected resource without credentials. The server responds with a 401 Unauthorized message that includes at least one WWW-Authenticate header. This header indicates what authentication schemes can be used to access the resource (and any additional information needed by the client to use them). The user-agent should select the most secure authentication scheme that it supports from those offered, prompt the user for their credentials, and then re-request the resource (including the encoded credentials in the Authorization header).

つまり、

  1. クライアントがサーバー上の認証の必要なリソースにアクセスしようとする。
  2. サーバーからクライアントへ向けて、「認証が必要だけど認証されていないよ (401 Unauthorized ステータス)」「リソースにアクセスするための認証の種類や情報はこれだよ (WWW-Authenticate ヘッダー)」が送出される。
  3. クライアントからサーバーへ向けて、「使用する認証の種類やユーザーの認証情報はこれだよ (Authorization ヘッダー)」を送出する。
  4. 認証結果に応じてリソースへのアクセスが許可または拒否される。

という流れになるということか。

タイトルとURLをコピーしました