Complete local deployment setup with Cloudflare tunnel

- setup_local_hosting.sh: Configures Nginx reverse proxy, installs cloudflared
- SETUP_CLOUDFLARE_TUNNEL.sh: Interactive tunnel setup script (5 min)
- check_status.sh: Real-time status dashboard for all services
- LOCAL_ACCESS_GUIDE.md: Complete local access instructions
- FINAL_DEPLOYMENT_README.md: Comprehensive deployment guide

Current Status:
   Nginx reverse proxy running (port 80)
   Backend API healthy (port 8000)
   Frontend running (port 3000, redirecting unauthenticated to login)
   PostgreSQL database connected with demo data
   All services accessible at http://10.30.20.38
   Cloudflare tunnel installed and ready

Access:
  - Local: http://10.30.20.38
  - With Cloudflare: https://your-domain.com (after tunnel setup)
  - Demo credentials included and working

Next Steps:
  1. Visit http://10.30.20.38 and login
  2. Run SETUP_CLOUDFLARE_TUNNEL.sh for global access
  3. Share HTTPS URL with anyone

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
drjones
2026-07-07 14:06:47 +00:00
parent c16272b8b5
commit d92a7c057d
12 changed files with 1592 additions and 38 deletions

178
setup_local_hosting.sh Executable file
View File

@@ -0,0 +1,178 @@
#!/bin/bash
# TrustOS Local Hosting & Cloudflare Tunnel Setup
# This script sets up TrustOS to be accessible locally and via Cloudflare tunnel
set -e
echo "🚀 TrustOS Local Hosting Setup"
echo "=============================="
echo ""
# Get machine IP
MACHINE_IP=$(ip addr show | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}' | cut -d'/' -f1 | head -1)
echo "Machine IP: $MACHINE_IP"
echo ""
# Detect OS
if command -v apt-get &> /dev/null; then
echo "✓ Ubuntu/Debian detected"
INSTALL_CMD="apt-get install -y"
OS="debian"
elif command -v yum &> /dev/null; then
echo "✓ CentOS/RHEL detected"
INSTALL_CMD="yum install -y"
OS="rhel"
else
echo "✗ Unsupported OS"
exit 1
fi
# Install Nginx if not present
if ! command -v nginx &> /dev/null; then
echo "Installing Nginx..."
$INSTALL_CMD nginx
fi
# Install Cloudflared if not present
if ! command -v cloudflared &> /dev/null; then
echo "Installing Cloudflare Tunnel..."
curl -s -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64 -o /usr/local/bin/cloudflared
chmod +x /usr/local/bin/cloudflared
fi
# Create Nginx config
echo "Creating Nginx configuration..."
mkdir -p /etc/nginx/sites-available /etc/nginx/sites-enabled
cat > /etc/nginx/sites-available/trustos << 'NGINX_CONFIG'
# TrustOS Backend API
upstream trustos_backend {
server localhost:8000;
}
# TrustOS Frontend
upstream trustos_frontend {
server localhost:3000;
}
# API Server
server {
listen 80;
server_name _;
client_max_body_size 100M;
# API endpoints
location /api {
proxy_pass http://trustos_backend;
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;
# CORS headers
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, PATCH, DELETE, OPTIONS' always;
add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization' always;
if ($request_method = 'OPTIONS') {
return 204;
}
}
# Health checks
location /health {
proxy_pass http://trustos_backend;
}
location /docs {
proxy_pass http://trustos_backend;
}
# Frontend
location / {
proxy_pass http://trustos_frontend;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
NGINX_CONFIG
# Enable site
ln -sf /etc/nginx/sites-available/trustos /etc/nginx/sites-enabled/trustos 2>/dev/null || true
# Test and start Nginx
echo "Testing Nginx configuration..."
nginx -t
systemctl restart nginx
echo "✓ Nginx configured and running"
echo ""
# Create Cloudflare tunnel setup
echo "Setting up Cloudflare Tunnel..."
echo ""
echo "⚠️ IMPORTANT: To complete Cloudflare tunnel setup:"
echo "1. Run: cloudflared tunnel login"
echo "2. Follow the browser prompt to authenticate"
echo "3. Then run: cloudflared tunnel create trustos"
echo "4. Then run: cloudflared tunnel route dns trustos <your-domain.com>"
echo ""
cat > /root/trustos/start_tunnel.sh << 'TUNNEL_SCRIPT'
#!/bin/bash
# Start Cloudflare tunnel
cloudflared tunnel run trustos --url http://localhost:80
TUNNEL_SCRIPT
chmod +x /root/trustos/start_tunnel.sh
# Create systemd service for tunnel (optional)
cat > /etc/systemd/system/trustos-tunnel.service << 'SERVICE_CONFIG'
[Unit]
Description=TrustOS Cloudflare Tunnel
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/cloudflared tunnel run trustos --url http://localhost:80
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
SERVICE_CONFIG
echo "✓ Cloudflare tunnel service created"
echo ""
# Display access information
echo "════════════════════════════════════════════════"
echo "🎉 TRUSTOS LOCAL HOSTING SETUP COMPLETE"
echo "════════════════════════════════════════════════"
echo ""
echo "📍 LOCAL ACCESS:"
echo " Frontend: http://$MACHINE_IP"
echo " Backend API: http://$MACHINE_IP/api"
echo " API Docs: http://$MACHINE_IP/docs"
echo ""
echo "🌐 CLOUDFLARE TUNNEL:"
echo " To set up tunnel, run:"
echo " 1. cloudflared tunnel login"
echo " 2. cloudflared tunnel create trustos"
echo " 3. cloudflared tunnel route dns trustos your-domain.com"
echo " 4. systemctl start trustos-tunnel (or run: /root/trustos/start_tunnel.sh)"
echo ""
echo "📊 MONITORING:"
echo " View Nginx logs: tail -f /var/log/nginx/access.log"
echo " View Tunnel status: cloudflared tunnel info trustos"
echo ""
echo "✅ Services Status:"
systemctl status nginx --no-pager -l 3
echo ""
curl -s http://localhost:8000/health | jq . && echo "✓ Backend API is healthy" || echo "⚠️ Backend not responding yet"
echo ""
echo "════════════════════════════════════════════════"