A secure Docker-based NGINX stream forwarder that forwards RTMP streams to YouTube Live and Twitch, with stream key authentication, deployable on fly.io.
With this forwarder only streams with the correct key can publish!
Stream URL format: rtmp://<app_name>.fly.dev/live/<your-secret-key>
- β RTMP stream forwarding to YouTube Live and Twitch
- β Stream key authentication for security
- β Docker containerized with Hono-based auth service
- β Ready for fly.io deployment
- β Health checks and monitoring
- β Multiple stream endpoints
- β Automatic failover and scaling
- β Real-time auth logging
Before starting, ensure you have:
- A fly.io account
- YouTube Live streaming enabled on your YouTube channel
- Your YouTube Live stream key ready
- A computer with internet access
Install the fly.io command line tool to deploy. Windows (PowerShell):
pwsh -c "iwr https://fly.io/install.ps1 -useb | iex"
Alternative (using package managers):
# macOS with Homebrew
brew install flyctl
# Linux with snap
sudo snap install flyctl
Authenticate with your fly.io account:
flyctl auth login
This will open your browser for authentication. Complete the login process.
Clone or download this repository:
git clone <repository-url>
cd nginx-stream-forwarding
Or download and extract the ZIP file, then navigate to the folder.
-
Set a unique app name in
fly.toml
:app = "your-unique-stream-forwarder" # Choose a unique name
-
Choose your deployment region (optional):
primary_region = "iad" # US East (default) # Other options: lax (US West), fra (Europe), nrt (Asia), etc.
Set your streaming platform keys and authentication key as secrets:
# Required: YouTube stream key
flyctl secrets set YOUTUBE_STREAM_KEY="your-youtube-stream-key-here"
# Optional: Twitch stream key (if you want multi-platform streaming)
flyctl secrets set TWITCH_STREAM_KEY="your-twitch-stream-key-here"
# Optional: X (Twitter) stream key
flyctl secrets set X_STREAM_KEY="your-x-stream-key-here"
# Required: Your secure stream authentication key
flyctl secrets set STREAM_KEY="your-secure-stream-key-here"
Deploy your stream forwarder:
flyctl launch --no-deploy
flyctl deploy
The --no-deploy
flag creates the app without deploying, then flyctl deploy
does the actual deployment.
-
Check app status:
flyctl status
-
View your app info:
flyctl info
-
Test the health endpoint:
curl https://your-app-name.fly.dev/health
Once deployed, use this URL in your streaming software:
rtmp://your-app-name.fly.dev/live/your-stream-key
Important: Replace your-stream-key
with the STREAM_KEY secret you set in Step 5. Only streams with the correct key will be accepted!
- Go to Settings β Stream
- Set Service to "Custom..."
- Set Server to:
rtmp://your-app.fly.dev/live/
- Set Stream Key to:
your-stream-key
ffmpeg -i input.mp4 -c copy -f flv rtmp://your-app.fly.dev/live/your-stream-key
[Your Streaming Software]
β RTMP
[nginx-stream-forwarder on fly.io]
β RTMP Forward
[YouTube Live & Twitch Servers]
The nginx.conf
file contains:
- HTTP server for health checks (port 80)
- Stream forwarding servers (ports 1935, 1936)
- Upstream YouTube and Twitch RTMP servers
- Logging and monitoring
The fly.toml
file defines:
- App settings and region
- Service ports (80, 1935, 1936)
- Resource allocation
- Health checks
- Health Check:
https://your-app.fly.dev/health
- Status:
https://your-app.fly.dev/
- Logs:
flyctl logs
-
Stream not connecting:
- Verify your YouTube stream key is correct
- Check if YouTube Live is enabled on your account
- Ensure ports 1935/1936 are not blocked
- Verify your STREAM_KEY matches what you set in secrets
-
Deployment fails:
- Check flyctl is installed and up to date
- Verify you're logged into fly.io
- Ensure the app name in fly.toml is unique
-
Stream drops:
- Check fly.io app logs:
flyctl logs
- Monitor network connectivity
- Consider increasing VM resources in fly.toml
- Check fly.io app logs:
View real-time logs:
flyctl logs
View nginx access logs:
flyctl ssh console
tail -f /var/log/nginx/stream.log
Edit nginx.conf
to add more upstream servers:
if [[ -n "$X_STREAM_KEY" ]]; then
echo " push rtmp://va.pscp.tv:80/x/$X_STREAM_KEY;" >> /etc/nginx/nginx.conf
fi
Edit fly.toml
to change deployment region:
primary_region = "fra" # Frankfurt
# Other options: lax, ord, lhr, nrt, syd, etc.
Modify VM resources in fly.toml
:
flyctl machines update <machine-id> --cpus 1 --memory 1024
MIT License - feel free to modify and use for your streaming needs!