aboutsummaryrefslogtreecommitdiff
path: root/tool/modules/nginx.py
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-11-27 11:18:47 +0800
committercrupest <crupest@outlook.com>2022-11-27 11:18:47 +0800
commit3be4d089dca831ec5e79eb457100a967b8a20398 (patch)
treea27aba4a7bbac9181ecb2e71994f8d3411b8975e /tool/modules/nginx.py
parentb0a7c606af768b190d5541e407803bd4a30b1dac (diff)
downloadcrupest-3be4d089dca831ec5e79eb457100a967b8a20398.tar.gz
crupest-3be4d089dca831ec5e79eb457100a967b8a20398.tar.bz2
crupest-3be4d089dca831ec5e79eb457100a967b8a20398.zip
Nginx add redirect.
Diffstat (limited to 'tool/modules/nginx.py')
-rwxr-xr-xtool/modules/nginx.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/tool/modules/nginx.py b/tool/modules/nginx.py
index 7aee923..08c8e1d 100755
--- a/tool/modules/nginx.py
+++ b/tool/modules/nginx.py
@@ -25,6 +25,8 @@ static_file_template = Template(os.path.join(
nginx_template_dir, 'static-file.conf.template'))
reverse_proxy_template = Template(os.path.join(
nginx_template_dir, 'reverse-proxy.conf.template'))
+redirect_template = Template(os.path.join(
+ nginx_template_dir, 'redirect.conf.template'))
cert_only_template = Template(os.path.join(
nginx_template_dir, 'cert-only.conf.template'))
@@ -50,8 +52,6 @@ def nginx_config_gen(domain: str, dest: str) -> None:
# generate nginx config for each site
sites: list = server["sites"]
for site in sites:
- if site["type"] not in ['static-file', 'reverse-proxy', "cert-only"]:
- continue
subdomain = site["subdomain"]
local_config = config.copy()
local_config['CRUPEST_NGINX_SUBDOMAIN'] = subdomain
@@ -62,8 +62,13 @@ def nginx_config_gen(domain: str, dest: str) -> None:
template = reverse_proxy_template
local_config['CRUPEST_NGINX_UPSTREAM_NAME'] = site["upstream"]["name"]
local_config['CRUPEST_NGINX_UPSTREAM_SERVER'] = site["upstream"]["server"]
+ elif site["type"] == 'redirect':
+ template = redirect_template
+ local_config['CRUPEST_NGINX_URL'] = site["url"]
elif site["type"] == 'cert-only':
template = cert_only_template
+ else:
+ raise Exception('Invalid site type')
with open(os.path.join(dest, f'{subdomain}.{domain}.conf'), 'w') as f:
f.write(template.generate(local_config))