這篇文章將為大家詳細(xì)講解有關(guān)如何使用nginx搭建點(diǎn)播和直播流媒體服務(wù)器,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
從網(wǎng)站建設(shè)到定制行業(yè)解決方案,為提供網(wǎng)站設(shè)計(jì)、成都做網(wǎng)站服務(wù)體系,各種行業(yè)企業(yè)客戶提供網(wǎng)站建設(shè)解決方案,助力業(yè)務(wù)快速發(fā)展。創(chuàng)新互聯(lián)將不斷加快創(chuàng)新步伐,提供優(yōu)質(zhì)的建站服務(wù)。
環(huán)境 centos7 nginx
1 安裝nginx依賴包 yum install gcc gcc-c++ openssl-devel zlib-devel pcre pcre-devel yamdi
2.下載解壓nginx_mod_h364_streaming,讓nginx支持flv,mp4流播放 wget http://h364.code-shop.com/download/nginx_mod_h364_streaming-2.2.7.tar.gz 解壓后需要修改src目錄下的ngx_http
_streaming_module.c文件,將r->zero_in_uri所在的if語句注釋掉
3.下載解壓nginx-rtmp-module,讓nginx支持rtmp/hls協(xié)議,wegt -o nginx-rtmp-module.zip https://github.com/arut/nginx-rtmp-module/archive/master.zip
4下載清除緩存的模塊 wget -Ongx_cache_purge.zip https://github.com/FRiCKLE/ngx_cache_purge/archive/master.zip
5.下載nginx wget http://nginx.org/download/nginx-1.9.0.tar.gz
6 .進(jìn)入nginx的安裝目錄下 執(zhí)行以下命令./configure --prefix=/usr/local/nginx/--add-module=../nginx-rtmp-module-master --add-module=../ngx_cache_purge-master--add-module=../nginx_mod_h364_streaming-2.2.7 --with-http_stub_status_module--with-http_ssl_module --with-http_sub_module --with-http_gzip_static_module--with-http_flv_module
7. 執(zhí)行以下命令編譯文件make && make install ,并修改nginx安裝目錄下的objs下的Makefile 刪除-Werror
9. 修改nginx.conf
10. 通過yum 停止firewalld防火墻并卸載,然后安裝iptables-services修改/etc/sysconfig/iptables文件夾放行80端口
11.nginx 配置如下:
#使用的用戶和組 #user nobody; #指定工作衍生的進(jìn)程數(shù),為cpu的核心數(shù)總和 worker_processes 2; #指定錯(cuò)誤日志的存放路徑 日志記錄級別[debug,info,notice,warn,error,crit] error_log /usr/local/nginx/logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #指定pid存放的路徑 pid /usr/local/nginx/logs/nginx.pid; events { #使用的網(wǎng)絡(luò)I/O模型,linux系統(tǒng)推薦是epoll而freeBSD是kqueue use epoll; #允許的連接數(shù),最大的高并發(fā)連接數(shù)為worker_processes*worker_connections worker_connections 51200; } rtmp { server { listen 1935; chunk_size 4096; application live { live on; record off; } #application live2 { #live on; #record off; #} # video on demand application media { play /usr/local/nginx/html/; } #application vod_http { #play http://192.168.31.185/vod; #} application hls { live on; hls on; hls_path /tmp/hls; } } } 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 / { root html; index index.html index.htm; } location ~ \.flv$ { root /usr/local/nginx/html/media/; flv; } location ~ \.mp4$ { root /usr/local/nginx/html/media/; mp4; } location /stat { rtmp_stat all; # Use this stylesheet to view XML as web page # in browser rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { # XML stylesheet to view RTMP stats. # Copy stat.xsl wherever you want # and put the full directory path here root /path/to/stat.xsl/; } location /hls { # Serve HLS fragments types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /tmp; add_header Cache-Control no-cache; } location /dash { # Serve DASH fragments root /tmp; add_header Cache-Control no-cache; } #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; # } #} }
12. 輸入xxx.xxx.xxx.xxx/*.mp4/*.flv就能播放視頻了
關(guān)于“如何使用nginx搭建點(diǎn)播和直播流媒體服務(wù)器”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯(cuò),請把它分享出去讓更多的人看到。
分享文章:如何使用nginx搭建點(diǎn)播和直播流媒體服務(wù)器
網(wǎng)址分享:http://aaarwkj.com/article10/pegedo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、外貿(mào)網(wǎng)站建設(shè)、虛擬主機(jī)、App開發(fā)、做網(wǎng)站、響應(yīng)式網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)