nginx + nginx-rtmp-module でストリーミング配信をする

nginxを予めyumでinstallしていた場合削除する

yum remove nginx

必要なパッケージをyumでインストールしておく

sudo yum install gcc wget pcre pcre-devel openssl openssl-devel

ngix用のrtmpモジュールをcloneしてくる

mkdir git
cd git
git clone https://github.com/arut/nginx-rtmp-module.git

ngixのソースをwgetしてくる

wget http://hg.nginx.org/nginx/archive/tip.zip
unzip tip.zip
mv nginx-c2f309fb7ad2 nginx
cd nginx

インストール(nginx-rtmp-moduleのパスは自分がgit cloneしてきた場所に読み替える)

./auto/configure --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --add-module=/git/nginx-rtmp-module --prefix=/usr/local/nginx

make && make install

confファイルの設定

vim /etc/nginx/nginx.conf
rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application live {
                        play /usr/local/nginx/html/video;
                        live on;
                        record off;
                }
        }
}

スタート&ストップ

$nginx
$sudo /usr/sbin/nginx -s stop

mime.typesに下記が記載されていることを確認

vim /etc/nginx/mime.types
-------------------------------------------------
    application/x-mpegURL                 m3u8;
    video/MP2T                            ts;
-------------------------------------------------

mp4ファイルを配置する

mkdir /usr/local/nginx/html/video
cp test.mp4 /usr/local/nginx/html/video

VLCプレイヤーをインストールする

http://www.videolan.org/vlc/

VLCプレイヤー>ファイル->ネットワークを開く

rtmp://192.168.0.1/live/test.mp4

以下はnginxをconfigureするときに起きたエラー。

あらかじめyum でopensslなどをいれておけば起きない。

>checking for PCRE library ... not found
>checking for PCRE library in /usr/local/ ... not found
>checking for PCRE library in /usr/include/pcre/ ... not found
>checking for PCRE library in /usr/pkg/ ... not found
>checking for PCRE library in /opt/local/ ... not found

>./auto/configure: error: the HTTP rewrite module requires the PCRE library.
>You can either disable the module by using --without-http_rewrite_module
>option, or install the PCRE library into the system, or build the PCRE library
>statically from the source with nginx by using --with-pcre=<path> option.

yum list | grep pcre
yum install pcre-devel

> + ngx_rtmp_module was configured
>checking for PCRE library ... found
>checking for PCRE JIT support ... not found
>checking for OpenSSL library ... not found

>./auto/configure: error: SSL modules require the OpenSSL library.
>You can either do not enable the modules, or install the OpenSSL library
>into the system, or build the OpenSSL library statically from the source
>with nginx by using --with-openssl=<path> option.

yum install openssl-devel