为什么我的 Apache2 .htaccess 文件 CORS header 导致 500 内部服务器错误?

Why is my Apache2 .htaccess file CORS header causing a 500 internal server error?

我正在尝试启用对 Apache2 Web 服务器上目录的 CORS 访问。我启用了 .htaccess 文件并添加了一行,旨在启用对目录的 CORS 访问。

Header set Access-Control-Allow-Origin: "*"

使用该行保存 .htaccess 文件后,我在尝试访问目录时收到 500 内部服务器错误 (http://williamgreen.hopto.org/audio/)。

有什么想法吗?我的 header 不正确吗? 谢谢。

Apache2 error.log:

[Thu Mar 09 15:02:15.118686 2017] [mpm_event:notice] [pid 2668:tid 547718139904] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations
[Thu Mar 09 15:02:15.119080 2017] [core:notice] [pid 2668:tid 547718139904] AH00094: Command line: '/usr/sbin/apache2'
[Thu Mar 09 19:27:09.148771 2017] [mpm_event:notice] [pid 2668:tid 547718139904] AH00491: caught SIGTERM, shutting down
[Thu Mar 09 19:27:10.339942 2017] [mpm_event:notice] [pid 14385:tid 548172222464] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations
[Thu Mar 09 19:27:10.340300 2017] [core:notice] [pid 14385:tid 548172222464] AH00094: Command line: '/usr/sbin/apache2'
[Thu Mar 09 19:39:47.583449 2017] [mpm_event:notice] [pid 14385:tid 548172222464] AH00491: caught SIGTERM, shutting down
[Thu Mar 09 19:39:47.776394 2017] [mpm_event:notice] [pid 14915:tid 548543827968] AH00489: Apache/2.4.18 (Ubuntu) configured -- resuming normal operations
[Thu Mar 09 19:39:47.776776 2017] [core:notice] [pid 14915:tid 548543827968] AH00094: Command line: '/usr/sbin/apache2'
[Thu Mar 09 19:39:51.201462 2017] [core:alert] [pid 14919:tid 548512096688] [client 73.15.129.28:57278] /var/www/html/audio/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration, referer: http://williamgreen.hopto.org/audio/Music/
[Thu Mar 09 19:39:51.204818 2017] [core:alert] [pid 14918:tid 548528873904] [client 73.15.129.28:57280] /var/www/html/audio/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration, referer: http://williamgreen.hopto.org/audio/Music/
[Thu Mar 09 19:39:55.389791 2017] [core:alert] [pid 14918:tid 548520485296] [client 73.15.129.28:57279] /var/www/html/audio/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
[Thu Mar 09 19:40:02.264113 2017] [core:alert] [pid 14918:tid 548512096688] [client 73.15.129.28:57283] /var/www/html/audio/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
[Thu Mar 09 19:40:03.735693 2017] [core:alert] [pid 14919:tid 548503708080] [client 73.15.129.28:57284] /var/www/html/audio/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
[Thu Mar 09 19:40:04.183378 2017] [core:alert] [pid 14918:tid 548503708080] [client 73.15.129.28:57285] /var/www/html/audio/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
[Thu Mar 09 19:40:04.527274 2017] [core:alert] [pid 14919:tid 548520485296] [client 73.15.129.28:57286] /var/www/html/audio/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
[Thu Mar 09 19:40:04.846900 2017] [core:alert] [pid 14919:tid 548495319472] [client 73.15.129.28:57287] /var/www/html/audio/.htaccess: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration

您没有安装 headers 模块。 使用 apache2,只需 运行 a2enmod headers 然后 sudo service apache2 restart 它会自动安装 headers 模块。