MediaCP Manual
    1. Getting Started
    2. Sales Questions
    3. Frequently Asked Questions
    4. Transcoder System Benchmarks
    5. Start your own streaming platform
    1. Change account currency
    2. Product Licensing
    1. Introduction
    2. Installation & Upgrade
      1. System Requirements
      2. Versions & Releases
      3. Installation
      4. Upgrading
      5. Streaming Servers
        1. Nginx-Rtmp Video Server
        2. Wowza Streaming Engine
        3. Flussonic Media Server
        4. Video Feature Comparison
        5. Icecast 2 / Icecast KH
        6. Shoutcast 2
      6. SSL Certificates
    3. Billing Integration
      1. WHMCS Integration Guide
      2. Clientexec Integration Guide
      3. Blesta Integration Guide
      4. WiseCP Integration Guide
      5. Billing Platform Comparision
    4. Migrate from other software
      1. Migrate From Centovacast
      2. Migrate From AzuraCast
    5. Backup & Restoration
      1. Backup MediaCP
      2. Restore MediaCP
      3. Transfer to another server
    6. Administration
      1. MediaCP System Commands
      2. Admin Tools
      3. Custom Web Service Configurations
      4. Change MediaCP domain name
      5. Port 80 / 443 Proxy
      6. Move media to another hard disk
      7. Custom Language Translations
      8. Custom Facebook App
      9. Branding Your Panel
      10. Secure your server
      11. Setup CSF Firewall
      12. Troubleshooting Login Errors
      13. Reset Admin Password
    7. Scaling
      1. Scale with Wowza and CloudFront CDN
      2. Nginx-Rtmp with CloudFront CDN
      3. Nginx-Rtmp with CDN Proxy
    8. Troubleshooting
      1. Grant access to support team
      2. Troubleshooting Wowza Streaming Engine
      3. FTP Troubleshooting
      4. MySQL Database Troubleshooting
      5. Reporting Troubleshooting
      6. Troubleshooting Liquidsoap AutoDJ
      7. Video Relay Troubleshooting
      8. Disk Troubleshooting
    1. Introduction
    2. Administrators Dashboard
    3. System Configuration
      1. General
      2. Services
      3. Video Players
      4. Albums
      5. Email
      6. Plugins
      7. Statistics
      8. Backups
      9. Custom HTML
      10. Misc
    4. Customer Accounts
      1. Managing existing Customers
      2. Create a new Customer
      3. Deleting a Customer
      4. Login as another Customer
      5. Send email to Customer
      6. Reset Customer Password
    5. Reseller Accounts
      1. Reseller Plans
      2. Create a Reseller Account
    6. Administrator Accounts
      1. Create a new Administrator
    7. Media Services
      1. Creating a Media Service
      2. Deleting a Media Service
    8. Announcements
      1. Managing Announcements
      2. Creating Announcement
      3. Deleting Announcement
    9. Statistics
    10. Software Health
    11. Software Updates
    12. Email Templates
    13. API
    1. Introduction
    2. Audio Operation Manual
      1. Basics 101
      2. Station Overview
      3. Media Library
      4. Playlists
        1. General Rotation
        2. Jingles & Advertising
        3. Scheduling
        4. Repeat Protection
      5. Live DJ Connections
      6. Live Stream Recording
      7. DJ Manager
      8. Country Blocking
      9. Fallback, Backup and Intro Files
      10. Stream Proxy
      11. AutoDJ Crossfade
      12. Public Page
      13. HTML5 Player
      14. Stream Authentication
      15. Widgets & Links
      16. Reporting
    3. Video Operation Manual
      1. Basics 101
      2. Service Overview
      3. Scheduling
      4. File Manager
      5. Streaming to Your Service
      6. Stream Targets
      7. GeoIP Country Locking
      8. Public Page
      9. Widgets & Links
      10. Reporting
    4. Reseller Operations Manual
      1. Reseller Dashboard
      2. Customers
      3. Media Services
    5. API
    1. Custom Domain Names
    2. Shoutcast 2 Admin Guide
    3. Wowza and Flussonic on same system
    4. Submit a feature request
    1. Getting started with Audio Streaming
    2. Icecast Live Broadcasting
    3. Shoutcast 2 Live Broadcasting
    4. Broadcasting with AutoDJ
    5. DJ Accounts
    6. GeoIP Country Locking
    7. HTML5 Audio Player
    8. Mount Points
    9. Managing Your Media
    10. Managing Media Using FTP
    11. Statistics
    12. Shoutcast 2 Premium
    1. Getting started with video streaming
    2. Live Streaming Overview
    3. TV Station Overview
    4. Ondemand Video Streaming
    5. Relay & IP Camera
    6. Stream Recording
    7. GeoIP Country Locking
    8. VAST Advertising
    9. Connecting your encoder
    10. Preparing Your Media Files
    11. Managing Media Using FTP
    12. Understanding Video Playlists
    13. Embedding player on your website
    14. Smooth Streaming and Content Transition
    15. Video Transcoding (Adaptive Bitrate Streaming)
    16. Stream Watermark​
    17. Statistics
    18. DVR Rewind
    19. Facebook Live Streaming
    20. Youtube Stream Publishing
    21. Twitch Stream Publishing
    22. Shoutcast 2 Stream Publishing
    23. Icecast Stream Publishing
    24. RTMP Stream Publishing
    1. Cloud Video Overview
    2. Admin Manual - Cloud Video
      1. Login to your cloud platform
      2. Dashboard - A First Look
      3. Branding your platform
      4. Team & Staff Members
      5. Plans & Customers
      6. WHMCS Billing Provisioning Module
      7. Activating VOD on Customer Plan
      8. API
    3. User Manual - Cloud Video
      1. Login to your video platform
      2. First Look
      3. Creating a Channel
      4. Channel Overview
      5. Broadcasting
      6. Recording
      7. Media Content
      8. Live Events
      9. Fallback Video
      10. 30 Minute Rewind
      11. TV Channels - 24x7 UGC
        1. TV Event Scheduling
        2. Channel Guide Widgets
      12. Relay Channels
      13. Video on Demand
      14. VOD Playlists
      15. Publishing
      16. Viewing Analytics
      17. Bandwidth Utilisation
      18. Publish Zoom Meetings
      19. Advertising
      20. Restreaming IP Cameras
    4. Video Guide Series
    5. Streaming Best Practices
    6. Feature Comparison
    7. Roadmap & Release Notes
Nginx-Rtmp with CDN Proxy

Last updated 2 weeks ago

This guide will walk you through setting up an NGINX proxy server that forwards requests to another server URL. We’ll optimize it for HTTP Live Streaming (HLS) content by configuring caching for .m3u8 and .ts files.

MediaCP is capable of deploying Nginx-Rtmp through a CDN to allow for this increased capacity and reliability.

Pros & Cons

Benefits

  • Increase Viewers Capacity beyond the limitations of a single server, with minimal cost
  • Reliable Streaming – CDNs typically cache content at edges around the world which means fast and reliable acaess to the broadcast from any location in the world.

Limitations

  • Connections and Statistics Information is not available from MediaCP. The information may be available from your CDN service. For this reason it is typically best suited to serve a single customer per server instance.
  • It is not possible to see or limit the number of viewers on a CDN enabled stream.

Cost

Compatibility with the MediaCP requires an add-on to be enabled on your MediaCP license. Contact our Billing & Support department to enable the CDN add-on. Please note additional costs may apply.

How to Set Up an NGINX Proxy for HLS Content

Prerequisites

The Nginx Proxy should be installed on a server external to your MediaCP installation, in order to proxy requests through to the MediaCP server. We recommend deploying the latest stable release of Ubuntu, Debian, CentOS, RHEL, or similar.

For SSL we recommend using CloudFlare or AWS Certificate Manager to automate certificate deployment. We will include steps for CloudFlare in this document.

Step 1: Install Nginx

Install NGINX using the commands relevant to your operating system below.

Ubuntu/Debian

sudo apt update
sudo apt install nginx certbot python3-certbot-dns-cloudflare

CentOS/RHEL/AlmaLinux

sudo yum install epel-release
sudo yum install nginx certbot python3-certbot-dns-cloudflare

Step 2: Configure DNS API Credentials

Create a credentials file for your DNS provider. For Cloudflare, it might look like the below.
  1. Generate CloudFlare API Token
  2. Create a file named cloudflare.ini:
    touch ~/cloudflare.ini
    
  3. Add your Cloudflare API token to the file:
    dns_cloudflare_api_token = your_cloudflare_api_token
    
  4. Secure the file by restricting permissions:
    chmod 600 ~/cloudflare.ini

Step 3: Obtain the SSL Certificate

Run Certbot with the DNS plugin to obtain your certificate. Replace cdn.yourdomain.com with your actual domain name:

sudo certbot --nginx --dns-cloudflare --dns-cloudflare-credentials ~/cloudflare.ini -d cdn.yourdomain.com

Step 4: Configure NGINX as a Proxy with SSL

Create a new configuration file for the proxy at /etc/nginx/conf.d/hls_proxy.conf and add the following configuration below.

Be sure to replace cdn.yourdomain.com with your CDN domain name, and panel.yourdomain.com with the MediaCP domain name. We’re also assuming nginx-rtmp is running on the default port 19350.

server {
    listen 80;
    server_name cdn.yourdomain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl;
    server_name cdn.yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/cdn.yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/cdn.yourdomain.com/privkey.pem;

    location / {
        proxy_pass https://panel.yourdomain.com;
        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;

        # Cache settings for HLS
        proxy_cache hls_cache;
        proxy_cache_valid 200 1s;
        proxy_cache_valid 404 1s;
        proxy_cache_valid 500 1s;
        proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args";
    }

    location ~* \.m3u8$ {
        proxy_pass https://panel.yourdomain.com;
        proxy_cache hls_cache;
        proxy_cache_valid 200 1s;
        proxy_cache_valid 404 1s;
        proxy_cache_valid 500 1s;
        add_header Cache-Control "public, max-age=1";
    }

    location ~* \.ts$ {
        proxy_pass https://panel.yourdomain.com;
        proxy_cache hls_cache;
        proxy_cache_valid 200 5s;
        proxy_cache_valid 404 5s;
        proxy_cache_valid 500 5s;
        add_header Cache-Control "public, max-age=5";
    }
}

Step 5: Set Up Proxy Cache

Add the following cache configuration to your main NGINX configuration file, typically found at /etc/nginx/nginx.conf:
http {
    # Other configurations...

    proxy_cache_path /var/cache/nginx/hls_cache levels=1:2 keys_zone=hls_cache:10m max_size=1g inactive=60m use_temp_path=off;

    # Include the proxy configuration
    include /etc/nginx/conf.d/*.conf;
}

Step 6: Test and Reload NGINX

Test your NGINX configuration for syntax errors:

sudo nginx -t

If the test is successful, reload NGINX to apply the changes:

sudo systemctl reload nginx

Step 7: MediaCP Edge URL

Navigate to System Config -> Plugins -> Nginx RTMP and fill out the “EDGEURL” field with your CDN URL.

Once saved, all URLs in the panel relating to Nginx-Rtmp Viewing links will be updated to use the Edge URL on default ports.

Multiple Proxies and Load Balancing

The proxy configuration can be replicated to as many servers as you desire to increase stability, reliability and capacity. We recommend sizing your clusters appropriately to the audience to take advantage of caching. 

A basic form of load balancing can be achieved by adding a duplicate A Record for each server ip address using nginx proxy. This will create a round-robin load balancer.

Table of Contents