
Rust WebRTC P2P #11 - Nginx Config + Deploy Live on VPS
Chúng ta đưa Signaling Server từ local lên VPS thực tế → Cấu hình domain → Setup Nginx → Thiết lập HTTPS (SSL)
1. Cấu hình Domain
2. Cài đặt Nginx
- Cài đặt trên Linux (Debian / CentOS)
- Kiểm tra hoạt động:
+ Port 80 (HTTP)
+ Port 443 (HTTPS)
3. Deploy ứng dụng Rust
- Cài đặt Rust trên VPS
- Build ứng dụng
- Upload:
+ File executable
+ Thư mục config
→ Sử dụng SFTP
- Chạy server:
+ Ví dụ port 1006
+ Thiết lập biến môi trường
4. Nginx Reverse Proxy & SSL
- Tạo SSL với Cloudflare Origin Server
- Cấu hình Nginx:
+ Redirect HTTP → HTTPS
+ Reverse proxy về port 1006
- Quan trọng:
+ Cấu hình header để hỗ trợ WebSocket
→ Upgrade connection
server
{
listen 80;
server_name test-p2p.bytebuffer.co;
return 301 https://$host$request_uri;
}
server
{
client_max_body_size 20M;
listen 443 ssl;
ssl_certificate /root/ssl/bytebuffer.co/certificate.pem;
ssl_certificate_key /root/ssl/bytebuffer.co/private-key.pem;
server_name test-p2p.bytebuffer.co;
root /usr/share/nginx/bytebuffer-p2p;
index index.php index.html index.htm;
location = /call
{
proxy_pass http://127.0.0.1:10006/call;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_read_timeout 300s;
}
location /
{
proxy_pass http://127.0.0.1:10006/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_request_buffering off;
proxy_read_timeout 300s;
proxy_connect_timeout 300s;
proxy_send_timeout 300s;
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;
}
}5. Test thực tế
- Test login qua domain thật
→ Kiểm tra response và log
- Test WebSocket:
→ Kết nối qua domain
→ Kiểm tra cookie authentication
6. Kết quả đạt được:
- Deploy thành công ứng dụng Rust lên VPS
- Cấu hình domain + HTTPS hoàn chỉnh
- Thiết lập reverse proxy cho WebSocket
- Sẵn sàng chạy production cho WebRTC
Khóa học thực chiến giúp bạn xây dựng từ đầu một Signaling Server bằng Rust, xử lý các cuộc gọi audio/video trực tiếp giữa hai trình duyệt thông qua WebRTC Peer-to-Peer mà không cần Media Server. Bạn sẽ nắm vững kiến trúc WebRTC signaling, cách trao đổi SDP Offer/Answer và ICE Candidates giữa các peer thông qua WebSocket. Khóa học sử dụng Axum + Tokio cho backend, MongoDB để lưu trữ dữ liệu, và JWT để xác thực người dùng. Đây là Phần 1 trong series 7 phần về Lập trình Rust với VoIP, bao gồm: WebRTC P2P, Media Server (Janus, LiveKit, Kurento, Asterisk, FreePBX), và hệ thống CRM/Queue/nhạc chờ/chuyển tiếp cuộc gọi. Yêu cầu tiên quyết: Kiến thức cơ bản về Rust (Ownership, Lifetimes, Traits, Async/Await).
Công nghệ sử dụng
Tác giả
ByteBuffer
Coder cỏ tại DTS Group và IPA Solutions
Chuyên gia về Rust và hệ thống VoIP/WebRTC. Nhiều năm kinh nghiệm xây dựng các hệ thống real-time communication với hiệu năng cao và độ trễ thấp.
Bài học
16 bàiRust WebRTC P2P #1 - Giới thiệu khóa học
5:29
Rust WebRTC P2P #2 - VoIP là gì? WebRTC là gì?
7:13
Rust WebRTC P2P #3 - SIP overview + Why choose Rust
3:23
Rust WebRTC P2P #4 - Install Rust + RustRover + Cargo Commands
7:36
Rust WebRTC P2P #5 - Hello World + Tokio Runtime + Cargo.toml
5:13
Rust WebRTC P2P #6 - Axum Server + Config Loading
42:44
Rust WebRTC P2P #7 - MongoDB + Logging with log4rs
15:44
Rust WebRTC P2P #8 - Create WebSocket Endpoint with Axum
15:45
Rust WebRTC P2P #9 - ConnectionState — Client Online management
8:46
Rust WebRTC P2P #10 - Message Routing — Dispatcher Pattern
9:37
Rust WebRTC P2P #11 - Nginx Config + Deploy Live on VPS
16:28
Rust WebRTC P2P #12 - User Model + MongoDB Queries
4:34
Rust WebRTC P2P #13 - Login Service + JWT + Argon2
22:03
Rust WebRTC P2P #14 - Auth Middleware HTTP + WebSocket Auth Flow
50:35
Rust WebRTC P2P #15 - Demo Login + WebSocket Auth từ Postman
5:12
Rust WebRTC P2P #16 - State Pattern — P2PCallStateHandler Trait
12:04
Khóa học liên quan
Xem tất cảRust VoIP: Freeswitch Media Server
Khám phá sức mạnh của FreeSWITCH trong việc xây dựng hệ thống VoIP production-ready. Từ nền tảng WebRTC P2P, bạn sẽ tiến tới kiến trúc Media Server có khả năng scale lớn, xử lý hàng nghìn cuộc gọi đồng thời.
Rust VoIP: Asterisk Media Server
Làm chủ công nghệ VoIP với khóa học "Lập trình VoIP với Rust: Asterisk Media Server". Vượt qua những giới hạn của WebRTC P2P để xây dựng hệ thống tổng đài và media server chuyên nghiệp. Khám phá sức mạnh của Asterisk kết hợp cùng Rust để xử lý các bài toán quy mô lớn, từ gọi App-to-App đến tích hợp hệ thống SIP và Auto Callout mạnh mẽ.
Rust VoIP: Janus Media Server
Chinh phục VoIP với khóa học "Lập trình VoIP với Rust: Janus Media Server". Bước tiếp từ nền tảng WebRTC P2P để xây dựng các hệ thống Media Server quy mô lớn, có khả năng scale thực tế và dùng trong production. Bạn sẽ làm chủ Janus Audiobridge để giải quyết triệt để các bài toán về băng thông, ghi âm tập trung và kết nối đa phương thức từ App-to-App đến SIP