This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

OSM Tile Server: how to enable CORS?

2

I've set up an OSM Tile Server, as described here.

The server is up and running, and I'm able to open the default map page in the browser (http://tile-server-ip/osm/slippymap.html) and see the map.

However, when I try to pull map data from Tile Server on a page from another site using OpenLayers library, I get:

Image from origin 'http://tile-server-ip' 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://my-other-site' is therefore not allowed access.

So, I need to enable CORS on Tile Server.

I tried adding CORS to Apache configuration (/etc/apache2/sites-enabled/tileserver_site.conf):

Header set Access-Control-Allow-Origin "*"

, but that has no effect. I tried modifying /etc/renderd.conf and adding:

CORS=*

to [default] section, but that, again, has no effect.

So, the question is: how to enable CORS on Tile Server?

asked 04 Nov '14, 12:53

weekens's gravatar image

weekens
101126
accept rate: 0%

edited 04 Nov '14, 13:42

aseerel4c26's gravatar image

aseerel4c26 ♦
32.6k18248554


2 Answers:

4

The problem was actually solved by providing crossOrigin: null to OpenLayers OSM source:

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

answered 04 Nov '14, 13:38

weekens's gravatar image

weekens
101126
accept rate: 0%

0

I have the same problem. Solved in this way: Add Header set Access-Control-Allow-Origin "*" In /etc/apache2/conf-available/security.conf

and change the server name in tileservice_site.con ServerName map.MYSERVER.it ServerAlias a.map.MYSERVER.it b.map.MYSERVER.it c.map.MYSERVER.it

Hope this help...

answered 12 Sep '15, 16:36

maurisor's gravatar image

maurisor
1
accept rate: 0%

Source code available on GitHub .