搭建nginx服务器

这里使用的是百度云的服务器,CentOS7系统的

nginx:Nginx代码完全用 C语言从头写成

Nginx (engine x) 是一个高性能的HTTP和反向代理服务器

下载nginx

Nginx官网:http://nginx.org/en/

下载nginx:http://nginx.org/en/download.html

linux下命令:wget http://nginx.org/download/nginx-1.12.1.tar.gz

还需要下载一个OpenSSL

OpenSSL官网:https://www.openssl.org/

下载OpenSSL,这个在github上面直接搜就可以,下载release版本的,我这里是OpenSSL_1_1_0f这个版本的

下载地址:https://github.com/openssl/openssl/releases/tag/OpenSSL_1_1_0f

linux下命令:wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_0f.tar.gz

还需要下载一个rtmp

直接在guthub上搜nginx-rtmp找星最多的那个,是叫arut/nginx-rtmp-module,下载release版本的

下载地址:https://github.com/arut/nginx-rtmp-module/releases/tag/v1.2.0

linux下命令:wget https://github.com/arut/nginx-rtmp-module/archive/v1.2.0.tar.gz

之后解压三个文件

tar -xzf nginx-1.12.1.tar.gz 
tar -xzf OpenSSL_1_1_0f.tar.gz 
tar -xzf v1.2.0.tar.gz

之后是编译nginx

编译nginx的前提是要先编译OpenSSL,要得到.so文件和头文件

编译OpenSSL

首先进入openSSl文件夹

创建一个bin目录,用来存放生成的so文件和头文件:mkdir bin

生成Makefile文件:./config --prefix=`pwd`/bin

最后编译:make install

会在bin目录里生成include(头文件)和lib(so文件)

之后编译nginx

首先进入nginx-rtmp-module-1.2.0文件夹中获取路径

执行命令:pwd,将打印的路径复制出来

在进入到nginx路径下

执行命令:./configure --add-module=上面拿到的路径

示例:./configure --add-module=/root/nginx/nginx-rtmp-module-1.2.0

这里会报错,因为找不到openSSL

在nginx-1.12.1/auto/lib/openssl/路径下有一个conf文件,是配置路径的

在里面修改下配置

    if [ $ngx_found = no ]; then

        # 自定义的

        ngx_feature="OpenSSL library in /root/nginx/openssl-OpenSSL_1_1_0f/bin/"
        #头文件路径
        ngx_feature_path="/root/nginx/openssl-OpenSSL_1_1_0f/bin/include"

        if [ $NGX_RPATH = YES ]; then
            ngx_feature_libs="-R/root/nginx/openssl-OpenSSL_1_1_0f/bin/lib -L/root/nginx/openssl-OpenSSL_1_1_0f/bin/lib -lssl -lcrypto $NGX_LIBDL"
        else
            ngx_feature_libs="-L/root/nginx/openssl-OpenSSL_1_1_0f/bin/lib -lssl -lcrypto $NGX_LIBDL"
        fi

        . auto/feature
    fi

将上面的内容添加到114行

ubuntu系统:

再回到nginx-1.12.1路径下,执行:./configure --prefix=`pwd`/bin --add-module=/root/nginx/nginx-rtmp-module-1.2.0

最后执行:make install

在当前路径下会生成一个bin目录生成一个可执行文件bin/sbin/nginx

centos系统:

回到nginx-1.12.1路径下,执行:./configure --without-http_rewrite_module --without-http_gzip_module --add-module=/root/nginx/nginx-rtmp-module-1.2.0

最后执行:make install

在/usr/local/nginx/下会生成一个sbin目录,里面有一个可执行文件/sbin/nginx


最后在nginx所在的路径下执行:./nginx

这个时候会报错:./nginx: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory

他找不到要引用的so库

解决:

vim /etc/ld.so.conf
在最后一行假如so文件所在的文件夹
eg:/root/nginx/openssl-OpenSSL_1_1_0f/bin/lib

保存,退出

在执行ldconfig使刚才的配置生效

最后在nginx所在的路径下执行:./nginx

可以看到没有任何错误了

这里在百度云配置一下服务器

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

这里写图片描述

之后就可以在浏览器里看到了

这里的端口号默认是80,所以输入ip直接就可以访问到,如果要修改的话,可以修改配置文件

ubuntu:/root/nginx/nginx-1.12.1/bin/conf/nginx.conf
centos:/usr/local/nginx/conf/nginx.conf

在这个路径下有一个nginx.conf文件,里面有一个listener 80;表示端口号,可以在这里修改,**这里对照着/root/nginx/nginx-rtmp-module-1.2.0/test/nginx.conf修改下**

我这里的是这样的


    #user  nobody;
    worker_processes  1;

    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;

    #pid        logs/nginx.pid;


    events {
        worker_connections  1024;
    }

    rtmp {
        server {
            listen 1935;
            application myapp{
                live on;

                 #record keyframes;
                 #record_path /tmp;
                 #record_max_size 128K;
                 #record_interval 30s;
                 #record_suffix .this.is.flv;

                 #on_publish http://localhost:8080/publish;
                 #on_play http://localhost:8080/play;
                 #on_record_done http://localhost:8080/record_done;
            }
        }
    }

    http {
        include       mime.types;
        default_type  application/octet-stream;

        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';

        #access_log  logs/access.log  main;

        sendfile        on;
        #tcp_nopush     on;

        #keepalive_timeout  0;
        keepalive_timeout  65;

        #gzip  on;

        server {
            #端口
            listen       80;
            server_name  localhost;

            location /stat {
                rtmp_stat all;
                rtmp_stat_stylesheet stat.xsl;
            }

            location /stat.xsl {
                root /root/nginx/nginx-rtmp-module-1.2.0/;      
            }

            location /control {
                rtmp_control all;
            }

            location /rtmp-publisher {
                root /root/nginx/nginx-rtmp-module-1.2.0/test;
            }

            #charset koi8-r;

            #access_log  logs/host.access.log  main;

            location / {
                root   html;
                #root /root/nginx/nginx-rtmp-module-1.2.0/test/www;
                index  index.html index.htm;
            }

            #error_page  404              /404.html;

            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }

            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ \.php$ {
            #    proxy_pass   http://127.0.0.1;
            #}

            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ \.php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}

            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /\.ht {
            #    deny  all;
            #}
        }


        # another virtual host using mix of IP-, name-, and port-based configuration
        #
        #server {
        #    listen       8000;
        #    listen       somename:8080;
        #    server_name  somename  alias  another.alias;

        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}


        # HTTPS server
        #
        #server {
        #    listen       443 ssl;
        #    server_name  localhost;

        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;

        #    ssl_session_cache    shared:SSL:1m;
        #    ssl_session_timeout  5m;

        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers  on;

        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}

    }


完了之后重启下服务器,然后重新./nginx

之后下载ffmpeg-static

下载地址:http://ffmpeg.zeranoe.com/builds/

进入ffmpeg\ffmpeg-static\bin执行命令

ffmpeg -re -i 视频 -f 格式 地址

eg:ffmpeg -re -i C:\Users\Administrator\Desktop\aaa.flv -f flv rtmp://47.94.141.202/myapp/mystream

这个时候使用VLC工具查看,VLC下载地址:http://rj.baidu.com/search/index/?kw=vlc

使用:媒体->打开网络串流-->rtmp://47.94.141.202/myapp/mystream

也可以使用app:

demo地址: https://github.com/zhaopingfu/AVSynchronization
在MainActivity里修改下地址就可以了

命令

nginx
Nginx代码完全用 C语言从头写成

Nginx (engine x) 是一个高性能的HTTP和反向代理服务器
百度  ngnix

下载页面
http://nginx.org/en/download.html

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


下载 OpenSl
https://www.openssl.org/source/   下载页面  github

https://github.com/openssl/openssl

下载realse版本
https://github.com/openssl/openssl/archive/OpenSSL_1_1_0f.tar.gz

下载  Rtmp
github搜索  nginx-rtmp
https://github.com/arut/nginx-rtmp-module
下载地址
https://github.com/arut/nginx-rtmp-module/archive/v1.2.0.tar.gz

----------------编译---------

Nginx-Rtmp  依赖于opensl   
需要得到opensl的两个so  和头文件
首先先编译opensl


1  编译openssl
创建bin目录  生成的文件放到bin目录中   
./config --prefix=`pwd`/bin
结果  生成makefile

生成之后调用make install

2 编译nginx目录下
第一步按照官方文档
./configure --add-module=/path/to/nginx-rtmp-module


会报错  提示需要没有opensl 
./configure --prefix=`pwd`/bin --add-module=/root/nginx/nginx-rtmp-module-1.2.0

正确步骤
./configure --prefix=`pwd`/bin --add-module=/root/nginx/nginx-rtmp-module-1.2.0 --with-openssl=/root/nginx/openssl-OpenSSL_1_1_0f/bin

修改默认查找openssl脚本
打开 auto/lib/openssl/conf

./configure --prefix=`pwd`/bin --add-module=/root/nginx/nginx-rtmp-module-1.2.0

make install 

编译结果
bin下面有
conf/(配置文件目录) html/(HTML页面) logs/(日志) sbin/(可执行文件)

开启 nginx 
进入 sbin
开启 ./nginx 
关闭 ./nginx -s stop

开启出现找不到ssl动态库错误
配置linux库查找目录
/etc/ld.so.conf
添加一行,指向openssl库目录
/root/nginx/openssl-OpenSSL_1_1_0f/bin
刷新: ldconfig

如果开启了 先关闭nginx服务器
修改配置
将nginx-rtmp-module/test/下的nginx.conf 复制到 nginx/bin/conf下面
当前在nginx-rtmp-module/test/目录下执行
cp nginx.conf /root/nginx/nginx-1.12.1/bin/conf/

rtmp://ip:port/myapp/xxx

sudo apt-get install openssl

配置用户组
user root;

测试电视台

测试可用:rtmp://live.hkstv.hk.lxdns.com/live/hks
rtmp://www.planeta-online.tv:1936/live/channel_4

香港卫视 rtmp://live.hkstv.hk.lxdns.com/live/hks
香港卫视 http://live.hkstv.hk.lxdns.com/live/hks/playlist.m3u8
香港卫视 http://124.160.184.137:80/live/5 ... a46720.m3u8?type=tv


香港卫视精品台 http://221.120.177.59/hls/i3d7ragr.m3u8
香港卫视精品台 rtmp://221.120.177.59/livestream/ucagm8kk  


香港9DTV  mmsh://media.9dtv.com.hk:8088/9DTVBroadCast            


酷六V音乐 http://main.gslb.ku6.com/broadcast/sub?channel=910


东森新闻   rtsp://adelivery_s.emome.net:554 ... ;at=1&mc=d2d58c


东森新闻亚洲 rtsp://adelivery_s.emome.net:554 ... ;at=1&mc=d2d58c


东森幼儿  http://119.147.242.8:14207            


华娱卫视  rtsp://116.199.127.68/huayu


阳光卫视  http://wzfree.10043.doftp.com/tvtest/182tv.php/live/id/suntv.m3u8
           http://proxy.myvst.net/live/7167 ... 53565151E76D4F.m3u8


本港卫视   rtsp://116.199.127.68/bengang
本港卫视   http://119.147.242.7:14075
本港卫视   rtsp://3ptv.cietv.com/bengang
本港台     http://v.hrtv8.com/vip.hrtv8.com/stream/2506.m3u8

本港亚洲台 http://119.147.242.7:14083

本港国际台 http://119.147.242.7:14082

健康生活台 http://wzfree.10043.doftp.com/tvtest/182tv.php/live/id/hlc.m3u8

TVB  http://rtsp.vdowowza.tvb.com:193 ... ream/chunklist.m3u8
TVB8 http://202.102.79.114:554/live/tvb8.stream/playlist.m3u8
TVB8 http://122.192.35.76:554/live/tvb8.stream/playlist.m3u8
TVB 互动新闻台  http://119.147.242.7:14078
TVB 互动新闻台  http://rtsp.vdowowza.tvb.com/tvb ... ream/chunklist.m3u8
TVB 互动新闻台  http://rtsp.vdowowza.tvb.com:193 ... ream/chunklist.m3u8
TVB 互动新闻台  http://rtsp.vdowowza.tvb.com:554 ... ream/chunklist.m3u8
TVB 互动新闻台  http://rtsp.vdowowza.tvb.com:554 ... ream/chunklist.m3u8
TVB 互动新闻台  http://rtsp.vdowowza.tvb.com:554 ... ream/chunklist.m3u8
TVB 互动新闻台  rtsp://rtsp.vdowowza.tvb.com/tvblive/mobile_inews_200.stream
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值