# Caching OSM tiles

**URL:** <https://www.ruby-forum.com/t/caching-osm-tiles/188392>\
**Category:** NGINX\
**Created:** [May 11, 2010, 8:38am UTC](https://www.ruby-forum.com/t/caching-osm-tiles/188392 "2010-05-11T08:38:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cedjo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7993a0/32.png) [@cedjo](https://www.ruby-forum.com/u/cedjo)\
**Post date:** [May 11, 2010, 8:38am UTC](https://www.ruby-forum.com/t/caching-osm-tiles/188392/1 "2010-05-11T08:38:39Z")

</div>

Hello!

I’m currently developping a really tiny app using OpenLayers[1] and  
OpenStreetMap[2].  
As I was testing it, I saw that sometimes tiles don’t come. I guess this  
is caused by server load at OSM. So I was thinking about caching some  
tiles so that it won’t overload OSM, and my app will work nicely.

Has anybody ever tried it ? if so, how can we do it ?  
If no one has tested/tried it, any hints/ideas ?

I guess I should configure a special vhost like “tiles.domain.ltd”,  
proxy-ing [tiles.openstreetmap.org](http://tiles.openstreetmap.org), with some caching, and tell  
OpenLayers to use OSM tiles through this proxy. Right ?

Thank you for your answers.

Best regards,

C. Jeanneret

[1] [http://openlayers.org/](http://openlayers.org/)  
[2] [http://www.openstreetmap.org/](http://www.openstreetmap.org/)

---

<div class="post-metadata">

**Author:** ![cedjo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7993a0/32.png) [@cedjo](https://www.ruby-forum.com/u/cedjo)\
**Post date:** [May 11, 2010, 9:35am UTC](https://www.ruby-forum.com/t/caching-osm-tiles/188392/2 "2010-05-11T09:35:26Z")

</div>

On Tue, May 11, 2010 at 08:37:19AM +0200, Cedric J. wrote:

> Hello!
> 
> I’m currently developping a really tiny app using OpenLayers[1] and OpenStreetMap[2].  
> As I was testing it, I saw that sometimes tiles don’t come. I guess this is caused by server load at OSM. So I was thinking about caching some tiles so that it won’t overload OSM, and my app will work nicely.
> 
> Has anybody ever tried it ? if so, how can we do it ?  
> If no one has tested/tried it, any hints/ideas ?
> 
> I guess I should configure a special vhost like “tiles.domain.ltd”, proxy-ing [tiles.openstreetmap.org](http://tiles.openstreetmap.org), with some caching, and tell OpenLayers to use OSM tiles through this proxy. Right ?

Yes.

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**

---

<div class="post-metadata">

**Author:** ![cedjo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7993a0/32.png) [@cedjo](https://www.ruby-forum.com/u/cedjo)\
**Post date:** [May 11, 2010, 12:21pm UTC](https://www.ruby-forum.com/t/caching-osm-tiles/188392/3 "2010-05-11T12:21:07Z")

</div>

On Tue, 11 May 2010 11:34:32 +0400  
Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > I guess I should configure a special vhost like “tiles.domain.ltd”, proxy-ing [tiles.openstreetmap.org](http://tiles.openstreetmap.org), with some caching, and tell OpenLayers to use OSM tiles through this proxy. Right ?
> 
> Yes.

Just for the posterity:

proxy\_cache\_path /home/tilecache levels=1:2:2  
keys\_zone=tilecache:1536m;

server {  
listen 94.23.198.39:80;  
server\_name tiles.domain.ltd;

access\_log /var/log/nginx/tiles\_access.log main;  
error\_log /var/log/nginx/tiles\_error.log info;  
location / {  
proxy\_pass [http://tile.openstreetmap.org/](http://tile.openstreetmap.org/) ;  
proxy\_cache tilecache;  
proxy\_cache\_key “$scheme$host$request\_uri”;  
proxy\_cache\_valid 200 302 300h;  
proxy\_cache\_valid 404 1m;  
}  
}

And I modified openlayers.js in this way :

- true,url:'[http://tile.openstreetmap.org/${z}/${x}/${y}](http://tile.openstreetmap.org/$%7Bz%7D/$%7Bx%7D/$%7By%7D)

- true,url:'[http://tiles.internux.ch/${z}/${x}/${y}](http://tiles.internux.ch/$%7Bz%7D/$%7Bx%7D/$%7By%7D)

It just works fine.

Beware of cache size - mine is a small one as I’m not coverring a big  
area.

Thanks again.

C.
