2014-06-18 113 views
0

我在图像服务器(maptile.org)上创建了一个.htaccess文件。已启用.htaccess中的跨源资源共享不起作用

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

我能使用a2enmod headers 我测试了一下它与apachectl -M启用MOD-header和它上市headers_module (shared)

这个建议在这个问题: Header set Access-Control-Allow-Origin in .htaccess doesn't work

然而,当我尝试保存作为图像的地图(使用html2canvas)它给我在控制台中的错误 http://www.justicemap.org/?id=63

错误:当图像存储在justicemap.org域

Image from origin ' http://maptile.org ' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' http://www.justicemap.org ' is therefore not allowed access.

另存为图片功能工作。

当我使用html2canvas时,请求方法是“GET”,响应状态码是“200”,并且mimeType是“image/png”。我没有看到Access-Control-Allow-Origin标题。

我是否需要添加Origin标头?我在Chrome Javascript控制台中查看请求时看不到一个。

+0

我使用的CloudFlare的DNS。这会影响到这一点吗?此链接表示Cloudflare支持CORS:https://support.cloudflare.com/hc/en-us/articles/200308847-Does-CloudFlare-support-Cross-origin-resource-sharing-CORS- –

回答

0

原来我没有运行Apache。我正在使用Lighttpd。我没有意识到这一点,因为Cloudflare将服务器头替换为:Server:cloudflare-nginx

我能够配置Lighttpd使用this recommendation工作。

0

我有同样的问题,并通过设置crossOrigin选项解决了null,像这样:

layers: [ 
    new ol.layer.Tile({ 
    source: new ol.source.OSM({ 
     url: 'http://tile-server-ip/osm/{z}/{x}/{y}.png', 
     crossOrigin: null 
    }) 
    }) 
], 
相关问题