How to connect to locahost OpenStreetMap tiling server ? (Failed to obtain image tile ERROR)


Following guide at I was able to get my own OSM tile server running.
(Ubuntu linux 14.04, Apache 2.4.7, Cesium-1.6, node-v0.12.0, postgresql-9.3-postgis-2.1, osm2pgsql 0.87.2-dev, Mapnik 2.2.0)

I did have verify state of my OSM tile server by using webrowser. For example at http://localhost/osm_tiles/0/0/0.png I get small picture od world.
Evertthing seems to be working at server side to me.

Cesium connected to online source of maps works fine as well.

Problem pops up, when i try connect Cesium to local OSM server. In Firefox console I get this error:

“An error occurred in “”: Failed to obtain image tile X: 1 Y: 1 Level: 1.” Cesium.js:381:25514
“An error occurred in “”: Failed to obtain image tile X: 1 Y: 0 Level: 1.” Cesium.js:381:25514
“An error occurred in “”: Failed to obtain image tile X: 0 Y: 0 Level: 1.” Cesium.js:381:25514
“An error occurred in “”: Failed to obtain image tile X: 0 Y: 1 Level: 1.” Cesium.js:381:25514


I’m already stuck with this problem for quite a few days. Here is what I have tried and found out so far:

  • Analyse Apache logfiles.
    My DEFAULT_ERRORLOG is set to “logs/error_log”, but there is no such file on my system. With documentation on
    i was able locate /var/log/apache2/error.log file.

Per request a identical line pops up in there :

debug: init_storage_backend: initialising file storage backend at: /var/lib/mod_tile


I was not able to find any difference in logs on Apache side between request from Cesium and webrowser.

  • Setting Apache and Cesium to run on same port
    I was not able to achieve this. Cesium does not like that. Spits at me angrily this:

Error: Port 8080 is already in use, select a different port.
Example: node server.js --port 8081
{ [Error: listen EADDRINUSE] code: ‘EADDRINUSE’, errno: ‘EADDRINUSE’, syscall: ‘listen’ }


I achieved this by changing port numbers from 80 to 8080 in files /etc/apache2/ports.conf and /etc/apache2/sites-enabled/000-default.conf .

  • Set Cross Origin Resource Sharing (CORS) on Apache
    Maybe I screwed up somewhere in the proces. Here is what I did:

Enabled mod_headers in Apache by

a2enmod headers


Changing Apache configuration file */etc/apache2/apache.conf * by adding line

Header set Access-Control-Allow-Origin “*”


to existing sections , <Directory /var/www/> and creating own section <Directory /var/lib/mod_tile/> .

Did not forget obligatory reloading server by

sudo service apache2 reload


After that I have been left disappointed by result: Still getting the same error.

Pretty please: Do anyone have idea what am I doing wrong?

Here is sourcecode of webpage I’m running Cesium from:

<!DOCTYPE html>
<html lang="en">
<!-- Use correct character set. -->
<meta charset="utf-8">
<!-- Tell IE to use the latest, best version (or Chrome Frame if pre-IE11). -->
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<!-- Make the application on mobile take up the full browser screen and disable user scaling. -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<title>Hello World!</title>
<script src="../Build/Cesium/Cesium.js"></script>
  @import url(../Build/Cesium/Widgets/widgets.css);
  html, body, #cesiumContainer {
      width: 100%; height: 100%; margin: 0; padding: 0; overflow: hidden;
<div id="cesiumContainer"></div>

//Initialize the viewer widget with several custom options and mixins.
var viewer = new Cesium.Viewer('cesiumContainer', {
//Hide the base layer picker
baseLayerPicker : false,
//Use OpenStreetMaps
imageryProvider : new Cesium.OpenStreetMapImageryProvider({
    url : '[http://localhost/osm_tiles/](http://localhost/osm_tiles/)'
  //url : '//[]('

// Show Columbus View map with Web Mercator projection
//    mapProjection : new Cesium.WebMercatorProjection()

//Add basic drag and drop functionality

//Show a pop-up alert if we encounter an error when processing a dropped file
viewer.dropError.addEventListener(function(dropHandler, name, error) {


Check to make sure your CORS header is being properly set.

curl -v ‘http://localhost/osm_tiles/0/0/0.png’ -o /dev/null

You should see:

Access-Control-Allow-Origin: *

in the response headers.

curl -v ‘http://localhost/osm_tiles/0/0/0.png’ -o /dev/null

I don’t get line saying
Access-Control-Allow-Origin: *

here is What I get:

  • Hostname was NOT found in DNS cache
    % Total % Received % Xferd Average Speed Time Time Time Current
    Dload Upload Total Spent Left Speed
    0 0 0 0 0 0 0 0 --:–:-- --:–:-- --:–:-- 0* Trying…
  • Connected to localhost ( port 80 (#0)

GET /osm_tiles/0/0/0.png HTTP/1.1
User-Agent: curl/7.35.0
Host: localhost
Accept: /

< HTTP/1.1 200 OK
< Date: Fri, 13 Mar 2015 15:10:19 GMT

  • Server Apache/2.4.7 (Ubuntu) is not blacklisted
    < Server: Apache/2.4.7 (Ubuntu)
    < ETag: “337ab9a3fb2a307a148786460b7b973b”
    < Content-Length: 7898
    < Cache-Control: max-age=1258
    < Expires: Fri, 13 Mar 2015 15:31:17 GMT
    < Content-Type: image/png
    { [data not shown]
    100 7898 100 7898 0 0 1274k 0 --:–:-- --:–:-- --:–:-- 1542k
  • Connection #0 to host localhost left intact


in configuration file /usr/local/etc/renderd.conf
tiles location is set to:

Based on this I was thinking for this directory is needed to set CORS in Apache2.
So I added following lines to /etc/apache2/apache2.conf file :

<Directory /var/lib/mod_tile/>
#CORS settings: to allow Cesium get maptiles from mod_tile & renderd Apache plugins
Header set Access-Control-Allow-Origin “*”
Options Indexes FollowSymLinks
AllowOverride None
Require all granted