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