---
title: "LiteLLM Proxy Gateway: Hướng dẫn cài đặt chuẩn HTTPS và Nginx Reverse Proxy trên VPS NVMe"
description: "Hướng dẫn triển khai LiteLLM Proxy Gateway chuẩn OpenAI API trên VPS NVMe Docker, cấu hình Nginx Reverse Proxy HTTPS và định tuyến đa model AI an toàn."
canonical: "https://thuecloud.vn/litellm-proxy-gateway-huong-dan-cai-dat-chuan-https-va-nginx-reverse-proxy-tren-vps-nvme"
markdown_url: "https://thuecloud.vn/litellm-proxy-gateway-huong-dan-cai-dat-chuan-https-va-nginx-reverse-proxy-tren-vps-nvme.md"
locale: "vi"
kind: "article"
published_at: "2026-11-22T16:18:12.375Z"
updated_at: "2026-11-22T16:18:10.011Z"
site: "ThueCloud.Vn"
estimated_tokens: 2192
---
# LiteLLM Proxy Gateway: Hướng dẫn cài đặt chuẩn HTTPS và Nginx Reverse Proxy trên VPS NVMe

> Hướng dẫn triển khai LiteLLM Proxy Gateway chuẩn OpenAI API trên VPS NVMe Docker, cấu hình Nginx Reverse Proxy HTTPS và định tuyến đa model AI an toàn.

- Canonical HTML: https://thuecloud.vn/litellm-proxy-gateway-huong-dan-cai-dat-chuan-https-va-nginx-reverse-proxy-tren-vps-nvme
- Markdown URL: https://thuecloud.vn/litellm-proxy-gateway-huong-dan-cai-dat-chuan-https-va-nginx-reverse-proxy-tren-vps-nvme.md
- Organization: ThueCloud.Vn
- Support Email: support@thuecloud.vn
- Hotline: 03333 499 48
- Published: 2026-11-22
- Updated: 2026-11-22

## Mục lục

- Bước 1: Chuẩn bị config.yaml và Docker Compose cho LiteLLM
- Bước 2: Cấu hình Nginx Reverse Proxy và SSL Let's Encrypt
- Bảng đối chiếu thông số vận hành LiteLLM Gateway
- Câu hỏi thường gặp (FAQ)
  - LiteLLM Proxy Gateway cần tối thiểu bao nhiêu RAM để chạy ổn định cùng PostgreSQL?
  - Có thể dùng LiteLLM để tự động chuyển dự phòng (fallback) từ OpenAI sang Claude/Gemini khi gặp lỗi 429 không?
  - Làm sao truy cập giao diện Admin UI của LiteLLM sau khi cài xong?

**LiteLLM Proxy Gateway** cho phép doanh nghiệp gom toàn bộ các nhà cung cấp AI (OpenAI, Anthropic Claude, Google Gemini, Azure, Ollama) về một chuẩn giao thức OpenAI API duy nhất, kèm quản lý ngân sách, virtual key và ghi nhận mức dùng token tập trung. Triển khai LiteLLM trên [VPS Việt Nam](https://thuecloud.vn/vps-viet-nam) dùng ổ NVMe phía sau Nginx HTTPS giúp mọi ứng dụng nội bộ và AI Agent kết nối an toàn mà không phải chia sẻ key gốc.

> **Tóm tắt nhanh (TL;DR):**
> - Chạy LiteLLM Proxy qua Docker Compose kết hợp PostgreSQL để lưu trữ Virtual Keys, log chi tiêu và giới hạn ngân sách theo từng team.
> - Bind cổng LiteLLM (`4000`) vào `127.0.0.1:4000` và cấu hình Nginx Reverse Proxy HTTPS tắt `proxy_buffering off` để stream token mượt mà.
> - Định tuyến các request đi ra API quốc tế qua [Proxy USA](https://thuecloud.vn/proxy-usa) khi cần ổn định kết nối và tránh chặn IP datacenter.
> - *Cập nhật: 11/2026*

## Bước 1: Chuẩn bị `config.yaml` và Docker Compose cho LiteLLM

Tạo thư mục `/opt/litellm` và file `litellm_config.yaml` khai báo danh sách model muốn định tuyến:

```yaml
model_list:
  - model_name: gpt-4o-mini
    litellm_params:
      model: openai/gpt-4o-mini
      api_key: os.environ/OPENAI_API_KEY
  - model_name: claude-sonnet
    litellm_params:
      model: anthropic/claude-3-7-sonnet-latest
      api_key: os.environ/ANTHROPIC_API_KEY

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  database_url: os.environ/DATABASE_URL
```

Tạo file `docker-compose.yml` đi kèm PostgreSQL và giới hạn RAM chặt chẽ:

```yaml
services:
  litellm-db:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_DB: litellm
      POSTGRES_USER: litellm
      POSTGRES_PASSWORD: StrongDbPassword2026!
    volumes:
      - ./pgdata:/var/lib/postgresql/data

  litellm:
    image: ghcr.io/berriai/litellm:main-stable
    restart: unless-stopped
    depends_on:
      - litellm-db
    ports:
      - "127.0.0.1:4000:4000"
    volumes:
      - ./litellm_config.yaml:/app/config.yaml:ro
    environment:
      - LITELLM_MASTER_KEY=sk-master-noi-bo-2026
      - DATABASE_URL=postgresql://litellm:StrongDbPassword2026!@litellm-db:5432/litellm
      - OPENAI_API_KEY=sk-proj-xxx
      - ANTHROPIC_API_KEY=sk-ant-xxx
    command: ["--config", "/app/config.yaml", "--port", "4000", "--num_workers", "2"]
    deploy:
      resources:
        limits:
          memory: 1536M
```

Khởi chạy bằng `docker compose up -d`. Nếu bạn cần mở rộng kiến trúc cho nhiều agent nội bộ, xem thêm [giải pháp hạ tầng AI](https://thuecloud.vn/giai-phap).

## Bước 2: Cấu hình Nginx Reverse Proxy và SSL Let's Encrypt

Tạo file `/etc/nginx/sites-available/litellm.conf`:

```nginx
server {
    listen 80;
    server_name llm.example.com;

    client_max_body_size 25M;

    location / {
        proxy_pass http://127.0.0.1:4000;
        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_buffering off;
        proxy_cache off;
        proxy_read_timeout 300s;
    }
}
```

Chạy `sudo nginx -t && sudo systemctl reload nginx` rồi cấp chứng chỉ HTTPS bằng `sudo certbot --nginx -d llm.example.com --redirect`.

## Bảng đối chiếu thông số vận hành LiteLLM Gateway

| Thông số | Giá trị mặc định | Khuyến nghị Production | Lý do kỹ thuật |
| :--- | :--- | :--- | :--- |
| **`--num_workers`** | `1` | `2 – 4` (theo số vCPU) | Tránh nghẽn khi nhiều ứng dụng gọi stream đồng thời |
| **`proxy_read_timeout`** | `60s` | `300s` | Đủ thời gian cho các mô hình suy luận sâu trả lời xong |
| **`LITELLM_MASTER_KEY`** | Bắt buộc tự đặt | Chuỗi ngẫu nhiên `sk-...` dài >= 32 ký tự | Chỉ dùng cho admin tạo Virtual Key, không phát cho dev/app |

Để hoàn thiện hệ thống bảo mật và mạng cho gateway, bạn có thể tham khảo thêm [bảo mật với Rkhunter + Chkrootkit chuẩn production](https://thuecloud.vn/bao-mat-voi-rkhunter-chkrootkit-huong-dan-cai-dat-va-kich-hoat-quy-tac-bao-ve-chuan-production), [cách giới hạn băng thông và kết nối đồng thời trên 3proxy](https://thuecloud.vn/huong-dan-3proxy-gioi-han-bang-thong-va-ket-noi-dong-thoi) hoặc [tối ưu RAM, CPU và tường lửa cho win-acme SSL IIS](https://thuecloud.vn/toi-uu-ram-cpu-va-tuong-lua-cho-win-acme-ssl-iis-chay-on-dinh-24-7).

> **Triển khai LiteLLM Proxy Gateway tốc độ cao tại ThueCloud.Vn:**
> Toàn bộ **VPS KVM Enterprise NVMe** tại `vn-hn` giúp PostgreSQL và Python worker của LiteLLM phản hồi cực nhanh, đi kèm **VAT 0%**, **SLA 99,9%** và **hoàn tiền 07 ngày**. Chọn ngay gói **VPS VN 2** (`78.000đ`/`90.000đ`) hoặc **VPS VN 3** (`139.000đ`/`170.000đ`) cùng **Proxy USA** từ `70.000đ/tháng` tại [bảng giá](https://thuecloud.vn/pricing).

## Câu hỏi thường gặp (FAQ)

### LiteLLM Proxy Gateway cần tối thiểu bao nhiêu RAM để chạy ổn định cùng PostgreSQL?
Với 2 worker và PostgreSQL đi kèm, mức an toàn tối thiểu là 2 GB RAM (VPS VN 2); nếu phục vụ cả công ty 20–50 nhân sự kèm UI Admin Dashboard và ghi log chi tiết, nên dùng 4 GB RAM (VPS VN 3).

### Có thể dùng LiteLLM để tự động chuyển dự phòng (fallback) từ OpenAI sang Claude/Gemini khi gặp lỗi 429 không?
Có. Trong `litellm_config.yaml`, bạn chỉ cần khai báo danh sách `fallbacks` hoặc đặt cùng một `model_name` cho nhiều deployment để LiteLLM tự động cân bằng tải và chuyển hướng khi một provider bị rate-limit.

### Làm sao truy cập giao diện Admin UI của LiteLLM sau khi cài xong?
Sau khi bật HTTPS, bạn truy cập `https://llm.example.com/ui` và đăng nhập bằng tài khoản admin / `LITELLM_MASTER_KEY` để tạo Virtual Key và theo dõi chi phí theo từng dự án.

## References / Sources

- https://docs.litellm.ai/docs/proxy/docker_quick_start
- https://nginx.org/en/docs/http/ngx_http_proxy_module.html

---

## Navigation & Machine-Readable Endpoints

- [Site Summary (llms.txt)](https://thuecloud.vn/llms.txt)
- [Full Technical Reference (llms-full.txt)](https://thuecloud.vn/llms-full.txt)
- [Pricing Catalog (Markdown)](https://thuecloud.vn/pricing.md)
- [Blog & Technical Guides (Markdown)](https://thuecloud.vn/blog.md)
- [XML Sitemap](https://thuecloud.vn/sitemap.xml)
