Merge pull request #589 from WordOps/updating-configuration

Add force-ssl.conf as a mustache template
This commit is contained in:
VirtuBox
2023-11-30 23:27:21 +01:00
committed by GitHub
2 changed files with 11 additions and 13 deletions

View File

@@ -0,0 +1,6 @@
server {
listen 80;
listen [::]:80;
server_name {domains};
return 301 https://$host$request_uri;
}

View File

@@ -7,6 +7,7 @@ from wo.core.logging import Log
from wo.core.shellexec import WOShellExec from wo.core.shellexec import WOShellExec
from wo.core.variables import WOVar from wo.core.variables import WOVar
from wo.core.acme import WOAcme from wo.core.acme import WOAcme
from wo.core.template import WOTemplate
class SSL: class SSL:
@@ -231,6 +232,7 @@ class SSL:
def httpsredirect(self, wo_domain_name, acme_domains, redirect=True): def httpsredirect(self, wo_domain_name, acme_domains, redirect=True):
"""Create Nginx redirection from http to https""" """Create Nginx redirection from http to https"""
wo_acme_domains = ' '.join(acme_domains) wo_acme_domains = ' '.join(acme_domains)
data = dict(domains=wo_acme_domains)
if redirect: if redirect:
Log.wait(self, "Adding HTTPS redirection") Log.wait(self, "Adding HTTPS redirection")
if WOFileUtils.enabledisable( if WOFileUtils.enabledisable(
@@ -240,19 +242,9 @@ class SSL:
return 0 return 0
else: else:
try: try:
sslconf = open( WOTemplate.deploy(self,
"/etc/nginx/conf.d/force-ssl-{0}.conf" f'/etc/nginx/conf.d/force-ssl-{wo_domain_name}.conf',
.format(wo_domain_name), data)
encoding='utf-8', mode='w')
sslconf.write(
"server {\n"
"\tlisten 80;\n" +
"\tlisten [::]:80;\n" +
"\tserver_name {0};\n"
.format(wo_acme_domains) +
"\treturn 301 https://$host"
"$request_uri;\n}")
sslconf.close()
except IOError as e: except IOError as e:
Log.debug(self, str(e)) Log.debug(self, str(e))
Log.debug( Log.debug(