在我的 httpd.conf 中的什么地方添加 "Header set Access-Control-Allow-Origin "*" "?

Where to add "Header set Access-Control-Allow-Origin "*" " inside my httpd.conf?

所以我读到这里: https://httpd.apache.org/docs/current/howto/htaccess.html

我应该避免使用 .htaccess 文件,因为它们会降低性能。 因为到目前为止我还没有让它与 .htaccess 文件一起工作 (How to enable CORS from .htaccess (inside ZURB Foundation Project))

我试试看,写进我的httpd.conf

现在我在这里读到了以下内容: https://www.w3.org/wiki/CORS_Enabled

“要公开 header,您可以在 <Directory><Location><Files> 部分或 .htaccess 文件中添加以下行。

 <IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
 </IfModule>"

但我无法理解这到底是什么意思^^ 我确实在我的 httpd.conf 中找到了以下 "section"(如果那是他们所指的),它看起来像这样:

 <Directory />
    AllowOverride none
    Require all denied
</Directory>

我还可以找到一个文件部分:

<Files ".ht*">
    Require all denied
</Files>

但是我找不到位置部分,这让我想知道我是否真的在正确的地方寻找,以及将上面引用的 wiki 代码放入目录和文件中是否正确部分?

如今,您通常会在定义 ServerName 的 apache 配置文件(即所谓的 vhost 文件)中执行此操作。例如。使用 ubuntu,您会在 /etc/apache2/sites-enabled/ 中找到该文件。通常此文件将包含以下指令:

ServerName your-domain.example.com
DocumentRoot /var/www/html/your-website 
<Directory /var/www/html/your-website/>
    ....
</Directory>

只需将 cors 片段放在 Directory 指令中路径与 DocumentRoot 相匹配的地方。重新启动 apache2,它应该可以工作。