---
title: "Claude Code + MCP Server: 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 MCP Server cho Claude Code trên VPS NVMe với Nginx Reverse Proxy chuẩn HTTPS, hỗ trợ SSE/Streamable HTTP và chứng chỉ SSL tự động."
canonical: "https://thuecloud.vn/claude-code-mcp-server-huong-dan-cai-dat-chuan-https-va-nginx-reverse-proxy-tren-vps-nvme"
markdown_url: "https://thuecloud.vn/claude-code-mcp-server-huong-dan-cai-dat-chuan-https-va-nginx-reverse-proxy-tren-vps-nvme.md"
locale: "vi"
kind: "article"
published_at: "2026-11-22T16:18:14.297Z"
updated_at: "2026-11-22T16:18:12.867Z"
site: "ThueCloud.Vn"
estimated_tokens: 1900
---
# Claude Code + MCP Server: 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 MCP Server cho Claude Code trên VPS NVMe với Nginx Reverse Proxy chuẩn HTTPS, hỗ trợ SSE/Streamable HTTP và chứng chỉ SSL tự động.

- Canonical HTML: https://thuecloud.vn/claude-code-mcp-server-huong-dan-cai-dat-chuan-https-va-nginx-reverse-proxy-tren-vps-nvme
- Markdown URL: https://thuecloud.vn/claude-code-mcp-server-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

- Cấu hình Nginx Reverse Proxy chuẩn cho MCP Server
- Bật HTTPS tự động với Certbot và kết nối từ Claude Code
- Câu hỏi thường gặp (FAQ)
  - Tại sao MCP Server chạy trên Docker lại bị lỗi 502 Bad Gateway qua Nginx?
  - Có cần mở thêm port 3100 trên tường lửa UFW không?
  - Làm sao kiểm tra luồng SSE qua Nginx có bị buffering không?

Khi mở rộng **Claude Code** kết nối tới các công cụ nội bộ (Database, Git, Jira, Monitoring) thông qua **Model Context Protocol (MCP)** chạy từ xa trên [VPS Việt Nam](https://thuecloud.vn/vps-viet-nam), việc truyền dữ liệu trực tiếp qua HTTP thuần không mã hóa là rủi ro bảo mật lớn. Thiết lập **Nginx Reverse Proxy chuẩn HTTPS** phía trước MCP Server giúp mã hóa toàn bộ luồng SSE/Streamable HTTP và hỗ trợ xác thực tập trung.

> **Tóm tắt nhanh (TL;DR):**
> - Chạy MCP Server bind nội bộ tại `127.0.0.1:3100` (không mở port trực tiếp ra Internet).
> - Cấu hình Nginx Reverse Proxy dùng **HTTP/1.1**, tắt `proxy_buffering off;` và tăng `proxy_read_timeout 3600s` để luồng SSE/Streamable HTTP không bị ngắt giữa chừng.
> - Cấp chứng chỉ SSL Let's Encrypt tự động bằng Certbot và kết nối qua [Proxy USA sạch](https://thuecloud.vn/proxy-usa) nếu cần gọi API Anthropic ổn định.
> - *Cập nhật: 11/2026*

## 1. Cấu hình Nginx Reverse Proxy chuẩn cho MCP Server

MCP remote transport (SSE và Streamable HTTP) giữ kết nối mở lâu để server đẩy tool result và notification về Claude Code client. Nếu giữ cấu hình Nginx mặc định, sau 60 giây không có dữ liệu, Nginx sẽ tự ngắt kết nối với lỗi `504 Gateway Timeout` hoặc `ECONNRESET`.

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

```nginx
server {
    listen 80;
    server_name mcp.example.vn;

    location / {
        proxy_pass http://127.0.0.1:3100;
        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_set_header Connection "";

        # Bắt buộc tắt buffering cho luồng SSE / Streamable HTTP
        proxy_buffering off;
        proxy_cache off;
        chunked_transfer_encoding on;
        proxy_read_timeout 3600s;
        proxy_send_timeout 3600s;
    }
}
```

## 2. Bật HTTPS tự động với Certbot và kết nối từ Claude Code

Kích hoạt cấu hình và cấp SSL miễn phí:

```bash
sudo ln -s /etc/nginx/sites-available/mcp.conf /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d mcp.example.vn
```

Sau đó trên máy trạm, đăng ký remote MCP server vào Claude Code:

```bash
claude mcp add --transport http my-remote-mcp https://mcp.example.vn/mcp \
  --header "Authorization: Bearer YOUR_STRONG_TOKEN"
```

| Thông số Nginx | Giá trị mặc định | Giá trị khuyến nghị cho MCP | Lý do kỹ thuật |
|---|---|---|---|
| `proxy_buffering` | `on` | `off` | Đẩy token/event ngay lập tức, không bị kẹt buffer |
| `proxy_read_timeout` | `60s` | `3600s` | Giữ phiên SSE/Streamable HTTP khi tác vụ chạy lâu |
| `proxy_http_version` | `1.0` | `1.1` | Hỗ trợ keep-alive và chunked transfer chuẩn |

Để hệ thống vận hành toàn diện, bạn nên kết hợp [kỹ thuật Geo-Testing qua Proxy SOCKS5/HTTP](https://thuecloud.vn/ky-thuat-toi-uu-ket-noi-proxy-cho-chay-kiem-thu-da-vung-dia-ly-geo-testing-qua-giao-thuc-socks5-http), [checklist ứng cứu LFI / Directory Traversal](https://thuecloud.vn/checklist-ung-cuu-khan-cap-khi-he-thong-bi-tan-cong-lfi-directory-traversal) và tham khảo [so sánh SQL Server vs PostgreSQL trên Windows](https://thuecloud.vn/so-sanh-sql-server-vs-postgresql-tren-windows-2026-hieu-nang-chi-phi-va-kich-ban-nen-chon) nếu MCP Server truy vấn cơ sở dữ liệu doanh nghiệp.

> **Triển khai Claude Code + MCP Server mượt mà tại ThueCloud.Vn:**
> Dựng MCP Server độ trễ thấp trên **VPS KVM Enterprise NVMe** tại `vn-hn`: **VPS VN 1** (`45.000đ` - `60.000đ/tháng`) cho MCP nhẹ hoặc **VPS VN 2** (`78.000đ` - `90.000đ/tháng`, 4 GB RAM) khi chạy kèm Docker/Database, kết hợp **Proxy USA** từ `70.000đ/tháng`. Cam kết **SLA 99,9%**, **VAT 0%**, **hoàn tiền 07 ngày** — xem tại [bảng giá](https://thuecloud.vn/pricing) và [giải pháp AI Automation](https://thuecloud.vn/giai-phap).

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

### Tại sao MCP Server chạy trên Docker lại bị lỗi 502 Bad Gateway qua Nginx?
Do MCP Server trong container đang lắng nghe `127.0.0.1` bên trong container thay vì `0.0.0.0:3100`. Hãy sửa bind address của app thành `0.0.0.0` và chỉ publish ra host bằng `-p 127.0.0.1:3100:3100`.

### Có cần mở thêm port 3100 trên tường lửa UFW không?
Không nên mở port 3100 ra ngoài Internet. Chỉ cần mở port `80` và `443` cho Nginx; mọi lưu lượng vào MCP Server đều đi qua lớp HTTPS và xác thực Bearer Token tại Nginx/App.

### Làm sao kiểm tra luồng SSE qua Nginx có bị buffering không?
Dùng lệnh `curl -N -H "Accept: text/event-stream" https://mcp.example.vn/sse`; nếu dữ liệu in ra từng dòng ngay lập tức thay vì dồn một cục sau vài giây là Nginx đã tắt buffering thành công.

## References / Sources

- https://modelcontextprotocol.io/specification/2025-03-26/basic/transports
- https://docs.anthropic.com/en/docs/claude-code/mcp
- 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)
