Apacheエラー「Invalid command ‘RequestHeader’」の原因と対処法
Apacheで「Invalid command ‘RequestHeader’, perhaps misspelled or defined by a module not included in the server configuration」が発生した場合の原因と対処法を解説します。mod_headersの有効化、設定確認、Apache再起動手順まで紹介します。
環境
- OS Ubuntu 20.10
エラー全文
RequestHeader使用時に発生
systemctl status apache2.service
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2021-02-28 10:55:01 JST; 9s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 1329803 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
2月 28 10:55:01 mebee-VirtualBox systemd[1]: Starting The Apache HTTP Server...
2月 28 10:55:01 mebee-VirtualBox apachectl[1329806]: AH00526: Syntax error on line 2 of /etc/apache2/conf-enabled/dotnet.conf:
2月 28 10:55:01 mebee-VirtualBox apachectl[1329806]: Invalid command 'RequestHeader', perhaps misspelled or defined by a module not included in the server configuration
2月 28 10:55:01 mebee-VirtualBox apachectl[1329803]: Action 'start' failed.
2月 28 10:55:01 mebee-VirtualBox apachectl[1329803]: The Apache error log may have more information.
2月 28 10:55:01 mebee-VirtualBox systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
2月 28 10:55:01 mebee-VirtualBox systemd[1]: apache2.service: Failed with result 'exit-code'.
2月 28 10:55:01 mebee-VirtualBox systemd[1]: Failed to start The Apache HTTP Server.原因
Ubuntuでは、デフォルトでApacheのRequestHeaderは無効になっている。
対処法
mod_headersを有効して再起動を行う
sudo a2enmod headers再起動
systemctl restart apache2
CentOS・RHEL系で確認する
CentOSやRHEL系では、mod_headersが読み込まれているか確認します。
httpd -M | grep headers以下のように表示されれば有効です。
headers_module (shared)表示されない場合は、Apache設定ファイルで以下の行がコメントアウトされていないか確認します。
LoadModule headers_module modules/mod_headers.so設定ファイルの構文チェック
Apacheを再起動する前に、設定ファイルに問題がないか確認しておくと安全です。
sudo apachectl configtestまたはCentOS系では以下を使用します。
sudo httpd -tApacheを再起動して反映する
モジュールを有効化したら、Apacheを再起動して設定を反映します。
sudo systemctl restart httpdUbuntu系の場合は以下です。
sudo systemctl restart apache2
参考リンク
-
前の記事
Nuxt.js ライブラリ「@chenfengyuan/vue-barcode」を使用してバーコードを作成する 2021.02.17
-
次の記事
javascript appendで最後の子ノードにノードを追加する 2021.02.18
コメントを書く