0Pricing
Real-Time Streaming Systems (WebRTC + Live Data) · レッスン

独自TURNサーバーのデプロイとセキュリティ保護

coturnでTURNサーバーをセルフホストし、時間制限付きトークンで認証情報を安全に設定し、セルフホストとマネージドTURNサービスのどちらを選ぶべきかを学びます。

「独自TURNサーバーのデプロイとセキュリティ保護」はCoddyKit上の無料Real-Time Streaming Systems (WebRTC + Live Data)レッスンです。 これはレッスン4/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはReal-Time Streaming Systems (WebRTC + Live Data)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Real-Time Streaming Systems (WebRTC + Live Data)コースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

From Theory to Operation

You understand NAT challenges, STUN, and what TURN does. Now you will actually run a TURN server, secure it, and connect WebRTC to it. The most common open-source choice is coturn.

Why Self-Host TURN

Public STUN is free, but TURN relays media and consumes bandwidth, so it is rarely free. Running your own TURN server gives you control over capacity, cost, and privacy.

Installing coturn

On a Linux server you install coturn from the package manager. It runs as a background service.

sudo apt-get update
sudo apt-get install -y coturn
sudo systemctl enable coturn

Basic Configuration

coturn reads /etc/turnserver.conf. A minimal config sets the realm and listening ports.

listening-port=3478
tls-listening-port=5349
realm=turn.example.com
fingerprint

The Credential Problem

TURN requires authentication or anyone could relay traffic through your server at your expense. Hardcoding a static username and password is risky because clients can leak them.

Time-Limited Credentials

The secure approach is the REST/ephemeral credential mechanism. Your server generates short-lived usernames and passwords derived from a shared secret, so leaked credentials expire quickly.

use-auth-secret
static-auth-secret=your_long_shared_secret

Generating a Credential

Your backend creates a username as an expiry timestamp and signs it with HMAC-SHA1 using the shared secret. The signature becomes the password.

const crypto = require('crypto');
function turnCredential(secret, ttl) {
  const username = String(Math.floor(Date.now() / 1000) + ttl);
  const hmac = crypto.createHmac('sha1', secret);
  hmac.update(username);
  const password = hmac.digest('base64');
  return { username, password };
}

Wiring It Into WebRTC

Pass the TURN URL and ephemeral credentials into the peer connection's ICE server list. WebRTC uses them when direct paths fail.

const pc = new RTCPeerConnection({
  iceServers: [{
    urls: 'turn:turn.example.com:3478',
    username: cred.username,
    credential: cred.password
  }]
});

Use TLS and TCP Fallback

Some restrictive networks block UDP entirely. Offer turns: over TCP on port 443 so media can tunnel through firewalls that only allow HTTPS traffic.

// add a TLS/TCP TURN entry alongside the UDP one
urls: 'turns:turn.example.com:443?transport=tcp'

Self-Host vs Managed

Self-hosting coturn is cheaper at scale but means you handle uptime, bandwidth, and security. Managed TURN providers cost more per GB but remove operational burden. Pick based on your team and traffic.

Operating Responsibly

Monitor bandwidth, rotate the shared secret periodically, restrict relay to authenticated users, and place the server geographically near your users to minimize latency. A well-run TURN server is the safety net that makes calls connect everywhere.

Quick Check

Test your understanding of TURN deployment.

Recap

You learned to deploy and secure TURN:

  • Install and configure coturn with a realm and ports
  • Use use-auth-secret with HMAC-based ephemeral credentials
  • Wire credentials into the ICE server list
  • Offer TLS/TCP on 443 for restrictive networks
  • Weigh self-hosting against managed services

A secure TURN server ensures calls connect even behind tough NATs.

よくある質問

「独自TURNサーバーのデプロイとセキュリティ保護」レッスンは無料ですか?

はい。「独自TURNサーバーのデプロイとセキュリティ保護」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Real-Time Streaming Systems (WebRTC + Live Data)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Real-Time Streaming Systems (WebRTC + Live Data)コースには全4レッスンが含まれています。

「独自TURNサーバーのデプロイとセキュリティ保護」で何を学びますか?

coturnでTURNサーバーをセルフホストし、時間制限付きトークンで認証情報を安全に設定し、セルフホストとマネージドTURNサービスのどちらを選ぶべきかを学びます。 ブラウザで直接実行するハンズオンコードでReal-Time Streaming Systems (WebRTC + Live Data)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Real-Time Streaming Systems (WebRTC + Live Data)を始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのReal-Time Streaming Systems (WebRTC + Live Data)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン4/4です。

「独自TURNサーバーのデプロイとセキュリティ保護」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このReal-Time Streaming Systems (WebRTC + Live Data)レッスンでコードを書いて実行できますか?

はい。すべてのReal-Time Streaming Systems (WebRTC + Live Data)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. NATとファイアウォールの課題
  2. STUNサーバーの仕組み
  3. リレー接続のためのTURNサーバー
  4. 独自TURNサーバーのデプロイとセキュリティ保護
← Real-Time Streaming Systems (WebRTC + Live Data)に戻る