Apache エラー「Invalid command ‘RequestHeader’, perhaps misspelled or defined by a module not included in the server configuration」が発生した場合の対処法

Apache エラー「Invalid command ‘RequestHeader’, perhaps misspelled or defined by a module not included in the server configuration」が発生した場合の対処法

Apacheでエラー「Invalid command ‘RequestHeader’, perhaps misspelled or defined by a module not included in the server configuration」が発生した場合の対処法を記述してます。

環境

  • 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