From 7e48b1883741c063c9077cb8d00d2ef790fe27fc Mon Sep 17 00:00:00 2001 From: VirtuBox Date: Sun, 6 Aug 2023 12:55:26 +0200 Subject: [PATCH] Add wo site create --alias --- wo/cli/plugins/site_create.py | 43 ++++++++++++++++++++++++++- wo/cli/templates/virtualconf.mustache | 10 +++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/wo/cli/plugins/site_create.py b/wo/cli/plugins/site_create.py index 836ff94..ffc990b 100644 --- a/wo/cli/plugins/site_create.py +++ b/wo/cli/plugins/site_create.py @@ -73,6 +73,9 @@ class WOSiteCreateController(CementBaseController): dict(help="create WordPress single/multi site " "with redis cache", action='store_true')), + (['--alias'], + dict(help="domain name to redirect to", + action='store', nargs='?')), (['-le', '--letsencrypt'], dict(help="configure letsencrypt ssl for the site", action='store' or 'store_const', @@ -129,10 +132,17 @@ class WOSiteCreateController(CementBaseController): proxyinfo = proxyinfo.split(':') host = proxyinfo[0].strip() port = '80' if len(proxyinfo) < 2 else proxyinfo[1].strip() - elif stype is None and not pargs.proxy: + elif stype is None and not pargs.proxy and not pargs.alias: stype, cache = 'html', 'basic' + elif stype is None and pargs.alias: + stype, cache = 'alias', '' + alias_name = pargs.alias.strip() + if not alias_name: + Log.error(self, "Please provide alias name") elif stype and pargs.proxy: Log.error(self, "proxy should not be used with other site types") + elif stype and pargs.alias: + Log.error(self, "alias should not be used with other site types") if not pargs.site_name: try: @@ -173,6 +183,16 @@ class WOSiteCreateController(CementBaseController): data['port'] = port data['basic'] = True + if stype == 'alias': + data = dict( + site_name=wo_domain, www_domain=wo_www_domain, + static=True, basic=False, wp=False, + wpfc=False, wpsc=False, wprocket=False, wpce=False, + multisite=False, wpsubdir=False, webroot=wo_site_webroot) + data['alias'] = True + data['alias_name'] = alias_name + data['basic'] = True + if (pargs.php72 or pargs.php73 or pargs.php74 or pargs.php80 or pargs.php81 or pargs.php82): data = dict( @@ -301,6 +321,27 @@ class WOSiteCreateController(CementBaseController): " http://{0}".format(wo_domain)) return + if 'alias' in data.keys() and data['alias']: + addNewSite(self, wo_domain, stype, cache, wo_site_webroot) + # Service Nginx Reload + if not WOService.reload_service(self, 'nginx'): + Log.info(self, Log.FAIL + + "There was a serious error encountered...") + Log.info(self, Log.FAIL + "Cleaning up afterwards...") + doCleanupAction(self, domain=wo_domain) + deleteSiteInfo(self, wo_domain) + Log.error(self, "service nginx reload failed. " + "check issues with `nginx -t` command") + Log.error(self, "Check the log for details: " + "`tail /var/log/wo/wordops.log` " + "and please try again") + if wo_auth and len(wo_auth): + for msg in wo_auth: + Log.info(self, Log.ENDC + msg, log=False) + Log.info(self, "Successfully created site" + " http://{0}".format(wo_domain)) + return + addNewSite(self, wo_domain, stype, cache, wo_site_webroot, php_version=php_version) diff --git a/wo/cli/templates/virtualconf.mustache b/wo/cli/templates/virtualconf.mustache index 396606f..3356ab8 100644 --- a/wo/cli/templates/virtualconf.mustache +++ b/wo/cli/templates/virtualconf.mustache @@ -16,6 +16,10 @@ server { access_log /var/log/nginx/{{site_name}}.access.log {{^wpredis}}{{^static}}rt_cache{{/static}}{{/wpredis}}{{#wpredis}}rt_cache_redis{{/wpredis}}; error_log /var/log/nginx/{{site_name}}.error.log; + {{#alias}} + location / { + return 301 https://{{alias_name}}$request_uri; + } {{#proxy}} add_header X-Proxy-Cache $upstream_cache_status; location / { @@ -23,7 +27,7 @@ server { proxy_redirect off; include proxy_params; } - + {{#alias}} # Security settings for better privacy # Deny hidden files location ~ /\.(?!well-known\/) { @@ -35,9 +39,11 @@ server { allow all; auth_basic off; } + {{/alias}} {{/proxy}} {{^proxy}} + {{^alias}} root {{webroot}}/htdocs; index {{^static}}index.php{{/static}} index.html index.htm; @@ -51,7 +57,7 @@ server { {{^static}}include {{#basic}}common/{{wo_php}}.conf;{{/basic}}{{#wpfc}}common/wpfc-{{wo_php}}.conf;{{/wpfc}}{{#wpsc}}common/wpsc-{{wo_php}}.conf;{{/wpsc}}{{#wpredis}}common/redis-{{wo_php}}.conf;{{/wpredis}}{{#wprocket}}common/wprocket-{{wo_php}}.conf;{{/wprocket}}{{#wpce}}common/wpce-{{wo_php}}.conf;{{/wpce}} {{#wpsubdir}}include common/wpsubdir.conf;{{/wpsubdir}}{{/static}} {{#wp}}include common/wpcommon-{{wo_php}}.conf;{{/wp}} - include common/locations-wo.conf;{{/proxy}} + include common/locations-wo.conf;{{/proxy}}{{/alias}} include {{webroot}}/conf/nginx/*.conf; }