From d587ad4ebd155053890f79eea1d235b99d92f596 Mon Sep 17 00:00:00 2001 From: Myron Blair Date: Mon, 8 Jun 2026 16:36:49 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20web=20server=20switch=20=E2=80=94=20panel?= =?UTF-8?q?=20always=20stays=20on=20Apache?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - novacpx-webserver-switch: new helper script that manages ports 80/443 only; panel ports 8880-8883 are never touched - system.php: save-option web_server now calls the helper script instead of stopping all web servers (which killed the panel) - admin.js: server options shows live Apache/Nginx status badges and notes that the panel always runs on Apache --- deploy/novacpx-webserver-switch | 59 +++++++++++++++++++++++++++++++++ panel/api/endpoints/system.php | 11 +++--- panel/assets/js/admin.js | 7 ++-- 3 files changed, 69 insertions(+), 8 deletions(-) create mode 100755 deploy/novacpx-webserver-switch diff --git a/deploy/novacpx-webserver-switch b/deploy/novacpx-webserver-switch new file mode 100755 index 0000000..d09363a --- /dev/null +++ b/deploy/novacpx-webserver-switch @@ -0,0 +1,59 @@ +#!/bin/bash +# NovaCPX — switch customer hosting web server (port 80/443) +# The panel ALWAYS stays on Apache (ports 8880-8883); only customer-facing ports are switched. +set -e +TARGET="${1:-apache}" +PORTS_CONF="/etc/apache2/ports.conf" + +write_ports_apache() { + cat > "$PORTS_CONF" << 'EOF' +# Managed by NovaCPX — do not edit manually + +# Panel ports (always active) +Listen 8880 +Listen 8881 +Listen 8882 +Listen 8883 + +# Customer hosting ports (Apache handles 80/443) +Listen 80 + + Listen 443 + +EOF +} + +write_ports_panel_only() { + cat > "$PORTS_CONF" << 'EOF' +# Managed by NovaCPX — do not edit manually + +# Panel ports (always active) +Listen 8880 +Listen 8881 +Listen 8882 +Listen 8883 + +# Customer hosting on 80/443 is handled by nginx +EOF +} + +case "$TARGET" in + nginx) + write_ports_panel_only + systemctl reload apache2 2>/dev/null || systemctl restart apache2 + systemctl enable nginx 2>/dev/null || true + systemctl start nginx 2>/dev/null || systemctl restart nginx 2>/dev/null || true + echo "switched:nginx" + ;; + apache) + systemctl stop nginx 2>/dev/null || true + systemctl disable nginx 2>/dev/null || true + write_ports_apache + systemctl reload apache2 2>/dev/null || systemctl restart apache2 + echo "switched:apache" + ;; + *) + echo "Usage: $0 {apache|nginx}" >&2 + exit 1 + ;; +esac diff --git a/panel/api/endpoints/system.php b/panel/api/endpoints/system.php index 928b870..483fd13 100644 --- a/panel/api/endpoints/system.php +++ b/panel/api/endpoints/system.php @@ -448,12 +448,13 @@ match ($action) { file_put_contents($configFile, $ini); } - // Inline service switching — stop all alternatives, start the chosen one + // Inline service switching + // NOTE: Apache is NEVER stopped — it always serves the panel on ports 8880-8883. + // The web_server switch only controls which server owns ports 80/443 for customer hosting. if ($key === 'web_server') { - $webSvcs = ['apache2','nginx','lighttpd','caddy']; - foreach ($webSvcs as $s) { shell_exec("sudo systemctl stop $s 2>/dev/null; sudo systemctl disable $s 2>/dev/null"); } - $startSvc = match($value) { 'nginx' => 'nginx', 'apache' => 'apache2', default => 'apache2' }; - shell_exec("sudo systemctl enable $startSvc 2>/dev/null && sudo systemctl start $startSvc 2>/dev/null"); + $target = in_array($value, ['nginx']) ? 'nginx' : 'apache'; + $out = shell_exec("sudo /usr/local/bin/novacpx-webserver-switch " . escapeshellarg($target) . " 2>&1"); + novacpx_log('info', "web_server switched to $target: $out"); } elseif ($key === 'ftp_server') { foreach (['proftpd','vsftpd','pure-ftpd'] as $s) { shell_exec("sudo systemctl stop $s 2>/dev/null; sudo systemctl disable $s 2>/dev/null"); } $startSvc = match($value) { 'vsftpd' => 'vsftpd', 'pureftpd' => 'pure-ftpd', default => 'proftpd' }; diff --git a/panel/assets/js/admin.js b/panel/assets/js/admin.js index 3615ecf..00e5d4b 100644 --- a/panel/assets/js/admin.js +++ b/panel/assets/js/admin.js @@ -3085,11 +3085,12 @@ async function serverOptions() {
Web Server${Nova.badge(opts.web_server||'apache','green')}
-

Current web server for hosting accounts. Changing requires migration of all vhosts.

+

Controls which server handles customer sites on ports 80/443. The panel itself always runs on Apache (ports 8880–8883) regardless of this setting.

+

Running status — Apache: ${opts.apache_active ? Nova.badge('active','green') : Nova.badge('inactive','red')}   Nginx: ${opts.nginx_active ? Nova.badge('active','green') : Nova.badge('inactive','red')}

- +