A minimal, production-grade guide to turning an idle physical Android smartphone into a 24/7 Linux server running Ubuntu 24.04 LTS via Termux, isolated PRoot, Nginx, and Cloudflare Named Tunnels.
+-------------------------------------------------------------------+
| PHYSICAL ANDROID HARDWARE (ARM64) |
| - Battery acts as zero-cost Hardware UPS (blackout immune) |
| - Android CPU Wake-Lock active |
+-------------------------------------------------------------------+
|
v
+-------------------------------------------------------------------+
| TERMUX BASE LAYER |
| - Host management, OpenSSH (:8022), tmux daemons |
| - Cloudflare Named Tunnel (outbound QUIC, 0 open ports) |
| - Sentinel Watchdog (auto-recovers dead processes in seconds) |
+-------------------------------------------------------------------+
|
v
+-------------------------------------------------------------------+
| UBUNTU 24.04 PRoot ISOLATED CONTAINER |
| - Runs securely without Android root |
| - Nginx 1.24 web server (:8080) |
| - Application web root: /var/www/html/ |
+-------------------------------------------------------------------+
- Hardware: Any physical Android smartphone (ARM64 / aarch64, 3GB+ RAM recommended).
- Terminal: Install Termux from F-Droid (do not use the obsolete Google Play version).
- Power: Plug the phone into a charger and keep it connected to Wi-Fi.
To prevent Android OS from putting the CPU or Wi-Fi to sleep:
- Acquire Termux Wake-Lock:
Run inside Termux:
termux-wake-lock
- Disable Android Battery Optimization: Go to phone Settings -> Apps -> Termux -> Battery and set to Unrestricted (or "Don't Optimize").
- Prevent App Killing (Android 12+ Phantom Process Killer):
If on Android 12+, enable Developer Options and disable phantom process limits, or execute via ADB:
adb shell "/system/bin/device_config put activity_manager max_phantom_processes 2147483647"
Inside Termux, update packages and install core utilities:
pkg update -y && pkg upgrade -y
pkg install -y proot-distro tmux git curl opensshUse proot-distro to install an isolated Ubuntu userland without rooting:
proot-distro install ubuntuVerify you can log into Ubuntu:
proot-distro login --isolated ubuntu(Type exit to return to Termux).
Log into Ubuntu and install Nginx 1.24:
proot-distro login --isolated ubuntu -- bash -c "apt update && apt install -y nginx && apt clean"Configure Nginx to listen on non-privileged port 8080:
proot-distro login --isolated ubuntu -- bash -c "sed -i 's/listen 80 default_server;/listen 8080 default_server;/g' /etc/nginx/sites-available/default && sed -i 's/listen \[::\]:80 default_server;/listen \[::\]:8080 default_server;/g' /etc/nginx/sites-available/default"Start Nginx inside Ubuntu as a background daemon:
proot-distro login --isolated -d ubuntu -- nginx -g "daemon off;"Test local connectivity from Termux:
curl -I http://127.0.0.1:8080/You should receive HTTP/1.1 200 OK.
This server requires zero router port forwarding, no public static IP, and 0 open inbound firewall ports. Traffic enters securely via an outbound encrypted tunnel.
- Install cloudflared in Termux:
pkg install -y cloudflared
- Authenticate with Cloudflare:
(Open the displayed URL in your browser and select your domain).
cloudflared tunnel login
- Create Named Tunnel:
cloudflared tunnel create my-phone-server
- Route Your Domain to the Tunnel:
cloudflared tunnel route dns my-phone-server yourdomain.com
- Configure Ingress (
~/.cloudflared/config.yml):tunnel: <TUNNEL_UUID> credentials-file: /data/data/com.termux/files/home/.cloudflared/<TUNNEL_UUID>.json ingress: - hostname: yourdomain.com service: http://127.0.0.1:8080 - service: http_status:404
- Run the Tunnel in tmux:
tmux new-session -d -s tunnel "cloudflared tunnel run my-phone-server"
Your website is now live at https://yourdomain.com with automatic HTTPS!
To prevent Android process killer from keeping your server down, run the included sentinel watchdog script in a tmux session:
chmod +x scripts/server-ctl.sh scripts/watchdog.sh
tmux new-session -d -s watchdog "./scripts/watchdog.sh"If Nginx or the tunnel crashes, the watchdog revives it within 5 seconds.
Use scripts/server-ctl.sh to manage all services in one command:
./scripts/server-ctl.sh start # Start Wake-lock, Nginx, Tunnel, and Watchdog
./scripts/server-ctl.sh status # Inspect real-time status of all daemons
./scripts/server-ctl.sh restart # Cleanly cycle all services
./scripts/server-ctl.sh stop # Gracefully stop everything and release wake-lockMIT License. Free to use, modify, and distribute.