nginx work

This commit is contained in:
Zsolt Ero
2024-02-24 02:37:07 +01:00
parent cb10f4ba90
commit 3c6aaeef57
3 changed files with 29 additions and 19 deletions

View File

@@ -2,7 +2,7 @@
SSH_PASSWD= SSH_PASSWD=
# Domain to server directly, without CloudFlare # Domain to server directly, without CloudFlare
DOMAIN_DIRECT=direct.openfreemap.org DOMAIN_LE=direct.openfreemap.org
# Domain via CloudFlare, using origin certificates # Domain via CloudFlare, using origin certificates
# Please put cf.key and cf.cert files in config/certs # Please put cf.key and cf.cert files in config/certs

View File

@@ -90,14 +90,14 @@ def prepare_tile_gen(c):
def upload_http_host_config(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() domain_cf = dotenv_values(f'{CONFIG_DIR}/.env').get('DOMAIN_CF', '').strip()
skip_planet = ( skip_planet = (
dotenv_values(f'{CONFIG_DIR}/.env').get('SKIP_PLANET', '').lower().strip() == 'true' dotenv_values(f'{CONFIG_DIR}/.env').get('SKIP_PLANET', '').lower().strip() == 'true'
) )
if not (domain_direct or domain_cf): if not (domain_le or domain_cf):
sys.exit('Please specify DOMAIN_DIRECT or DOMAIN_CF in config/.env') sys.exit('Please specify DOMAIN_LE or DOMAIN_CF in config/.env')
if domain_cf: if domain_cf:
if ( 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') sys.exit('When using DOMAIN_CF, please put cf.key and cf.cert files in config/certs')
host_config = { host_config = {
'domain_direct': domain_direct, 'domain_le': domain_le,
'domain_cf': domain_cf, 'domain_cf': domain_cf,
'skip_planet': skip_planet, 'skip_planet': skip_planet,
} }

View File

@@ -6,31 +6,41 @@ from http_host_lib import DEFAULT_RUNS_DIR, HOST_CONFIG, MNT_DIR, NGINX_DIR, OFM
def write_nginx_config(): def write_nginx_config():
location_str, curl_text = create_location_blocks()
curl_text_mix = '' curl_text_mix = ''
if HOST_CONFIG['domain_cf']: if HOST_CONFIG['domain_cf']:
with open(NGINX_DIR / 'cf.conf') as fp: curl_text_mix += create_nginx_conf(
cf_template = fp.read() template_path=NGINX_DIR / 'cf.conf',
local='ofm_cf',
cf_template = cf_template.replace('__LOCATION_BLOCKS__', location_str) domain=HOST_CONFIG['domain_cf'],
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'
) )
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(['nginx', '-t'], check=True)
subprocess.run(['systemctl', 'reload', 'nginx'], check=True) subprocess.run(['systemctl', 'reload', 'nginx'], check=True)
print(curl_text_mix) 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(): def create_location_blocks():
location_str = '' location_str = ''
curl_text = '' curl_text = ''