1.下载
wget http://nginx.org/download/nginx-1.19.0.tar.gz
2.安装依赖
apt install openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev make
3.配置
./configure --prefix=/opt/nginx \ --with-http_ssl_module \ --http-client-body-temp-path=/opt/nginx/temp/client_body_temp \ --http-proxy-temp-path=/opt/nginx/temp/proxy_temp \ --http-fastcgi-temp-path=/opt/nginx/temp/fastcgi_temp \ --http-uwsgi-temp-path=/opt/nginx/temp/uwsgi_temp \ --http-scgi-temp-path=/opt/nginx/temp/scgi_temp
4.make &&make install
5.启动
ubuntu@ubuntu:/opt/nginx/sbin$ sudo ./nginx
ubuntu@ubuntu:/opt/nginx/sbin$
6.此时即可访问到
6.git clone rtmp扩展模块,这里是在gitee上找了一个,条件允许,请使用github
git clone https://gitee.com/tclab414/nginx-rtmp-module.git
请放在nginx源码同级目录下
7.配置
./configure --add-module=/home/ubuntu/Downloads/nginx-rtmp-module
ubuntu@ubuntu:~/Downloads/nginx-1.19.0$ ./configure --prefix=/opt/nginx --with-http_ssl_module --http-client-body-temp-path=/opt/nginx/temp/client_body_temp --http-proxy-temp-path=/opt/nginx/temp/proxy_temp --http-fastcgi-temp-path=/opt/nginx/temp/fastcgi_temp --http-uwsgi-temp-path=/opt/nginx/temp/uwsgi_temp --http-scgi-temp-path=/opt/nginx/temp/scgi_temp --add-module=/home/ubuntu/Downloads/nginx-rtmp-module
8.编译安装
sudo make -j8
sudo make install
9.修改nginx配置文件
#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;
chunk_size 4096;
application live
{
live on;
}
}
}
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;
}
#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;
# }
#}
}
#server {
# listen 8080;
# location /stat{
# rtmp_stat all;
# rtmp_stat_stylesheet stat.xsl;
# }
# location /stat.xsl{
# root /home/ubuntu/Downloads/nginx-rtmp-module;
# }
# }
10.推流
ubuntu@ubuntu:~/Videos$ ffmpeg -i abc.mp4 -f flv rtmp://192.168.186.228/live/test1
推流成功
11.拉流
ffplay rtmp://192.168.186.228/live/test1 弹出播放画面