Skip to content

Instantly share code, notes, and snippets.

@davidbgk davidbgk/nginx.conf
Created May 3, 2018

Embed
What would you like to do?
nginx conf to proxy carto tiles
proxy_cache_path /srv/user/cache levels=1:2 keys_zone=tiles-cache:8m max_size=500000m inactive=1000d;
proxy_temp_path /srv/user/cache/tmp;
upstream openaip_backend {
server 1.tile.maps.openaip.net;
server 2.tile.maps.openaip.net;
server 3.tile.maps.openaip.net;
}
upstream cartodb_backend {
server cartodb-basemaps-a.global.ssl.fastly.net;
server cartodb-basemaps-b.global.ssl.fastly.net;
server cartodb-basemaps-c.global.ssl.fastly.net;
}
server {
server_name domain.fr;
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_certificate /etc/letsencrypt/live/domain.fr/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.fr/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/domain.fr/fullchain.pem;
include /etc/nginx/snippets/ssl.conf;
charset utf-8;
client_max_body_size 25M;
include /etc/nginx/snippets/letsencrypt.conf;
location ~ ^/tiles/openaip/(?<tile_path>.*)$ {
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 tiles-cache;
expires 3d;
proxy_cache_valid 200 302 3d;
proxy_cache_valid 404 1m;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://openaip_backend/geowebcache/service/tms/1.0.0/openaip_basemap@EPSG:900913@png/$tile_path;
break;
}
}
location ~ ^/tiles/cartodb/(?<tile_path>.*)$ {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X_FORWARDED_PROTO http;
# Not using $http_host otherwise this error is returned:
# Fastly error: unknown domain: domain.fr.
# Please check that this domain has been added to a service.
proxy_set_header Host cartodb-basemaps-a.global.ssl.fastly.net;
proxy_cache tiles-cache;
expires 3d;
proxy_cache_valid 200 302 3d;
proxy_cache_valid 404 1m;
proxy_redirect off;
if (!-f $request_filename) {
proxy_pass http://cartodb_backend/$tile_path;
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.