Self-hosting Stable Diffusion on a Hong Kong VPS gives Asia-Pacific teams a private, low-latency image generation API — without the per-image pricing of Midjourney or Adobe Firefly, without sending prompts and generated images to US cloud servers, and with the flexibility to run any open-source model (SDXL, FLUX, Stable Diffusion 3.5) fine-tuned for specific styles or subject matter.
This guide covers deploying AUTOMATIC1111 WebUI (the most widely used interface) and the ComfyUI API backend on a Hong Kong VPS, including CPU-only deployment for budget plans and GPU configuration for production throughput.
Hardware Reality: CPU vs GPU Inference
Stable Diffusion inference speed is dominated by available GPU VRAM. Understanding the trade-offs upfront:
| Configuration | Model | 512×512 generation time | Use case |
|---|---|---|---|
| CPU only (8 vCPU) | SD 1.5 | 3–8 minutes | Low-volume, batch overnight |
| CPU only (8 vCPU) | SDXL | 20–40 minutes | Not practical for real-time |
| GPU (NVIDIA T4, 16 GB VRAM) | SDXL | 8–15 seconds | API service, small team |
| GPU (NVIDIA A100, 80 GB VRAM) | FLUX.1 | 3–6 seconds | Production API, high volume |
CPU-only deployment is practical for batch image generation tasks (overnight product photography, asset pipeline jobs) but unsuitable for real-time applications. For an API serving interactive users, a GPU-enabled VPS or dedicated server is required.
Server.HK’s dedicated server configurations include GPU options for production image generation workloads. For exploration, development, and low-volume batch use, the CPU deployment below works on any standard VPS.
Step 1: System Preparation
apt update && apt upgrade -y
apt install -y python3 python3-pip python3-venv git wget curl \
libglib2.0-0 libsm6 libxrender1 libxext6 libgl1
# Create dedicated user for SD
useradd -m -s /bin/bash sduser
su - sduserStep 2A: Install AUTOMATIC1111 WebUI (CPU Mode)
cd ~
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui
# Download a model (SD 1.5 — smallest practical model, ~2 GB)
mkdir -p models/Stable-diffusion
wget -O models/Stable-diffusion/v1-5-pruned-emaonly.safetensors \
https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensorsCreate a launch script optimised for CPU-only operation:
cat > launch-cpu.sh << 'EOF'
#!/bin/bash
python3 launch.py \
--skip-torch-cuda-test \
--precision full \
--no-half \
--use-cpu all \
--listen \
--port 7860 \
--api \
--nowebui
EOF
chmod +x launch-cpu.sh# Install dependencies and launch
python3 -m venv venv
source venv/bin/activate
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
./launch-cpu.shFirst launch downloads additional dependencies and takes 5–10 minutes. Subsequent launches are faster.
Step 2B: Install ComfyUI (API-First, More Efficient)
ComfyUI is the preferred backend for API use cases — lower overhead than AUTOMATIC1111, JSON-based workflow API, and better memory management for CPU inference:
cd ~
git clone https://github.com/comfyanonymous/ComfyUI.git
cd ComfyUI
python3 -m venv venv
source venv/bin/activate
# CPU-only PyTorch
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
pip install -r requirements.txt
# Download model
mkdir -p models/checkpoints
wget -O models/checkpoints/sd15.safetensors \
https://huggingface.co/runwayml/stable-diffusion-v1-5/resolve/main/v1-5-pruned-emaonly.safetensors
# Launch
python3 main.py --listen 0.0.0.0 --port 8188 --cpuStep 3: Expose as a Secured API via Nginx
Never expose the WebUI port (7860 or 8188) directly to the internet. Add Nginx with authentication:
exit # Return to root
apt install nginx apache2-utils certbot python3-certbot-nginx -y
# Create API password
htpasswd -c /etc/nginx/.htpasswd apiuser
cat > /etc/nginx/sites-available/sdapi << 'EOF'
server {
listen 80;
server_name sdapi.yourdomain.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name sdapi.yourdomain.com;
ssl_certificate /etc/letsencrypt/live/sdapi.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/sdapi.yourdomain.com/privkey.pem;
client_max_body_size 50m;
location / {
auth_basic "SD API";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://127.0.0.1:8188;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 600s; # Long timeout for CPU generation
}
}
EOF
ln -s /etc/nginx/sites-available/sdapi /etc/nginx/sites-enabled/
certbot --nginx -d sdapi.yourdomain.com
nginx -t && systemctl reload nginxStep 4: Generate Images via API
AUTOMATIC1111 API
import requests, base64
response = requests.post(
"https://sdapi.yourdomain.com/sdapi/v1/txt2img",
auth=("apiuser", "your_password"),
json={
"prompt": "Hong Kong skyline at night, photorealistic, 8k",
"negative_prompt": "blurry, low quality",
"steps": 20,
"width": 512,
"height": 512,
"cfg_scale": 7
}
)
image_data = base64.b64decode(response.json()["images"][0])
with open("output.png", "wb") as f:
f.write(image_data)ComfyUI API
import requests, json, uuid
# ComfyUI uses a workflow-based JSON API
workflow = {
"3": {
"inputs": {"seed": 42, "steps": 20, "cfg": 7,
"sampler_name": "euler", "scheduler": "normal",
"denoise": 1, "model": ["4", 0],
"positive": ["6", 0], "negative": ["7", 0],
"latent_image": ["5", 0]},
"class_type": "KSampler"
},
"6": {"inputs": {"text": "Hong Kong city, night, cinematic", "clip": ["4", 1]},
"class_type": "CLIPTextEncode"},
"7": {"inputs": {"text": "blurry, low quality", "clip": ["4", 1]},
"class_type": "CLIPTextEncode"}
}
client_id = str(uuid.uuid4())
response = requests.post(
"https://sdapi.yourdomain.com/prompt",
auth=("apiuser", "your_password"),
json={"prompt": workflow, "client_id": client_id}
)Step 5: Run as Systemd Service
cat > /etc/systemd/system/comfyui.service << 'EOF'
[Unit]
Description=ComfyUI Stable Diffusion
After=network.target
[Service]
User=sduser
WorkingDirectory=/home/sduser/ComfyUI
ExecStart=/home/sduser/ComfyUI/venv/bin/python main.py --listen 127.0.0.1 --port 8188 --cpu
Restart=on-failure
RestartSec=10s
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now comfyuiPopular Open-Source Models for Asia-Pacific Use Cases
| Model | Size | Best for | Source |
|---|---|---|---|
| Stable Diffusion 1.5 | 2 GB | General use, CPU feasible | HuggingFace |
| SDXL 1.0 | 6.5 GB | High quality general images | HuggingFace |
| FLUX.1 schnell | 12 GB | Fast, high quality (GPU recommended) | HuggingFace |
| Anything V5 | 2 GB | Anime / illustration style | CivitAI |
| ChilloutMix | 2 GB | Asian portrait photography | CivitAI |
| epiCRealism | 2 GB | Photorealistic people | CivitAI |
Use Cases for Asia-Pacific Teams
- E-commerce product imagery — generate lifestyle backgrounds for product photos; batch-process hundreds of SKUs overnight
- Game asset generation — character concepts, texture variations, environment sketches for game development studios in Hong Kong, Taiwan, and Japan
- Marketing content — generate campaign visuals in brand-consistent styles using fine-tuned LoRA models
- Design prototyping — rapid UI mockup backgrounds, illustration concepts for client presentations
- Data augmentation — generate synthetic training data for computer vision models, particularly for Asian face recognition datasets
Conclusion
Hosting Stable Diffusion on a Hong Kong VPS provides a private, cost-effective image generation pipeline for Asia-Pacific teams — no per-image fees, no US data transfer for proprietary prompts, and low-latency API access from Hong Kong, Taiwan, and mainland China via CN2 GIA routing. CPU-only deployment works for batch jobs and development; GPU-equipped dedicated servers unlock real-time generation throughput for production API services.
Start generating: Browse Server.HK Hong Kong VPS plans for CPU batch workloads, or dedicated server options for GPU-accelerated production image generation.