gpt4 book ai didi

apache2 mod_headers 不工作

转载 作者:行者123 更新时间:2023-12-03 04:35:27 25 4
gpt4 key购买 nike

问题描述:我想设置我的网站“Access-Control-Allow-Origin”,所以我在apache的配置中设置它(几乎在任何地方),但它不起作用。我还设置了其他 header 进行测试,但仍然不起作用。

Apache 版本:2.2.22

Apache 模块: http://www.anwcl.com/test/show_modules.php

我的目标网址:

http://www.anwcl.com/test/test_only_div.html

它链接到我的本地文件:

e:\wamp\www\test\test_only_div.html
<小时/>

这是我的 apache 的配置:

E:\wamp\bin\apache\apache2.2.22\conf\httpd.conf

...
LoadModule headers_module modules/mod_headers.so
...
Include conf/extra/httpd-vhosts.conf
...

E:\wamp\bin\apache\apache2.2.22\conf\extra\httpd-vhosts.conf

NameVirtualHost *:80
<VirtualHost *:80>
Header add Access-Control-Allow-Origin "*"
Header echo ^TS
Header add MyHeader "Hello Joe. It took %D microseconds for Apache to serve this request."
ServerAdmin xxx@gmail.com
DocumentRoot "E:/wamp/www/"
ServerName www.anwcl.com
ErrorLog "logs/xxx.log"
CustomLog "logs/xxx.log" common
<Directory "E:/wamp/www/">
Header add Access-Control-Allow-Origin "*"
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

E:\wamp\www\.htaccess

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"

E:\wamp\www\test\.htaccess

Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
<小时/>

这是 Wireshark 的上限,没有预期的 header :

http://www.anwcl.com/question/apache-mod-headers-not-working.jpg
http://www.anwcl.com/question/apache-mod-headers-not-working-304.jpg

最佳答案

当我意识到我在配置文件中修改了错误的虚拟主机时,我也遇到了这个问题并修复了它:/etc/apache2/sites-enabled/000-default.conf

当我使用具有不同端口的虚拟主机时,我正在修改默认的虚拟主机配置。

<VirtualHost *:6000>
Header set Access-Control-Allow-Origin "*"
</VirtualHost>

我还遇到了 Dylan Maxey 描述的错误,并通过禁用浏览器检查器中的缓存来解决该错误: Disabling cache in Chromium based browser这也是我发现有用的网站的链接: https://enable-cors.org/server_apache.html

关于apache2 mod_headers 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19341639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com