提示:首先查看最近最近的服务器有没有开启防火墙
提示:后续会更加完善加入:nginx-http-flv-module、ffmpeg-4.2.3、openssl-1.0.2l、pcre-8.38、zlib-1.2.11
提示:以下是本篇文章正文内容,下面案例可供参考
# 关闭防火墙
systemctl stop firewalld
# 禁用防火墙
systemctl disable firewalld
#查看防火墙的状态
systemctl status firewalld
# 安装wget
yum -y install wget
# 安装 gcc gcc-c++
yum -y install gcc gcc-c++
# 安装PCRE库
cd /usr/local/
wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
tar -zxvf pcre-8.33.tar.gz
cd pcre-8.33
./configure
make && make install
# 安装openssl
cd /usr/local/
wget http://www.openssl.org/source/openssl-1.0.1j.tar.gz
tar -zxvf openssl-1.0.1j.tar.gz
cd openssl-1.0.1j
./config
make && make install
### 如果提示You need Perl 5,则输入下面这个命令。 ###
yum -y install Perl 5
# 安装zlib
/**
*注意如果一下地址出现404,
*可以到网上找一个zlib相关的包然后用Xftp传入到服务器中
*/
cd /usr/local/
wget http://zlib.net/zlib-1.2.11.tar.gz
tar -zxvf zlib-1.2.11.tar.gz
./configure
make && make install
# git clone
cd /usr/local/
yum -y install git
git clone https://github.com/arut/nginx-rtmp-module.git
# 安装nginx
cd /usr/local/
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/src/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-http_sub_module --with-http_ssl_module --add-module=../nginx-rtmp-module --with-openssl=<path> --with-http_ssl_module
make && make install
###如果提示###
./configure: error: SSL modules require the OpenSSL library.
#执行
yum -y install openssl openssl-devel
#如果提示
yum -y install pcre-devel
#nginx相关命令
/usr/local/src/nginx/sbin/nginx
#如果启动不了,进入到/usr/local/src/nginx/sbin文件中用如下命令
./nginx : 启动nginx
./nginx -s stop : 停止nginx
./nginx -s reload : 重启nginx
user root;
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 4000;
drop_idle_publisher 10s; #指定的时间内丢弃空闲的publisher
application rtmplive {#rtmp推流请求路径 (切记路径错了会推不上流)
record off;
live on; #开启实时
hls on; #开启hls
hls_path /usr/local/nginx/hegui; #rtmp推流请求路径,文件存放路径
hls_continuous on; #切片编号从上一次结束开始
hls_fragment 5s; #每个TS文件包含5秒的视频内容
}
}
}
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;
location /rtmplive {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /usr/local/nginx/hegui;
chunked_transfer_encoding on;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Origin' '*';
add_header Access-Control-Allow-Headers X-Requested-With;
add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
add_header 'Cache-Control' 'no-cache';
#ngx_fastdfs_module;
#add_header Cache-Control no-cache;
#expires -1;
}
# location / {
# root html;
# index index.html index.htm;
# }
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#项目
server {
listen 163;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
#vue项目的打包后的dist
root /www/test/dist/;
location /{
try_files $uri $uri/ @router;#需要指向下面的@router否则会出现vue的路由在nginx中刷新出现404
index index.html index.htm;
}
#对应上面的@router,主要原因是路由的路径资源并不是一个真实的路径,所以无法找到具体的文件
#因此需要rewrite到index.html中,然后交给路由在处理请求资源
location @router {
rewrite ^.*$ /index.html last;
}
location /api {
proxy_pass http://*.*.*.*:9001/;
#proxy_pass http://&env;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header REMOTE-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
rewrite ^/api/(.*) /$1 break;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
#nacos配置
location /nacos/ {
rewrite ^//(.*)$ /$1 break;
proxy_pass http://*.*.*.*:8080/nacos;
proxy_set_header Host $host;
proxy_set_header User-Agent $http_user_agent;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header authorization $http_authorization;
}
#error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
# 推流地址
rtmp://*.*.*.*:1935/就是下面的application 后面跟的名字/你推流的文件名(不要后缀)
# 下载一个VLC 进行拉流 拉流地址
rtmp://*.*.*.*:1935/就是下面的application 后面跟的名字/你推流的文件名
#流媒体
rtmp {
server {
listen 1935; #监听的端口
chunk_size 4000;
drop_idle_publisher 10s; #指定的时间内丢弃空闲的publisher
application rtmplive { #rtmp推流请求路径 (切记路径错了会推不上流)
record off;
live on; #开启实时
hls on; #开启hls
hls_path /usr/local/nginx/hegui; #rtmp推流请求路径,文件存放路径
hls_continuous on; #切片编号从上一次结束开始
hls_fragment 5s; #每个TS文件包含5秒的视频内容
}
}
}
自己测试了,是可以的,有问题评论,或者私信!