mirror of
https://github.com/hyperknot/openfreemap.git
synced 2026-05-21 14:02:15 +00:00
nginx work
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
SSH_PASSWD=
|
||||
|
||||
# Domain to server directly, without CloudFlare
|
||||
DOMAIN_DIRECT=direct.openfreemap.org
|
||||
DOMAIN_LE=direct.openfreemap.org
|
||||
|
||||
# Domain via CloudFlare, using origin certificates
|
||||
# Please put cf.key and cf.cert files in config/certs
|
||||
|
||||
@@ -90,14 +90,14 @@ def prepare_tile_gen(c):
|
||||
|
||||
|
||||
def upload_http_host_config(c):
|
||||
domain_direct = dotenv_values(f'{CONFIG_DIR}/.env').get('DOMAIN_DIRECT', '').strip()
|
||||
domain_le = dotenv_values(f'{CONFIG_DIR}/.env').get('DOMAIN_LE', '').strip()
|
||||
domain_cf = dotenv_values(f'{CONFIG_DIR}/.env').get('DOMAIN_CF', '').strip()
|
||||
skip_planet = (
|
||||
dotenv_values(f'{CONFIG_DIR}/.env').get('SKIP_PLANET', '').lower().strip() == 'true'
|
||||
)
|
||||
|
||||
if not (domain_direct or domain_cf):
|
||||
sys.exit('Please specify DOMAIN_DIRECT or DOMAIN_CF in config/.env')
|
||||
if not (domain_le or domain_cf):
|
||||
sys.exit('Please specify DOMAIN_LE or DOMAIN_CF in config/.env')
|
||||
|
||||
if domain_cf:
|
||||
if (
|
||||
@@ -107,7 +107,7 @@ def upload_http_host_config(c):
|
||||
sys.exit('When using DOMAIN_CF, please put cf.key and cf.cert files in config/certs')
|
||||
|
||||
host_config = {
|
||||
'domain_direct': domain_direct,
|
||||
'domain_le': domain_le,
|
||||
'domain_cf': domain_cf,
|
||||
'skip_planet': skip_planet,
|
||||
}
|
||||
|
||||
@@ -6,31 +6,41 @@ from http_host_lib import DEFAULT_RUNS_DIR, HOST_CONFIG, MNT_DIR, NGINX_DIR, OFM
|
||||
|
||||
|
||||
def write_nginx_config():
|
||||
location_str, curl_text = create_location_blocks()
|
||||
curl_text_mix = ''
|
||||
|
||||
if HOST_CONFIG['domain_cf']:
|
||||
with open(NGINX_DIR / 'cf.conf') as fp:
|
||||
cf_template = fp.read()
|
||||
|
||||
cf_template = cf_template.replace('__LOCATION_BLOCKS__', location_str)
|
||||
cf_template = cf_template.replace('__DOMAIN__', HOST_CONFIG['domain_cf'])
|
||||
cf_template = cf_template.replace('__LOCAL__', 'ofm_cf')
|
||||
|
||||
curl_text_mix += curl_text.replace('__DOMAIN__', HOST_CONFIG['domain_cf']).replace(
|
||||
'__LOCAL__', 'ofm_cf'
|
||||
curl_text_mix += create_nginx_conf(
|
||||
template_path=NGINX_DIR / 'cf.conf',
|
||||
local='ofm_cf',
|
||||
domain=HOST_CONFIG['domain_cf'],
|
||||
)
|
||||
|
||||
with open('/data/nginx/sites/cf.conf', 'w') as fp:
|
||||
fp.write(cf_template)
|
||||
print(' nginx config written')
|
||||
|
||||
subprocess.run(['nginx', '-t'], check=True)
|
||||
subprocess.run(['systemctl', 'reload', 'nginx'], check=True)
|
||||
|
||||
print(curl_text_mix)
|
||||
|
||||
|
||||
def create_nginx_conf(*, template_path, local, domain):
|
||||
location_str, curl_text = create_location_blocks()
|
||||
|
||||
with open(template_path) as fp:
|
||||
template = fp.read()
|
||||
|
||||
template = template.replace('__LOCATION_BLOCKS__', location_str)
|
||||
template = template.replace('__LOCAL__', local)
|
||||
template = template.replace('__DOMAIN__', domain)
|
||||
|
||||
curl_text = curl_text.replace('__LOCAL__', local)
|
||||
curl_text = curl_text.replace('__DOMAIN__', domain)
|
||||
|
||||
with open(f'/data/nginx/sites/{local}.conf', 'w') as fp:
|
||||
fp.write(template)
|
||||
print(f' nginx config written: {domain} {local}')
|
||||
|
||||
return curl_text
|
||||
|
||||
|
||||
def create_location_blocks():
|
||||
location_str = ''
|
||||
curl_text = ''
|
||||
|
||||
Reference in New Issue
Block a user