Files
zmb-webui/deploy/setup-nginx-static.sh
Claude Code 6d74d874b6 ZMB Webui: Complete Project – Rebrand & Initial Clean Commit
ARCHITECTURE
============
Backend: FastAPI + uvicorn (port 8000)
  - JWT authentication with PAM system users
  - ZFS CLI wrapper with caching (30-60s TTL)
  - WebSocket pool status broadcaster (30s interval)
  - Services: auth, zfs_runner, file_manager, shares, identities, system_info
  - Routers: pools, datasets, snapshots, shares, identities, navigator, system

Frontend: Next.js 15 + TypeScript (static export)
  - Incremental Static Regeneration (ISR) for weak hardware
  - Type-safe API client (lib/api.ts)
  - Dark mode + custom Tailwind theme
  - Pages: Dashboard, Login, Snapshots, Datasets, Shares, etc.

DEPLOYMENT
==========
Test Target: 192.168.1.179:8090 (Debian LXC)
Production: 10.66.120.3:9090 (Raspberry Pi 4GB ARM64)
Updater: Automated Gitea-based deployment (update-test.sh, update-pi.sh)

FEATURES COMPLETED
==================
Phase 3a: Dashboard Quick Stats (System, CPU, Memory, Storage)
  - Real-time stats with color-coded progress bars
  - Responsive grid layout (mobile: 1, tablet: 2, desktop: 4 columns)
  - ISR-optimized for fast loads on weak hardware

REBRANDING
==========
Renamed throughout:
  - Project: 'ZFS Manager' → 'ZMB Webui'
  - Services: 'zfs-manager' → 'zmb-webui'
  - Systemd units: zfs-manager-backend → zmb-webui-backend
  - Configuration files and documentation

Co-Authored-By: Patrick <patrick@perlbach24.de>
2026-04-22 00:43:05 +02:00

123 lines
3.7 KiB
Bash

#!/bin/bash
# Minimales Nginx-Setup für statische Frontend Dateien
set -e
echo "=== Nginx Static Frontend Setup ==="
FRONTEND_DIR="/opt/zmb-webui/frontend/out"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
# Verify frontend export exists
echo -e "${YELLOW}1. Checking frontend export...${NC}"
if [ ! -d "$FRONTEND_DIR" ]; then
echo -e "${RED}✗ Frontend export not found: $FRONTEND_DIR${NC}"
exit 1
fi
FILE_COUNT=$(find "$FRONTEND_DIR" -type f | wc -l)
echo -e "${GREEN}✓ Frontend export found ($FILE_COUNT files)${NC}"
# Configure nginx
echo -e "${YELLOW}2. Configuring nginx...${NC}"
mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled
sudo tee /etc/nginx/sites-available/zmb-webui > /dev/null <<'NGINX_CONF'
server {
listen 9090;
server_name _;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
# Compression
gzip on;
gzip_min_length 1000;
gzip_types text/plain text/css application/json application/javascript;
gzip_comp_level 5;
# Static assets cache (7 days)
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
root /opt/zmb-webui/frontend/out;
expires 7d;
add_header Cache-Control "public, max-age=604800, immutable";
access_log off;
}
# Frontend static pages (SPA routing)
location / {
root /opt/zmb-webui/frontend/out;
try_files $uri $uri/ /index.html;
add_header Cache-Control "public, max-age=3600";
}
# API routes → Backend
location /api/ {
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 10s;
proxy_read_timeout 30s;
}
# Health check
location /health {
proxy_pass http://localhost:8000;
access_log off;
}
# Logging
access_log /var/log/nginx/zmb-webui-access.log combined;
error_log /var/log/nginx/zmb-webui-error.log warn;
}
NGINX_CONF
echo -e "${GREEN}✓ Nginx configured${NC}"
# Enable nginx site
echo -e "${YELLOW}3. Enabling nginx site...${NC}"
sudo rm -f /etc/nginx/sites-enabled/default
sudo ln -sf /etc/nginx/sites-available/zmb-webui /etc/nginx/sites-enabled/zmb-webui
echo -e "${GREEN}✓ Nginx site enabled${NC}"
# Test and reload nginx
echo -e "${YELLOW}4. Testing and reloading nginx...${NC}"
sudo nginx -t 2>&1 | grep -v "warning\|redundant"
sudo systemctl reload nginx
echo -e "${GREEN}✓ Nginx reloaded${NC}"
# Clean up old services
echo -e "${YELLOW}5. Cleaning up Node.js service (if exists)...${NC}"
if sudo systemctl is-enabled zmb-webui-frontend 2>/dev/null; then
sudo systemctl disable zmb-webui-frontend
sudo systemctl stop zmb-webui-frontend 2>/dev/null || true
sudo rm -f /etc/systemd/system/zmb-webui-frontend.service
sudo systemctl daemon-reload
fi
echo -e "${GREEN}✓ Cleanup complete${NC}"
# Verify
echo -e "${YELLOW}6. Testing connectivity...${NC}"
sleep 1
if curl -s http://localhost:9090 > /dev/null 2>&1; then
echo -e "${GREEN}✓ Frontend accessible on port 9090${NC}"
else
echo -e "${YELLOW}⚠ Testing with curl (may need time to warm up)${NC}"
fi
# Summary
echo ""
echo -e "${GREEN}=== Setup Complete ===${NC}"
echo ""
echo "Frontend: http://$(hostname -I | awk '{print $1}'):9090"
echo "API: http://localhost:8000"
echo ""
echo "Service: systemctl reload nginx"
echo "Logs: tail -f /var/log/nginx/zmb-webui-*.log"
echo ""