Lonely Dreamer (sanmai) wrote,
Lonely Dreamer
sanmai

Сaching tiles for OpenStreetMap with nginx

proxy_cache_path /var/cache/tiles levels=1:2:2 keys_zone=tiles:32m max_size=20G;

upstream openstreetmap {
    server   a.tile.openstreetmap.org;
    server   b.tile.openstreetmap.org;
    server   c.tile.openstreetmap.org;
}

server {
    server_name tiles.example.org;
    listen tiles.example.org:80;

    location ~* \.png {
        expires     7d;
        proxy_pass http://openstreetmap;
        proxy_cache       tiles;
        proxy_cache_valid  200 302  7d;
        proxy_cache_valid  404      1m;
        proxy_cache_key "$request_uri";
    }
}
Additionally, you may need to:
# mkdir /var/cache/tiles
# chown www-data /var/cache/tiles
When using OpenLayers, change definition of the layer to:
new OpenLayers.Layer.OSM("OpenStreetMap/nginx",
	"http://tiles.example.org/${z}/${x}/${y}.png");
Tags: linux, nginx, useful
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments