From a1762976ad238167ff1b3c86262b66355965d142 Mon Sep 17 00:00:00 2001 From: Prabuddha Chakraborty Date: Thu, 17 Dec 2015 16:30:59 +0530 Subject: [PATCH] added httpsRedirect() functionality --- ee/cli/plugins/site_functions.py | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/ee/cli/plugins/site_functions.py b/ee/cli/plugins/site_functions.py index 0b15df96..b8ba3a12 100644 --- a/ee/cli/plugins/site_functions.py +++ b/ee/cli/plugins/site_functions.py @@ -1227,8 +1227,7 @@ def setupLetsEncrypt(self, ee_domain_name): sslconf = open("/var/www/{0}/conf/nginx/ssl.conf" .format(ee_domain_name), encoding='utf-8', mode='w') - sslconf.write("listen 80;\n" - "listen 443 ssl spdy;\n" + sslconf.write("listen 443 ssl spdy;\n" "ssl on;\n" "ssl_certificate /etc/letsencrypt/live/{0}/fullchain.pem;\n" "ssl_certificate_key /etc/letsencrypt/live/{0}/privkey.pem;\n" @@ -1282,6 +1281,32 @@ def renewLetsEncrypt(self, ee_domain_name): EEGit.add(self, ["/etc/letsencrypt"], msg="Adding letsencrypt folder") +#redirect= False to disable https redirection +def httpsRedirect(self,ee_domain_name,redirect=True): + if redirect: + try: + Log.info(self, "Adding /etc/nginx/conf.d/force-ssl-{0}.conf".format(ee_domain_name)) + + sslconf = open("/etc/nginx/conf.d/force-ssl-{0}.conf" + .format(ee_domain_name), + encoding='utf-8', mode='w') + sslconf.write("server {\n" + "\tlisten 80;\n" + "\tserver_name www.{0} {0};\n" + "\treturn 301 https://{0}$request_uri;\n" + "}\n" + .format(ee_domain_name)) + sslconf.close() + # Nginx Configation into GIT + EEGit.add(self, + ["/etc/nginx"], msg="Adding /etc/nginx/conf.d/force-ssl-{0}.conf".format(ee_domain_name)) + except IOError as e: + Log.debug(self, str(e)) + Log.debug(self, "Error occured while generating " + "/etc/nginx/conf.d/force-ssl-{0}.conf".format(ee_domain_name)) + + +