diff --git a/CHANGES b/CHANGES index 238c2dac6..25409c916 100644 --- a/CHANGES +++ b/CHANGES @@ -2700,4 +2700,5 @@ [7.6.1] * Cleanup backup validation mount point +* dashboard: remove nginx config of old domain when domain changed diff --git a/src/dashboard.js b/src/dashboard.js index 954295102..0c49b40a4 100644 --- a/src/dashboard.js +++ b/src/dashboard.js @@ -129,10 +129,13 @@ async function changeLocation(subdomain, domain, auditSource) { assert.strictEqual(typeof domain, 'string'); assert.strictEqual(typeof auditSource, 'object'); + const oldLocation = await getLocation(); await setupLocation(subdomain, domain, auditSource); debug(`setupLocation: notifying appstore and platform of domain change to ${domain}`); await eventlog.add(eventlog.ACTION_DASHBOARD_DOMAIN_UPDATE, auditSource, { subdomain, domain }); await safe(appstore.updateCloudron({ domain }), { debug }); await platform.onDashboardLocationChanged(auditSource); + + await safe(reverseProxy.removeDashboardConfig(oldLocation.domain), { debug }); } diff --git a/src/reverseproxy.js b/src/reverseproxy.js index 40a46efe9..642fa2737 100644 --- a/src/reverseproxy.js +++ b/src/reverseproxy.js @@ -25,6 +25,7 @@ exports = module.exports = { writeDashboardConfig, writeAppConfigs, + removeDashboardConfig, removeAppConfigs, restoreFallbackCertificates, @@ -472,7 +473,7 @@ async function writeDashboardNginxConfig(vhost, certificatePath) { async function writeDashboardConfig(domain) { assert.strictEqual(typeof domain, 'string'); - debug(`writeDashboardConfig: writing admin config for ${domain}`); + debug(`writeDashboardConfig: writing dashboard config for ${domain}`); const dashboardFqdn = dns.fqdn(constants.DASHBOARD_SUBDOMAIN, domain); const location = { domain, fqdn: dashboardFqdn, certificate: null }; @@ -481,6 +482,19 @@ async function writeDashboardConfig(domain) { await reload(); } +async function removeDashboardConfig(domain) { + assert.strictEqual(typeof domain, 'string'); + + debug(`removeDashboardConfig: removing dashboard config of ${domain}`); + + const vhost = dns.fqdn(constants.DASHBOARD_SUBDOMAIN, domain); + const nginxConfigFilename = path.join(paths.NGINX_APPCONFIG_DIR, `dashboard/${vhost}.conf`); + + if (!safe.fs.unlinkSync(nginxConfigFilename)) throw new BoxError(BoxError.FS_ERROR, safe.error.message); + + await reload(); +} + async function writeAppLocationNginxConfig(app, location, certificatePath) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof location, 'object');