ubuntu 安装编译nginx,并实现HLS推送,,可以实现摄像头直播

1.安装nginx的依赖包  zlib pcre openssl(可以源码安装也可以直接系统安装)

sudo apt-get install libpcre3 libpcre3-dev zlib1g-dev libssl-dev build-essential

2.下载openssl源码包

wget http://www.openssl.org/source/openssl-1.0.2a.tar.gz

sudo tar -zxvf openssl-1.0.2a.tar.gz -C /usr/local/src/

cd /usr/local/src/openssl-1.0.2a/

sudo ./config

sudo make && sudo make install

3.为了增加对rtmp的支持下载nginx-rtmp-module,地址:https://github.com/arut/nginx-rtmp-module

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

4.下载nginx源码包

wget  http://nginx.org/download/nginx-1.8.0.tar.gz

sudo tar -zxvf nginx-1.8.0.tar.gz -C /usr/local/src/

cd ../nginx-1.4.4
./configure --prefix=/usr/local/nginx --with-google_perftools_module 
--add-module=/usr/local/src/nginx-rtmp-module  --with-http_ssl_module --with-debug
make
make install

5.

在原有的nginx.conf中加入如下配置

rtmp {

    server {

        listen 1935;

        chunk_size 4000;
      
        #HLS

        # For HLS to work please create a directory in tmpfs (/tmp/app here)
        # for the fragments. The directory contents is served via HTTP (see
        # http{} section in config)
        #
        # Incoming stream must be in H264/AAC. For iPhones use baseline H264
        # profile (see ffmpeg example).
        # This example creates RTMP stream from movie ready for HLS:
        #
        # ffmpeg -loglevel verbose -re -i movie.avi  -vcodec libx264 
        #    -vprofile baseline -acodec libmp3lame -ar 44100 -ac 1 
        #    -f flv rtmp://localhost:1935/hls/movie
        #
        # If you need to transcode live stream use 'exec' feature.
        #
        application hls {
            live on;
            hls on;
            hls_path /usr/local/nginx/html/hls;
            hls_fragment 5s;
        }
    }
}

http {

    server {

        listen  8080;
        location /hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root html;
            expires -1;
        }
    }
}

其中rtmp部分与原有的http部分在同一个级别,但是下面的http部分要放到已有的http部分中,也就是增加一个server部分。

启动nginx服务

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf  

原文地址:https://www.cnblogs.com/nopassword/p/6061833.html