• ubuntu编译安装nginx并且配置流服务器


    1,安装流媒体服务器nginx:

    主要参考教程:https://blog.csdn.net/ansu_wl/article/details/83040674

    总结起来就是:下载,源码和rtmp扩展包

    解压放到~目录下,让它看起来大约这样:

    └── nginx-1.15.3    #这个是源码
        ├── auto
        │   ├── cc
        │   ├── lib
        │   ├── os
        │   └── types
        ├── conf
        ├── contrib
        │   ├── unicode2nginx
        │   └── vim
        ├── html
        ├── man
        ├── nginx-rtmp-module-master    #源码下放了rtmp扩展包
        │   ├── dash
        │   ├── doc
        │   ├── hls
        │   └── test
        ├── objs
        │   ├── addon
        │   └── src
        └── src
            ├── core
            ├── event
            ├── http
            ├── mail
            ├── misc
            ├── os
            └── stream

    然后执行安装:

    ./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=./nginx-rtmp-module-master/ --with-file-aio

    大意是:安装到/usr/local/nginx,需要http_ssl_module扩展,添加rtmp扩展,路径是./nginx-rtmp-module-master/,需要file-aio(咱也不知道那是啥),

    然后就开始配置了,

    Configuration summary
    + using system PCRE library
    + using system OpenSSL library
    + using system zlib library

    nginx path prefix: "/usr/local/nginx"
    nginx binary file: "/usr/local/nginx/sbin/nginx"
    nginx modules path: "/usr/local/nginx/modules"
    nginx configuration prefix: "/usr/local/nginx/conf"
    nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
    nginx pid file: "/usr/local/nginx/logs/nginx.pid"
    nginx error log file: "/usr/local/nginx/logs/error.log"
    nginx http access log file: "/usr/local/nginx/logs/access.log"
    nginx http client request body temporary files: "client_body_temp"
    nginx http proxy temporary files: "proxy_temp"
    nginx http fastcgi temporary files: "fastcgi_temp"
    nginx http uwsgi temporary files: "uwsgi_temp"
    nginx http scgi temporary files: "scgi_temp"

    然后进行安装的常规操作

    make j6

    make install

    查看端口:sudo netstat -tlpn

    2,ffmpeg命令行推流

    推流流程:
    1),首先要配置一个流服务器:

    配置文件(网上抄的):

    #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 rtmplive {  
              live on;  
              #为 rtmp 引擎设置最大连接数。默认为 off  
              max_connections 521;  
           }  
          application hls{  
              live on;  
              hls on;  
              hls_path /var/www/hls;  
              hls_fragment 1s;  
          }  
       }  
    }

    2),#开启nginx服务

    cd /usr/local/nginx/sbin
    sudo ./nginx


    3),开启ffmpeg推流:
    cd /usr/local/ffmpeg/bin
    ./ffmpeg -re -i ~/temp/ffmpeg/video/1.wmv -f flv rtmp://192.168.3.188:1935/rtmplive/room

    #接流:rtmp://192.168.3.188:1935/rtmplive/room

    3,nginx有关命令

    1)nginx Start/Stop/Restart
    sudo /usr/local/nginx/sbin/nginx
    sudo /usr/local/nginx/sbin/nginx -s stop
    sudo /usr/local/nginx/sbin/nginx -s reload

    2)测试nginx的配置文件是不是有错误

    sudo /usr/local/nginx/sbin/nginx -t

    返回successful就是没问题

    3,nginx配置文件的含义

     基本分为如下几方面:

    ##目录
    ##全局配置
        ##http服务器配置
            ##server配置1
                ##location配置1
                ##location配置2
            ##server配置2
    ##rtmp配置

    详解:

    ##全局配置
    user nobody nobody;    
    #访问的时候默认使用的用户是nobody,nobody并不是没有,而是真有此用户,但是打开此设置会报错,还是不要打开吧。。。
    worker_processes 2;    #指定了Nginx要开启的进程数。每个Nginx进程平均耗费10M~12M内存,建议和核心数量一样
    error_log logs/error.log notice;
    #全局错误日志文件。日志输出级别有debug、info、notice、warn、error、crit
    pid logs/nginx.pid;
    #主模块指令,用来指定进程pid的存储文件位置
    worker_rlimit_nofile 65535;
    #worker_rlimit_nofile用于绑定worker进程和CPU,具体怎么绑的不知
    
    
    events{
    #events事件指令是设定Nginx的工作模式及连接数上限
    use epoll;
    #设置nginx工作模式,Linux系统,epoll工作模式是首选。Nginx支持的工作模式有select、poll、kqueue、epoll、rtsig和/dev/poll
    worker_connections 512;
    }
    ##全局配置结束
    
    ##http服务器配置
    
    
    http{
        include conf/mime.types;  
        #指向的是conf下的mime.types文件
        default_type application/octet-stream;
        #默认访问为二进制流
        log_format main '$remote_addr - $remote_user [$time_local] '
        '"$request" $status $bytes_sent '
        '"$http_referer" "$http_user_agent" '
        '"$gzip_ratio"';
        #log_format是Nginx的HttpLog模块指令,用于指定Nginx日志的输出格式,main表示此日志输出格式的名称
    
        log_format download '$remote_addr - $remote_user [$time_local] '
        '"$request" $status $bytes_sent '
        '"$http_referer" "$http_user_agent" '
        '"$http_range" "$sent_http_content_range"';
        client_max_body_size 20m;
        #设置允许客户端请求的最大的单个文件字节数
        client_header_buffer_size 32K;
        #指定来自客户端请求头的headerbuffer大小。大部分时候1k就够了
        large_client_header_buffers 4 32k;
        #指定客户端请求中较大的消息头的缓存最大数量和大小, “4”为个数,“128K”为大小,最大缓存量为4个128K;
        sendfile on;
        #开启高效文件传输模式。
        tcp_nopush on;
        tcp_nodelay on;
        #tcp_nopush和tcp_nodelay两个指令设置为on用于防止网络阻塞;
        keepalive_timeout 60;
        #设置客户端连接保持活动的超时时间。
        client_header_timeout 10;
        #设置客户端请求头读取超时时间,如果超时客户仍旧没有发送数据,那就返回408
        client_body_timeout 10;
        #户端请求主体读取超时时间。如果超过这个时间,客户端还没有发送任何数据,返回408
        send_timeout 10;
        #send_timeout指定响应客户端的超时时间。
    
        ##服务器配置暂时结束
    
        ##HttpGzip模块在Nginx配置中的相关属性设置
        #
        #这个我们没装,不信可以查看命令./nginx -V
        ##HttpGzip模块在Nginx配置中的相关属性设置结束
    
        ##负载均衡配置
        #因为我们目前仅有1个server所以我们不需要均衡,略过
        ##负载均衡配置结束
    
    
        ##server虚拟主机配置(如果没说错的话,server应该是写在服务器配置中的)
        server{
            listen 80;
            #listen用于指定虚拟主机的服务端口
            server_name localhost;
            #server_name用来指定IP地址或者域名,多个域名可以用空格分开
            index index.html index.htm index.php;
            #index用于设定访问的默认首页地址
            root /home/lvnv/webroot;
            #root指令用于指定虚拟主机的网页根目录
            charset gb2312;
            #Charset用于 设置网页的默认编码格式
            access_log off;
            #access_log用来指定此虚拟主机的访问日志存放路径
            
                ##location配置在虚拟主机配置内部,稍微有些复杂,涉及正则,没细研究,主要作用是通过指定正则表达式与客户端请求的URI相匹配
                location / {
                    root   /home/lvnv/webroot;
                    index  index.php index.html index.htm;
                }
    
        }
        ##server虚拟主机配置结束
        
        
        
    }
  • 相关阅读:
    滑雪
    2084 数塔HDU
    括号匹配(二)
    项链
    单调递增最长子序列
    矩形嵌套
    最长公共子序列
    poj3253
    表达式求值
    颜色16进制代码表显示和16进制数值对比显示方便查找
  • 原文地址:https://www.cnblogs.com/0-lingdu/p/13139487.html
Copyright © 2020-2023  润新知