Ubuntu安装nginx+rtmp安装可能出现的问题
安装前卸载之前安装的nginx: https://blog.csdn.net/adley_app/article/details/79223221
nginx启动等命令: https://blog.csdn.net/tototuzuoquan/article/details/52736387
如果是是一般用户,建议使用sudo命令进行所有操作,不然可能会出现各种问题:
安装
安装 build-essential
(sudo) apt-get install build-essential
安装pcre
(sudo) apt-get install libpcre3 libpcre3-dev
安装openssl
sudo) apt-get install libssl-dev
安装zlib (ubuntu库中名为zlib1g zlib1g-dev)
(sudo) apt-get install zlib1g
(sudo) apt-get install zlib1g-dev
安装unzip(如果需要)
(sudo) apt-get install unzip
下载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
解压安装包
(sudo) tar -zxvf nginx-1.12.2.tar.gz
(sudo) unzip nginx-rtmp-module-master.zip
编译安装
生成配置文件:
进入 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
修改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; } } }
启动nginx
进入/usr/local/nginx/sbin: (sudo) ./nginx -c conf/nginx.conf
查看进程
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测试
————————————————
版权声明:本文为CSDN博主「weixin_41730450」的原创文章,遵循CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_41730450/article/details/90028598