Log in

No account? Create an account

Previous Entry Share Next Entry
С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",