Cache

proxy_cache_path  /tmp/cache levels=1:2 keys_zone=openstreetmap-backend-cache:8$
proxy_temp_path   /tmp/cache/tmp;

upstream openstreetmap_backend {
  server  a.tile.openstreetmap.org;
  server  b.tile.openstreetmap.org;
  server  c.tile.openstreetmap.org;
}
##### openstreetmap ######################
    server_name data.example.com;
    location / {
    return 404;
    }
    location ~ \.(png)$ {
    proxy_cache_valid 200 301 302 31d;
    proxy_cache openstreetmap-backend-cache;
    proxy_cache_min_uses 1;
    proxy_cache_key "os-$request_uri";
    proxy_redirect off;
    proxy_pass  http://openstreetmap_backend;
    }
    location ^~ /.well-known/acme-challenge/ {
    root /storage/www;
    }
}
location /osm_proxy/ {
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X_FORWARDED_PROTO http;
  proxy_set_header Host $http_host;
  proxy_cache openstreetmap-backend-cache;
  proxy_cache_valid  200 302  365d;
  proxy_cache_valid  404      1m;
  proxy_redirect off;
  if (!-f $request_filename) {
    rewrite ^/osm_proxy(/.*)$ $1 break;
    proxy_pass http://openstreetmap_backend;
    break;
  }
}