diff --git a/conf/nginx.conf b/conf/nginx.conf index 7414cd34..db1a38a2 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -52,5 +52,7 @@ server { fastcgi_param SCRIPT_FILENAME /usr/local/bin/mailinabox-webfinger.php; fastcgi_pass unix:/tmp/php-fastcgi.www-data.sock; } + + # ADDITIONAL DIRECTIVES HERE } diff --git a/management/web_update.py b/management/web_update.py index e85e0d02..78659fed 100644 --- a/management/web_update.py +++ b/management/web_update.py @@ -2,7 +2,7 @@ # domains for which a mail account has been set up. ######################################################################## -import os, os.path +import os, os.path, re, rtyaml from mailconfig import get_mail_domains from utils import shell, safe_domain_name, sort_domains @@ -67,6 +67,20 @@ def make_domain_config(domain, template, env): nginx_conf = nginx_conf.replace("$ROOT", root) nginx_conf = nginx_conf.replace("$SSL_KEY", ssl_key) nginx_conf = nginx_conf.replace("$SSL_CERTIFICATE", ssl_certificate) + + # Add in any user customizations. + nginx_conf_parts = re.split("(# ADDITIONAL DIRECTIVES HERE\n)", nginx_conf) + nginx_conf_custom_fn = os.path.join(env["STORAGE_ROOT"], "www/custom.yaml") + if os.path.exists(nginx_conf_custom_fn): + yaml = rtyaml.load(open(nginx_conf_custom_fn)) + if domain in yaml: + yaml = yaml[domain] + if "proxy" in yaml: + nginx_conf_parts[1] += "\tlocation / {\n\t\tproxy_pass %s;\n\t}\n" % yaml["proxy"] + + # Put it all together. + nginx_conf = "".join(nginx_conf_parts) + return nginx_conf def get_web_root(domain, env):