NewCode CLOUD — 20% off your first month on all cloud VPSClaim

How to Run Ollama and Local LLMs on a Hong Kong VPS: AI Inference for Asia-Pacific (2026)

· 6 min read

Running local large language models on a Hong Kong VPS solves a problem that affects every developer and business in mainland China and the broader Asia-Pacific region: access to AI inference without dependence on OpenAI, Anthropic, or Google APIs that are either blocked, restricted, or subject to unpredictable availability from China.

Ollama — the most widely used local LLM runtime — turns a Hong Kong VPS into a self-hosted AI inference server. With CN2 GIA routing, Chinese developers and applications can call your self-hosted LLM API at 20–35 ms latency, serving models like LLaMA 3, DeepSeek R2, Mistral, and Qwen as drop-in replacements for OpenAI’s API.

This guide covers Ollama installation, model management, API exposure via Nginx, authentication, and performance benchmarks on CPU-only VPS hardware — the complete setup for production-ready self-hosted AI inference on a Hong Kong VPS.


Hardware Requirements for LLM Inference on VPS

LLM inference on CPU (without GPU) is viable for many use cases — particularly smaller models and batch-tolerant workloads. Understanding the hardware requirements helps you choose the right VPS spec:

Model Parameters Min RAM (Q4 quantised) Recommended vCPU Approx. Tokens/sec (4 vCPU)
Llama 3.2 3B 3B 4 GB 4 vCPU 15–25 tok/s
Llama 3.1 8B 8B 8 GB 4–8 vCPU 8–15 tok/s
DeepSeek R1 7B 7B 8 GB 4–8 vCPU 8–12 tok/s
Mistral 7B 7B 6 GB 4 vCPU 10–18 tok/s
Qwen2.5 7B 7B 6 GB 4 vCPU 10–16 tok/s
Llama 3.1 70B 70B 48 GB 16+ vCPU 1–3 tok/s

Q4 quantisation reduces model size by approximately 75% vs full precision, with minimal quality degradation for most use cases. All token/s figures are CPU-only estimates on modern x86 hardware.

Practical recommendation: For a general-purpose self-hosted AI endpoint accessible from China, a 4 vCPU / 8 GB RAM Hong Kong VPS running Llama 3.1 8B or DeepSeek R1 7B (Q4) handles 1–3 concurrent requests with acceptable response times for non-interactive batch workloads and chat interfaces with short prompts.


Step 1: Install Ollama

curl -fsSL https://ollama.com/install.sh | sh

The installer detects your OS and installs the appropriate Ollama binary. Verify the installation:

ollama --version
systemctl status ollama

Ollama runs as a systemd service, listening on 127.0.0.1:11434 by default — not exposed to the public internet until you configure Nginx in Step 4.


Step 2: Download and Run Models

# Pull a model (downloads to ~/.ollama/models — ensure sufficient disk space)
ollama pull llama3.1:8b

# Pull DeepSeek R1 (excellent for reasoning tasks, popular in China)
ollama pull deepseek-r1:7b

# Pull Qwen2.5 (Alibaba's model, good Chinese language support)
ollama pull qwen2.5:7b

# Pull a smaller model for testing
ollama pull llama3.2:3b

# List downloaded models
ollama list

Test inference locally before exposing via API:

# Interactive chat
ollama run llama3.1:8b

# Single prompt (non-interactive)
ollama run llama3.2:3b "Explain CN2 GIA routing in one paragraph"

Step 3: Test the Ollama API Locally

Ollama exposes an OpenAI-compatible REST API on port 11434:

# Test the API endpoint
curl http://localhost:11434/api/generate \
  -d '{
    "model": "llama3.1:8b",
    "prompt": "What is Hong Kong famous for?",
    "stream": false
  }'

# OpenAI-compatible chat completions endpoint
curl http://localhost:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama3.1:8b",
    "messages": [
      {"role": "user", "content": "Hello, what can you do?"}
    ]
  }'

The /v1/chat/completions endpoint is OpenAI-compatible — any application using the OpenAI Python SDK or HTTP client can switch to your self-hosted endpoint by changing the base URL.


Step 4: Expose Ollama via Nginx with Authentication

Never expose Ollama’s port 11434 directly to the internet — it has no built-in authentication. Use Nginx as a reverse proxy with API key authentication:

apt install -y nginx apache2-utils

# Generate an API key (use this as your bearer token)
openssl rand -hex 32
# Example output: a3f8b2c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1
nano /etc/nginx/sites-available/ollama
server {
    listen 80;
    server_name ai.yourdomain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name ai.yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/ai.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/ai.yourdomain.com/privkey.pem;
    ssl_protocols TLSv1.2 TLSv1.3;

    # Rate limiting — prevent abuse
    limit_req zone=ai_api burst=20 nodelay;
    limit_req_status 429;

    # API key authentication
    # Clients send: Authorization: Bearer YOUR_API_KEY
    set $api_key_valid 0;
    if ($http_authorization = "Bearer a3f8b2c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1") {
        set $api_key_valid 1;
    }
    if ($api_key_valid = 0) {
        return 401 '{"error": "Invalid or missing API key"}';
    }

    # Proxy to Ollama
    location / {
        proxy_pass http://127.0.0.1:11434;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        # Important: LLM inference can be slow — increase timeouts
        proxy_read_timeout 300s;
        proxy_connect_timeout 10s;
        proxy_send_timeout 300s;

        # Streaming support
        proxy_buffering off;
        proxy_cache off;
    }

    access_log /var/log/nginx/ollama.access.log;
    error_log /var/log/nginx/ollama.error.log;
}

Add the rate limiting zone to /etc/nginx/nginx.conf inside the http {} block:

limit_req_zone $binary_remote_addr zone=ai_api:10m rate=10r/s;
ln -s /etc/nginx/sites-available/ollama /etc/nginx/sites-enabled/
certbot --nginx -d ai.yourdomain.com --email your@email.com --agree-tos --no-eff-email
nginx -t && systemctl reload nginx

Step 5: Use with OpenAI-Compatible Clients

Your self-hosted Ollama endpoint is now a drop-in replacement for OpenAI’s API:

Python (OpenAI SDK):

from openai import OpenAI

client = OpenAI(
    base_url="https://ai.yourdomain.com/v1",
    api_key="a3f8b2c1d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1"
)

response = client.chat.completions.create(
    model="llama3.1:8b",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain the benefits of Hong Kong VPS hosting"}
    ]
)

print(response.choices[0].message.content)

Node.js:

import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://ai.yourdomain.com/v1',
  apiKey: 'your_api_key_here'
});

const response = await client.chat.completions.create({
  model: 'deepseek-r1:7b',
  messages: [{ role: 'user', content: 'Hello from Hong Kong!' }]
});

Step 6: Configure Ollama for Production

nano /etc/systemd/system/ollama.service.d/override.conf
[Service]
# Bind only to localhost (Nginx handles external access)
Environment="OLLAMA_HOST=127.0.0.1:11434"

# Limit concurrent requests (prevent OOM on small VPS)
Environment="OLLAMA_MAX_LOADED_MODELS=1"
Environment="OLLAMA_NUM_PARALLEL=2"

# Keep model loaded in memory (avoid reload latency between requests)
Environment="OLLAMA_KEEP_ALIVE=30m"
systemctl daemon-reload
systemctl restart ollama

Step 7: Monitor Inference Performance

# Check Ollama status and loaded models
curl http://localhost:11434/api/ps

# View inference logs
journalctl -fu ollama

# Monitor CPU and RAM during inference
htop

# Benchmark a model
time curl http://localhost:11434/api/generate \
  -d '{"model": "llama3.2:3b", "prompt": "Count from 1 to 20", "stream": false}' \
  | python3 -c "import json,sys; d=json.load(sys.stdin); print(f\"Tokens: {d['eval_count']}, Speed: {d['eval_count']/(d['eval_duration']/1e9):.1f} tok/s\")"

Why Hong Kong VPS Is Ideal for Self-Hosted AI

Beyond the CN2 GIA latency advantage for Chinese users, a Hong Kong VPS provides several AI-specific benefits:

  • No API rate limits or cost per token: Self-hosted inference has no per-call charges — ideal for high-volume applications, internal tools, and development environments
  • No geographic API restrictions: OpenAI, Anthropic, and Google restrict API access from certain regions; a Hong Kong self-hosted endpoint is accessible from anywhere
  • Data privacy: Prompts and responses never leave your server — important for processing sensitive business data or user information that should not be sent to external APIs
  • Model customisation: Fine-tuned or custom models can be deployed — not possible with closed API providers
  • Chinese language models: Qwen2.5 and DeepSeek have superior Chinese language capabilities compared to most Western LLMs — easily deployable via Ollama

Conclusion

Running Ollama on a Hong Kong VPS creates a self-hosted AI inference endpoint accessible with low latency from mainland China and across Asia-Pacific — solving both the API access restriction problem and the latency problem for China-facing AI applications simultaneously.

For the best LLM inference experience, choose a VPS with at least 8 GB RAM and 4 vCPU. Server.HK’s Hong Kong VPS plans include NVMe SSD storage for fast model loading and CN2 GIA routing for low-latency Chinese user access — the right foundation for self-hosted AI infrastructure.


Frequently Asked Questions

Can I run DeepSeek R1 on a Hong Kong VPS?

Yes. DeepSeek R1’s 7B parameter version runs on a 4 vCPU / 8 GB RAM VPS using Q4 quantisation via Ollama. The 7B model achieves 8–12 tokens/second on CPU, suitable for non-interactive use cases. The larger 32B or 70B versions require 32 GB+ RAM and are better suited to dedicated servers.

Is self-hosted LLM inference legal in Hong Kong?

Running open-source LLMs on a Hong Kong VPS for your own use or for your business is entirely legal. Hong Kong has no specific restrictions on operating AI inference infrastructure. Ensure the models you deploy are licensed for your use case — Llama 3, Mistral, DeepSeek, and Qwen all have open licences permitting commercial use with varying conditions.

How does CPU inference speed compare to GPU?

GPU inference is typically 10–50× faster than CPU for LLMs. A 7B model on a modern GPU achieves 50–100+ tokens/second vs 8–15 tokens/second on a 4-core CPU. For interactive chat requiring fast responses, a GPU server is preferable. For batch processing, document analysis, and API calls where 1–2 second response times are acceptable, CPU inference on a VPS is cost-effective and practical.

Related articles

More in VPS & ServersServer setup guides