apache2 mod_标头不工作
问题描述:我想设置我的站点“Access Control Allow Origin”,所以我在apache的配置中设置了它(几乎在任何地方),但它不起作用。我还为测试设置了其他标题,但它仍然不起作用 Apache版本:2.2.22 Apache模块: 我的目标url:apache2 mod_标头不工作,apache,mod-headers,Apache,Mod Headers,问题描述:我想设置我的站点“Access Control Allow Origin”,所以我在apache的配置中设置了它(几乎在任何地方),但它不起作用。我还为测试设置了其他标题,但它仍然不起作用 Apache版本:2.2.22 Apache模块: 我的目标url: http://www.anwcl.com/test/test_only_div.html e:\wamp\www\test\test_only_div.html 并链接到我的本地文件: http://www.anwcl.com
http://www.anwcl.com/test/test_only_div.html
e:\wamp\www\test\test_only_div.html
并链接到我的本地文件:
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
...
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\bin\apache\apache2.2.22\conf\extra\httpd vhosts.conf
...
LoadModule headers_module modules/mod_headers.so
...
Include 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\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"
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的封盖,没有预期的标题:
检查
php_info()
的输出,查看是否从apache Web服务器加载了mod_头。更改可能已经发生,而您在浏览器中看不到更改。如果您正在为静态文件(如试图更改其标题的图像)提供服务,这一点尤其典型
您甚至可以在打开Javascript控制台查看页面时禁用chrome缓存,但仍然无法看到更改生效
您要查找的是响应代码。如果是304,则服务器已识别您的浏览器已具有请求文件的有效表示形式,并将为该文件提供服务。如果是,您将看不到浏览器最初下载该页面后添加的标题
若要查看是否存在这种情况,请将url更改为
http://myexample.com/myimage.jpg?t=1
,或者任何其他随机查询参数,看看是否有效。我也遇到了这个问题,当我意识到我在这里找到的配置文件中修改了错误的虚拟主机时,我修复了它:/etc/apache2/sites enabled/000 default.conf
我在修改默认的VirtualHost配置时使用了一个具有不同端口的配置
<VirtualHost *:6000>
Header set Access-Control-Allow-Origin "*"
</VirtualHost>
标题集访问控制允许原点“*”
我还遇到了Dylan Maxey所描述的错误,并通过在浏览器检查器中禁用缓存来解决:
这里还有一个链接,指向我认为有用的网站:
对于我的案例,添加
标题集“key”“value”
无效。我必须使用RequestHeader set“key”value
作为ProxyPass
发送头
<VirtualHost *:443>
ServerName myserver.com
ServerAlias www.myserver.com
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / http://127.0.0.1:8081/
ProxyPassReverse / http://127.0.0.1:8081/
RequestHeader set "X-Forwarded-Proto" "https"
#
# Setup SSL
#
# SSLProxyEngine on
SSLEngine on
SSLCertificateFile location-to-certificate.crt
SSLCertificateKeyFile location-to-private.key
SSLCertificateChainFile location-to-ca_bundle.crt
</VirtualHost>
ServerName myserver.com
ServerAlias www.myserver.com
代理请求关闭
代理主机
ProxyPass/http://127.0.0.1:8081/
ProxyPassReverse/http://127.0.0.1:8081/
RequestHeader设置“X-Forwarded-Proto”“https”
#
#设置SSL
#
#SSLProxyEngine打开
斯伦金安
SSLCertificateFile location-to-certificate.crt
SSLCertificateKeyFile location-to-private.key
SSLCertificateChainFile location-to-ca_bundle.crt
是的,它已加载。但问题中提到的实际标题仍然没有添加。