mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
nginx, added timeout to requests
This commit is contained in:
@@ -48,7 +48,7 @@ def download_tileset(area: str, version: str, list_versions: bool, runs_dir: Pat
|
||||
if area not in {'planet', '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()
|
||||
|
||||
versions = sorted(r.text.splitlines())
|
||||
|
||||
@@ -71,19 +71,21 @@ def create_version_location(area: str, version: str, subdir: Path) -> str:
|
||||
alias {tilejson_path}; # no trailing slash
|
||||
default_type application/json;
|
||||
|
||||
expires 1d; # TODO target 1w
|
||||
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header Cache-Control public;
|
||||
expires 1d; # TODO target 1w
|
||||
}}
|
||||
|
||||
location /{area}/{version}/ {{ # trailing slash
|
||||
alias {subdir}/tiles/; # trailing slash
|
||||
try_files $uri @empty;
|
||||
|
||||
add_header Content-Encoding gzip;
|
||||
|
||||
expires 1d; # TODO target 10y
|
||||
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
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
|
||||
default_type application/json;
|
||||
|
||||
expires 1d;
|
||||
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header Cache-Control public;
|
||||
expires 1d;
|
||||
}}
|
||||
"""
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ def set_tileset_versions():
|
||||
need_nginx_sync = False
|
||||
|
||||
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()
|
||||
remote_version = r.text.strip()
|
||||
print(f' remote version for {area}: {remote_version}')
|
||||
|
||||
@@ -27,13 +27,27 @@ server {
|
||||
|
||||
location /fonts/ {
|
||||
# trailing slash
|
||||
|
||||
alias /data/ofm/http_host/assets/fonts/; # trailing slash
|
||||
try_files $uri =404;
|
||||
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 Cache-Control public;
|
||||
expires 1d; # target 1w
|
||||
}
|
||||
|
||||
# we need to handle missing tiles as valid request returning empty string
|
||||
@@ -41,9 +55,10 @@ server {
|
||||
default_type application/vnd.mapbox-vector-tile;
|
||||
return 200 '';
|
||||
|
||||
expires 10y;
|
||||
|
||||
add_header 'Access-Control-Allow-Origin' '*' always;
|
||||
add_header Cache-Control public;
|
||||
expires 10y;
|
||||
}
|
||||
|
||||
location = / {
|
||||
@@ -53,5 +68,7 @@ server {
|
||||
# catch-all block to deny all other requests
|
||||
location / {
|
||||
deny all;
|
||||
|
||||
error_log /data/ofm/http_host/logs_nginx/tiles-org-error.log error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ def download_if_size_differs(url: str, local_file: Path) -> bool:
|
||||
|
||||
|
||||
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')
|
||||
return int(size) if size else None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user