Skip to content

Self Hosting

Peerix relies on NATS for signaling and TURN for media relay in certain network conditions. You can choose to self-host these servers as part of your deployment, or use managed services provided by Peerix.

Tip

Ensure optimal performance and reliability, and avoid the complexities of self-hosting and maintenance by using production-ready managed servers.

NATS Server

The NATS server is responsible for handling signaling messages between peers. It allows peers to discover each other and exchange messages necessary for establishing peer-to-peer connections. You can use the official NATS server image to set up your own NATS server for development or production use.

Here’s an example of how to set up a NATS server using Docker Compose:

services:
  nats:
    image: nats:latest
    network_mode: host
    command:
      - "--websocket_port=8080" # Enable WebSocket support
      - "--websocket_no_tls" # Use only for local development
      - "--http_port=8222" # Enables the monitoring dashboard

More details on configuring the NATS server can be found in the official NATS documentation.

TURN Server

The TURN server is responsible for relaying media when direct peer-to-peer communication is not possible. This is particularly useful in scenarios where network restrictions, such as NATs or firewalls, prevent direct connections between peers. You can use the popular coturn TURN server to set up your own TURN server for development or production use.

Here’s an example of how to set up a coturn TURN server using Docker Compose:

services:
  coturn:
    image: coturn/coturn:latest
    network_mode: host
    tmpfs:
      - /var/lib/coturn:uid=0,gid=0,mode=1777
    command:
      - "--listening-port=3478"
      - "--realm=peerix.app" # Replace with your own realm
      - "--user=username:password" # Replace with your own credentials
      - "--lt-cred-mech" # Use long-term credential mechanism
      - "--log-file=stdout"
    environment:
      - "DETECT_EXTERNAL_IP=yes" # Enable external IP detection
      - "DETECT_RELAY_IP=yes" # Enable relay IP detection

More details on configuring the coturn TURN server can be found in the official coturn documentation.