搭建Nginx环境

1、下载Nginx源码包

curl http://nginx.org/download/nginx-1.20.1.tar.gz -o nginx-1.20.1.tar.gz

2、解压源码包

tar -zxvf nginx-1.20.1.tar.gz -C ../	# -C指定解压路径

3、配置生成文件(一般修改配置文件、日志文件路径)

./configure --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/lib/nginx/nginx.pid --with-http_v2_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module

注:需要下载配置环境

如:

yum install pcre-devel zlib-devel openssl-devel

4、make编译

5、make install安装

6、添加nginx到环境变量

ln -s /usr/local/nginx/sbin/nginx /usr/local/bin/

(注! /usr/local/nginx/sbin/nginx为nginx启动文件的绝对路径)

此时可直接使用nginx命令,如:nginx -s stop停止nginx服务

7、关闭防火墙

systemctl stop firewalld

systemctl disable firewalld #永久禁用

至此,访问80端口可看到Nginx测试页

下载任意html静态网站压缩包,解压并复制到Nginx网站路径,即可访问静态网页

8、其他注意事项

/var/lib/mysql				# mysql数据路径
/usr/local/nginx/html # Nginx默认网站路径
/etc/nginx/nginx.conf # Nginx配置文件

修改root /var/www/html即可改变默认路径

1

Nginx搭建直播推流平台

工具:

nginx-http-flv-module-master.zip + OBS Studio(pc端)/杏林推流(app端)

1、源码安装,配置

在nginx源码编译基础上,增加–add-module=/home/chen/software/nginx-http-flv-module-master(导入为绝对路径),即:

./configure --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/lib/nginx/nginx.pid --with-http_v2_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-http_ssl_module --add-module=/home/chen/software/nginx-http-flv-module-master

2、make、make install

3、修改配置文件

(/etc/nginx/nginx.conf)

在http中新增(与最内层函数同级)

location /live {

flv_live on;

chunked_transfer_encoding on;

add_header Access-Control-Allow-Origin *;

}

在文件末尾新增(与http函数同级)

rtmp {

server {

listen 1935;


application chen {

live on;

}

}

}

(注!live不可更改,会导致无法加载视频)

4、检查

nginx -t		# 检测配置文件有无语法错误
nginx -s reload # 重新加载

5、推流设置

OBS推流设置(PC)

说明 命令
服务器 rtmp://139.224.x.x/live/
串流密钥 chen(可更改,类似于密码)

杏林推流设置(APP)

rtmp://139.224.x.x/live/chen

6、观看

http://bilibili.github.io/flv.js/demo/			#观看视频地址
http://139.224.x.x/live?app=live&stream=chen #推流视频链接