Rust WebRTC P2P #11 - Nginx Config + Deploy Live on VPS
Bài 1116:28

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

- Trỏ subdomain về IP VPS

→ Sử dụng DNS A record

- Ví dụ:

test.bytebuffer.com → IP server

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

RustWebRTCVoIPP2PAxumTokioWebSocketMongoDBJWT

Tác giả

ByteBuffer

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.