Advertisement
Guest User

OpenStreetMaps tiles caching with nginx

a guest
Jul 14th, 2018
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nginx 1.01 KB | None | 0 0
  1. proxy_cache_path /var/www/cache levels=1:2 keys_zone=tiles:8m max_size=1G;
  2. proxy_temp_path   /var/www/cache/tmp;
  3.  
  4. upstream openstreetmap_backend {
  5.   server  a.tile.openstreetmap.org;
  6.   server  b.tile.openstreetmap.org;
  7.   server  c.tile.openstreetmap.org;
  8. }
  9.  
  10. server {
  11.  
  12.  #... other config
  13.  
  14.  
  15.  # Use tiles pattern URL '/tiles/{z}/{x}/{y}.png' (relative)
  16.  
  17.  location /tiles/ {
  18.       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  19.       proxy_set_header X_FORWARDED_PROTO http;
  20.       proxy_set_header Host $http_host;
  21.       proxy_cache tiles;
  22.       proxy_cache_valid  200 302  30d;
  23.       proxy_cache_valid  404      1m;
  24.       proxy_cache_key "$request_uri";
  25.       proxy_redirect off;
  26.       proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504;
  27.       add_header X-Cache-Status $upstream_cache_status;
  28.  
  29.       expires 7d;
  30.       add_header Cache-Control public;
  31.       add_header Last-Modified "";
  32.       add_header ETag "";
  33.  
  34.       proxy_pass http://openstreetmap_backend/;
  35.   }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement