N
N
nApoBo32020-01-15 20:27:48
Nginx
nApoBo3, 2020-01-15 20:27:48

Nginx as a proxy for OSM does not save tiles, how to fix it?

nginx is configured to proxy requests to openstreetmap servers.
config below

proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=osm_cache:100m max_size=2g inactive=100d use_temp_path=off;
         		
  upstream openstreetmap_backend {
    server  a.tile.openstreetmap.org;
    server  b.tile.openstreetmap.org;
    server  c.tile.openstreetmap.org;
  }
  
    server {
  ....		
        
    location /osm/ {			
      access_log  /var/log/nginx/access_osm.log;						
      proxy_cache       osm_cache;
      proxy_cache_use_stale error timeout http_500 http_502 http_503 http_504 http_429;
      proxy_cache_background_update on;
      proxy_cache_lock on;			
      proxy_ignore_headers Expires Cache-Control;
      proxy_cache_valid 200 302 20d;						
      proxy_cache_valid any 5m;
      proxy_cache_key "$request_uri";
      proxy_pass http://openstreetmap_backend/;
    }

All requests for png files with upstream go with the status [Cache:MISS]
[Cache:MISS] .... "GET /osm/15/19138/9533.png
In this case, errors are cached, i.e. if you make an incorrect request and get from upstream http_429, then it will be cached and will be [Cache:HIT]
How to fix the config for correct png caching?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nApoBo3, 2020-01-29
@nApoBo3

Two lines were missing.
Nginx does not cache data that has a set-cookie header.
proxy_hide_header Set-Cookie;
proxy_ignore_headers Set-Cookie;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question