nginx, added timeout to requests

This commit is contained in:
Zsolt Ero
2024-01-08 19:16:32 +01:00
parent 44359c8ca9
commit a011f9c803
5 changed files with 29 additions and 9 deletions

View File

@@ -48,7 +48,7 @@ def download_tileset(area: str, version: str, list_versions: bool, runs_dir: Pat
if area not in {'planet', 'monaco'}: if area not in {'planet', 'monaco'}:
sys.exit(' please specify area: "planet" or "monaco"') sys.exit(' please specify area: "planet" or "monaco"')
r = requests.get(f'https://{area}.openfreemap.com/dirs.txt') r = requests.get(f'https://{area}.openfreemap.com/dirs.txt', timeout=30)
r.raise_for_status() r.raise_for_status()
versions = sorted(r.text.splitlines()) versions = sorted(r.text.splitlines())

View File

@@ -71,19 +71,21 @@ def create_version_location(area: str, version: str, subdir: Path) -> str:
alias {tilejson_path}; # no trailing slash alias {tilejson_path}; # no trailing slash
default_type application/json; default_type application/json;
expires 1d; # TODO target 1w
add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Origin' '*' always;
add_header Cache-Control public; add_header Cache-Control public;
expires 1d; # TODO target 1w
}} }}
location /{area}/{version}/ {{ # trailing slash location /{area}/{version}/ {{ # trailing slash
alias {subdir}/tiles/; # trailing slash alias {subdir}/tiles/; # trailing slash
try_files $uri @empty; try_files $uri @empty;
add_header Content-Encoding gzip; add_header Content-Encoding gzip;
expires 1d; # TODO target 10y
add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Origin' '*' always;
add_header Cache-Control public; add_header Cache-Control public;
expires 1d; # TODO target 10y
}} }}
""" """
@@ -107,9 +109,10 @@ def create_latest_locations() -> str:
alias {tilejson_path}; # no trailing slash alias {tilejson_path}; # no trailing slash
default_type application/json; default_type application/json;
expires 1d;
add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Origin' '*' always;
add_header Cache-Control public; add_header Cache-Control public;
expires 1d;
}} }}
""" """

View File

@@ -9,7 +9,7 @@ def set_tileset_versions():
need_nginx_sync = False need_nginx_sync = False
for area in ['planet', 'monaco']: for area in ['planet', 'monaco']:
r = requests.get(f'https://assets.openfreemap.com/versions/deployed_{area}.txt') r = requests.get(f'https://assets.openfreemap.com/versions/deployed_{area}.txt', timeout=30)
r.raise_for_status() r.raise_for_status()
remote_version = r.text.strip() remote_version = r.text.strip()
print(f' remote version for {area}: {remote_version}') print(f' remote version for {area}: {remote_version}')

View File

@@ -27,13 +27,27 @@ server {
location /fonts/ { location /fonts/ {
# trailing slash # trailing slash
alias /data/ofm/http_host/assets/fonts/; # trailing slash alias /data/ofm/http_host/assets/fonts/; # trailing slash
try_files $uri =404; try_files $uri =404;
default_type application/x-protobuf; default_type application/x-protobuf;
expires 1d; # target 1w
add_header 'Access-Control-Allow-Origin' '*' always;
add_header Cache-Control public;
}
location /ne/ {
# trailing slash
alias /data/ofm/http_host/assets/natural_earth/tiles; # trailing slash
try_files $uri =404;
expires 1d; # target 10y
add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Origin' '*' always;
add_header Cache-Control public; add_header Cache-Control public;
expires 1d; # target 1w
} }
# we need to handle missing tiles as valid request returning empty string # we need to handle missing tiles as valid request returning empty string
@@ -41,9 +55,10 @@ server {
default_type application/vnd.mapbox-vector-tile; default_type application/vnd.mapbox-vector-tile;
return 200 ''; return 200 '';
expires 10y;
add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Origin' '*' always;
add_header Cache-Control public; add_header Cache-Control public;
expires 10y;
} }
location = / { location = / {
@@ -53,5 +68,7 @@ server {
# catch-all block to deny all other requests # catch-all block to deny all other requests
location / { location / {
deny all; deny all;
error_log /data/ofm/http_host/logs_nginx/tiles-org-error.log error;
} }
} }

View File

@@ -33,7 +33,7 @@ def download_if_size_differs(url: str, local_file: Path) -> bool:
def get_remote_file_size(url: str) -> int | None: def get_remote_file_size(url: str) -> int | None:
r = requests.head(url) r = requests.head(url, timeout=30)
size = r.headers.get('Content-Length') size = r.headers.get('Content-Length')
return int(size) if size else None return int(size) if size else None