mirror of
https://github.com/myronblair/novacpx
synced 2026-06-30 17:50:41 -05:00
Fix web server switch — panel always stays on Apache
- 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
This commit is contained in:
Executable
+59
@@ -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
|
||||
<IfModule ssl_module>
|
||||
Listen 443
|
||||
</IfModule>
|
||||
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
|
||||
@@ -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' };
|
||||
|
||||
@@ -3085,11 +3085,12 @@ async function serverOptions() {
|
||||
<div class="card">
|
||||
<div class="card-header"><span class="card-title">Web Server</span>${Nova.badge(opts.web_server||'apache','green')}</div>
|
||||
<div class="card-body">
|
||||
<p class="text-muted" style="font-size:.85rem;margin-bottom:1rem">Current web server for hosting accounts. Changing requires migration of all vhosts.</p>
|
||||
<p class="text-muted" style="font-size:.85rem;margin-bottom:.5rem">Controls which server handles customer sites on ports 80/443. The panel itself always runs on Apache (ports 8880–8883) regardless of this setting.</p>
|
||||
<p class="text-muted" style="font-size:.85rem;margin-bottom:1rem">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')}</p>
|
||||
<div class="form-group">
|
||||
<label>Active Web Server</label>
|
||||
<label>Customer Hosting Web Server</label>
|
||||
<select id="so-web" class="form-control">
|
||||
${['apache','nginx','openlitespeed','caddy'].map(s=>`<option value="${s}" ${s===(opts.web_server||'apache')?'selected':''}>${s.charAt(0).toUpperCase()+s.slice(1)}</option>`).join('')}
|
||||
${['apache','nginx'].map(s=>`<option value="${s}" ${s===(opts.web_server||'apache')?'selected':''}>${s.charAt(0).toUpperCase()+s.slice(1)}</option>`).join('')}
|
||||
</select>
|
||||
</div>
|
||||
<button class="btn btn-primary btn-sm" onclick="soSave('web_server','so-web','Web server')">Save & Switch</button>
|
||||
|
||||
Reference in New Issue
Block a user