我应该在我的 apache2 服务器中的什么地方设置 'Header set Access-Control-Allow-Origin "*"' Header?
Where should I set 'Header set Access-Control-Allow-Origin "*"' Header in my apache2 server?
我想从我的服务器访问其他服务器。
当我尝试向 www.posttestserver.com 发送 GET/POST 请求时,它已成功建立。
作为响应,该服务器向我提供响应 header 为:
Access-Control-Allow-Origin:*
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:129
Content-Type:text/html; charset=UTF-8
Date:Tue, 13 Jun 2017 07:24:27 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.4.18 (Ubuntu)
Vary:Accept-Encoding
那么,如何设置同类型的 header:
Access-Control-Allow-Origin:*
通过我的服务器,以便访问我的服务器的其他网站在他们的响应中收到此 headers?
我的服务器是在 ubuntu 16.04.
上托管的 apache2
注意:
我已经设置了这个 header:
Header set Access-Control-Allow-Origin "*"
in /etc/apache2/apache2.conf 部分,
并在 /var/www/html.
中的 .htaccess 文件中
由于您使用的是 ubuntu,最好在 /etc/apache2/conf-available/ 中创建一个简短的配置文件,然后使用 a2enconf 启用它。
这使您可以不修改随附的配置文件。
我想从我的服务器访问其他服务器。
当我尝试向 www.posttestserver.com 发送 GET/POST 请求时,它已成功建立。
作为响应,该服务器向我提供响应 header 为:
Access-Control-Allow-Origin:*
Connection:Keep-Alive
Content-Encoding:gzip
Content-Length:129
Content-Type:text/html; charset=UTF-8
Date:Tue, 13 Jun 2017 07:24:27 GMT
Keep-Alive:timeout=5, max=100
Server:Apache/2.4.18 (Ubuntu)
Vary:Accept-Encoding
那么,如何设置同类型的 header:
Access-Control-Allow-Origin:*
通过我的服务器,以便访问我的服务器的其他网站在他们的响应中收到此 headers?
我的服务器是在 ubuntu 16.04.
上托管的 apache2注意: 我已经设置了这个 header:
Header set Access-Control-Allow-Origin "*"
in /etc/apache2/apache2.conf 部分,
并在 /var/www/html.
由于您使用的是 ubuntu,最好在 /etc/apache2/conf-available/ 中创建一个简短的配置文件,然后使用 a2enconf 启用它。
这使您可以不修改随附的配置文件。