写在前面的话,尝试了好多版本组合最终nginx-1.20.1和nginx-vod-module1.28组合顺利编译部署视频测试通过,如有疑问评论区回复
yum -y install wget ntpdate
第一节:安装nginx
一:下载Nginx和点播模块
离线下载地址:http://nginx.org/en/download.html
wget http://nginx.org/download/nginx-1.20.1.tar.gz
wget https://github.com/kaltura/nginx-vod-module/archive/refs/tags/1.28.tar.gz
二:移动文件
mv nginx-1.20.1.tar.gz /usr/local/src/
mv 1.28.tar.gz /usr/local/src/
三:解压文件
tar -zxvf nginx-1.20.1.tar.gz
tar -zxvf 1.28.tar.gz
四:安装编译器和依赖
yum install -y gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y
五:同步服务器时间
timedatectl set-timezone Asia/Shanghai
ntpdate ntp.aliyun.com
六:编译安装
1.切换目录
cd /usr/local/src/nginx-1.20.1
2.设定编译参数并编译安装
./configure --prefix=/usr/local/nginx-1.20.1 --with-http_v2_module --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-pcre --with-cc-opt='-O0 -gstabs+3' --add-module=../nginx-vod-module-1.28/
make && make install
3.链接
ln -sf /usr/local/nginx-1.20.1/ /usr/local/nginx
4.测试
/usr/local/nginx/sbin/nginx -t
七:Nginx启动
cd /usr/local/nginx/sbin
./nginx
八:Nginx停止
./nginx -s quit
./nginx -s stop
kill Nginx主进程ID
killall nginx
如果没有killall 用yum install -y psmisc安装
./nginx -s reload #重新加载配置文件
./nginx -s reopen
第二节:添加系统环境变量
echo $PATH
ln -sf /usr/local/nginx/sbin/nginx /usr/local/sbin/nginx
一:添加系统服务
vi /usr/lib/systemd/system/nginx.service
[Unit]
Description=The nginx HTTP and reverse proxy service
Documentation=http://nginx.org/en/docs/
After=network.target
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx
ExecStartPost=/bin/sleep 1
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
PrivateTmp=true
[Install]
WantedBy=default.target
二:修改文件权限
chmod 755 /usr/lib/systemd/system/nginx.service
三:开机启动
systemctl enable nginx
安装netstat
yum install net-tools
netstat -anlp | grep ":80"
四:测试
curl http://192.168.56.101
五:修改防火墙
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
########配置nginx.conf 新网站测试
server {
listen 80;
server_name xxx.com;
index index.html index.htm;
alias /www/xxx.com;
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md){
return 404;
}
}
vi /usr/local/nginx-1.20.1/conf/nginx.conf
##########user www www;
include /www/conf/nginx/*.conf;
########配置nginx.conf
location /vod {
vod hls; # 协议使用hls模式
vod_mode local; # 访问模式指定为local模式
vod_align_segments_to_key_frames on; # 每个切片以关键帧开头
vod_manifest_segment_durations_mode accurate; # 精确显示每个切片的长度
# 解决浏览器跨域问题
add_header Access-Control-Allow-Headers '*';
add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
add_header Access-Control-Allow-Origin '*';
alias /media; # 视频文件路径
}