├── .dockerignore ├── .gitignore ├── .travis.yml ├── Dockerfile ├── README.md └── run.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | .travis.yml 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .*.swp 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: 2 | - required 3 | language: 4 | - bash 5 | services: 6 | - docker 7 | 8 | install: 9 | - git clone https://github.com/JasonRivers/Docker-nginx-rtmp.git ~/Docker-nginx-rtmp 10 | 11 | script: 12 | - docker build -t nginx-rtmp . 13 | 14 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine:latest as builder 2 | 3 | ARG NGINX_VERSION=1.21.1 4 | ARG NGINX_RTMP_VERSION=1.2.2 5 | 6 | 7 | RUN apk update && \ 8 | apk add \ 9 | git \ 10 | gcc \ 11 | binutils \ 12 | gmp \ 13 | isl \ 14 | libgomp \ 15 | libatomic \ 16 | libgcc \ 17 | openssl \ 18 | pkgconf \ 19 | pkgconfig \ 20 | mpc1 \ 21 | libstdc++ \ 22 | ca-certificates \ 23 | libssh2 \ 24 | curl \ 25 | expat \ 26 | pcre \ 27 | musl-dev \ 28 | libc-dev \ 29 | pcre-dev \ 30 | zlib-dev \ 31 | openssl-dev \ 32 | curl \ 33 | make 34 | 35 | 36 | RUN cd /tmp/ && \ 37 | curl --remote-name http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz && \ 38 | git clone https://github.com/arut/nginx-rtmp-module.git -b v${NGINX_RTMP_VERSION} 39 | 40 | RUN cd /tmp && \ 41 | tar xzf nginx-${NGINX_VERSION}.tar.gz && \ 42 | cd nginx-${NGINX_VERSION} && \ 43 | ./configure \ 44 | --prefix=/opt/nginx \ 45 | --with-http_ssl_module \ 46 | --add-module=../nginx-rtmp-module && \ 47 | make && \ 48 | make install 49 | 50 | FROM alpine:latest 51 | LABEL org.opencontainers.image.authors="jason@jasonrivers.co.uk" 52 | RUN apk update && \ 53 | apk add \ 54 | openssl \ 55 | libstdc++ \ 56 | ca-certificates \ 57 | pcre 58 | 59 | COPY --from=0 /opt/nginx /opt/nginx 60 | COPY --from=0 /tmp/nginx-rtmp-module/stat.xsl /opt/nginx/conf/stat.xsl 61 | RUN rm /opt/nginx/conf/nginx.conf 62 | ADD run.sh / 63 | 64 | EXPOSE 1935 65 | EXPOSE 8080 66 | 67 | CMD /run.sh 68 | 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Docker-nginx-rtmp 2 | Docker image for an RTMP/HLS server running on nginx 3 | 4 | * NGINX Version 1.21.1 5 | * nginx-rtmp-module Version 1.2.2 6 | 7 | ## Configurations 8 | This image exposes port 1935 for RTMP Steams and has 2 default channels open "live" and "testing". 9 | 10 | live (or your first stream name) is also accessable via HLS on port 8080 11 | 12 | It also exposes 8080 so you can access http://:8080/stat to see the streaming statistics. 13 | 14 | The configuration file is in /opt/nginx/conf/ 15 | 16 | ## Running 17 | 18 | To run the container and bind the port 1935 to the host machine; run the following: 19 | ``` 20 | docker run -p 1935:1935 -p 8080:8080 jasonrivers/nginx-rtmp 21 | ``` 22 | 23 | ### Multiple Streams: 24 | You can enable multiple streams on the container by setting RTMP_STREAM_NAMES when launching, This is a comma seperated list of names, E.G. 25 | ``` 26 | docker run \ 27 | -p 1935:1935 \ 28 | -p 8080:8080 \ 29 | -e RTMP_STREAM_NAMES=live,teststream1,teststream2 \ 30 | jasonrivers/nginx-rtmp 31 | ``` 32 | 33 | ### Pushing streams 34 | You can ush your main stream out to other RTMP servers, Currently this is limited to only the first stream in RTMP_STREAM_NAMES (default is live) by setting RTMP_PUSH_URLS when launching, This is a comma seperated list of URLS, EG: 35 | ``` 36 | docker run \ 37 | -p 1935:1935 \ 38 | -p 8080:8080 \ 39 | -e RTMP_PUSH_URLS=rtmp://live.youtube.com/myname/streamkey,rtmp://live.twitch.tv/app/streamkey 40 | jasonrivers/nginx-rtmp 41 | ``` 42 | 43 | ## OBS Configuration 44 | Under broadcast settings, set the follwing parameters: 45 | ``` 46 | Streaming Service: Custom 47 | Server: rtmp:///live 48 | Play Path/Stream Key: mystream 49 | ``` 50 | 51 | ## Watching the steam 52 | 53 | In your favorite RTMP video player connect to the stream using the URL: 54 | rtmp://<your server ip>/live/mystream 55 | http://<your server ip>/hls/mystream.m3u8 56 | 57 | ## Tested players 58 | * VLC 59 | * omxplayer (Raspberry Pi) 60 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | NGINX_CONFIG_FILE=/opt/nginx/conf/nginx.conf 4 | 5 | 6 | RTMP_CONNECTIONS=${RTMP_CONNECTIONS-1024} 7 | RTMP_STREAM_NAMES=${RTMP_STREAM_NAMES-live,testing} 8 | RTMP_STREAMS=$(echo ${RTMP_STREAM_NAMES} | sed "s/,/\n/g") 9 | RTMP_PUSH_URLS=$(echo ${RTMP_PUSH_URLS} | sed "s/,/\n/g") 10 | 11 | apply_config() { 12 | 13 | echo "Creating config" 14 | ## Standard config: 15 | 16 | cat >${NGINX_CONFIG_FILE} <>${NGINX_CONFIG_FILE} <>${NGINX_CONFIG_FILE} <>${NGINX_CONFIG_FILE} <>${NGINX_CONFIG_FILE} <>${NGINX_CONFIG_FILE} <>${NGINX_CONFIG_FILE} <>${NGINX_CONFIG_FILE} <