Ubuntu安装nginx+rtmp

Ubuntu安装nginx+rtmp


安装前卸载之前安装的nginx: https://blog.csdn.net/adley_app/article/details/79223221
nginx启动等命令: https://blog.csdn.net/tototuzuoquan/article/details/52736387
如果是是一般用户,建议使用sudo命令进行所有操作,不然可能会出现各种问题:

安装

  1. 安装 build-essential
    (sudo) apt-get install build-essential
  2. 安装pcre
    (sudo) apt-get install libpcre3 libpcre3-dev
  3. 安装openssl
    sudo) apt-get install libssl-dev
  4. 安装zlib (ubuntu库中名为zlib1g zlib1g-dev)
    (sudo) apt-get install zlib1g
    (sudo) apt-get install zlib1g-dev
  5. 安装unzip(如果需要)
    (sudo) apt-get install unzip
  6. 下载nginx和nginx-rtmp
    (sudo) wget http://nginx.org/download/nginx-1.12.2.tar.gz (版本自选)
    (sudo) wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
  7. 解压安装包
    (sudo) tar -zxvf nginx-1.12.2.tar.gz
    (sudo) unzip nginx-rtmp-module-master.zip
  8. 编译安装
    • 生成配置文件:
      进入 nginx-1.12.2文件夹:(sudo) ./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=…/nginx-rtmp-module-master
      在这里插入图片描述
    • 编译
      (sudo) make
      在这里插入图片描述
    • 安装
      (sudo) make install
      在这里插入图片描述
  9. 修改conf文件:
    修改后的文件(需要的修改的地方: http里面 添加: location /live 、 location /hls,代码最后添加:rtmp )
#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;
}


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;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

       location /live { 
            root   html;
            index  index.html index.htm;
        }
        location /hls{
            types{
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
                }
            root /usr/local/var/www;
            add_header Cache-Control no-cache;
            add_header Access-Control-Allow-Origin *;
        }

        #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;
    #    }
    #}

}
rtmp{
        server {
                listen 1935;
                chunk_size 4000;


                application rtmplive{
                        live on;
                        max_connections 1024;
                }
                application hls{
                        live on;
                        hls on;
                        hls_path /temp;
                        hls_fragment 5s;
                }
        }


}
  1. 启动nginx
    进入/usr/local/nginx/sbin: (sudo) ./nginx -c conf/nginx.conf
  2. 查看进程
    ps -ef|grep nginx

可能出现的问题

1.生成配置文件时:mkdir: cannot create directory ‘objs’: Permission denied等提示
在这里插入图片描述
解决方案:缺少root权限,使用sudo命令 :(sudo) ./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=…/nginx-rtmp-module-master
2. 问题:C compiler cc is not found
解决方案:未安装gcc-c++:(sudo) apt-get install build-essential
3. nginx启动 出现: nginx: command not found
解决方案:使用(sudo)./nginx可以解决 要想彻底解决可以参考 https://blog.csdn.net/zxc_user/article/details/74936059
4. 出现各种文件或文件夹无法创建:
解决方案:权限不够,使用sudo
5. 无法推流,访问:
解决方案:检查是否有防火墙,打开1935端口
6. 测试:可以使用obs+vlc测试

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值