Add wo site create --alias

This commit is contained in:
VirtuBox
2023-08-06 12:55:26 +02:00
parent 717cdf8542
commit 7e48b18837
2 changed files with 50 additions and 3 deletions

View File

@@ -73,6 +73,9 @@ class WOSiteCreateController(CementBaseController):
dict(help="create WordPress single/multi site " dict(help="create WordPress single/multi site "
"with redis cache", "with redis cache",
action='store_true')), action='store_true')),
(['--alias'],
dict(help="domain name to redirect to",
action='store', nargs='?')),
(['-le', '--letsencrypt'], (['-le', '--letsencrypt'],
dict(help="configure letsencrypt ssl for the site", dict(help="configure letsencrypt ssl for the site",
action='store' or 'store_const', action='store' or 'store_const',
@@ -129,10 +132,17 @@ class WOSiteCreateController(CementBaseController):
proxyinfo = proxyinfo.split(':') proxyinfo = proxyinfo.split(':')
host = proxyinfo[0].strip() host = proxyinfo[0].strip()
port = '80' if len(proxyinfo) < 2 else proxyinfo[1].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' 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: elif stype and pargs.proxy:
Log.error(self, "proxy should not be used with other site types") 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: if not pargs.site_name:
try: try:
@@ -173,6 +183,16 @@ class WOSiteCreateController(CementBaseController):
data['port'] = port data['port'] = port
data['basic'] = True 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 if (pargs.php72 or pargs.php73 or pargs.php74 or
pargs.php80 or pargs.php81 or pargs.php82): pargs.php80 or pargs.php81 or pargs.php82):
data = dict( data = dict(
@@ -301,6 +321,27 @@ class WOSiteCreateController(CementBaseController):
" http://{0}".format(wo_domain)) " http://{0}".format(wo_domain))
return 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, addNewSite(self, wo_domain, stype, cache, wo_site_webroot,
php_version=php_version) php_version=php_version)

View File

@@ -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}}; 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; error_log /var/log/nginx/{{site_name}}.error.log;
{{#alias}}
location / {
return 301 https://{{alias_name}}$request_uri;
}
{{#proxy}} {{#proxy}}
add_header X-Proxy-Cache $upstream_cache_status; add_header X-Proxy-Cache $upstream_cache_status;
location / { location / {
@@ -23,7 +27,7 @@ server {
proxy_redirect off; proxy_redirect off;
include proxy_params; include proxy_params;
} }
{{#alias}}
# Security settings for better privacy # Security settings for better privacy
# Deny hidden files # Deny hidden files
location ~ /\.(?!well-known\/) { location ~ /\.(?!well-known\/) {
@@ -35,9 +39,11 @@ server {
allow all; allow all;
auth_basic off; auth_basic off;
} }
{{/alias}}
{{/proxy}} {{/proxy}}
{{^proxy}} {{^proxy}}
{{^alias}}
root {{webroot}}/htdocs; root {{webroot}}/htdocs;
index {{^static}}index.php{{/static}} index.html index.htm; 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}} {{^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}} {{#wpsubdir}}include common/wpsubdir.conf;{{/wpsubdir}}{{/static}}
{{#wp}}include common/wpcommon-{{wo_php}}.conf;{{/wp}} {{#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; include {{webroot}}/conf/nginx/*.conf;
} }