一、准備
1、資源
1、nginx源碼
這里版本對變異結果也有影響,其他版本有編譯失敗的情況,推薦固定這幾個版本
2、編譯工具
1、mingw
2、perl
3、nasm
4、sed
安裝完成后需要把根目錄添加進系統環境變量
3、編譯器
MSVC
由於需要使用cl.exe、link.exe和VS2015本機工具命令提示符工具,最好安裝Visual Studio 2015
安裝Visual Studio 2015默認不帶c++編譯器,安裝的時候需要手動勾選C++選項才會有cl.exe編譯器和link.exe工具(默認在C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin下)。安裝完成后將cl.exe所在目錄添加到系統環境變量
二、開始編譯
1、新建文件夾nginx-flv並解壓nginx源碼到nginx-flv下
2、在nginx-flv下新建文件夾build,進入build,在build下新建文件夾3rdlib和output
3、將nginx-http-flv-module,openssl,zlib,pcre解壓縮到nginx-flv/build/3rdlib目錄下
4、在nginx-flv目錄下新建build.bat文件並輸入以下腳本
auto/configure --with-cc=cl --builddir=build/output --prefix= \
--conf-path=conf/nginx.conf --pid-path=logs/nginx.pid \
--http-log-path=logs/access.log --error-log-path=logs/error.log \
--sbin-path=nginx-flv.exe --http-client-body-temp-path=temp/client_body_temp \
--http-proxy-temp-path=temp/proxy_temp \
--http-fastcgi-temp-path=temp/fastcgi_temp \
--http-scgi-temp-path=temp/scgi_temp \
--http-uwsgi-temp-path=temp/uwsgi_temp \
--with-cc-opt=-DFD_SETSIZE=1024 --with-pcre=build/3rdlib/pcre-8.34 \
--with-zlib=build/3rdlib/zlib-1.2.11 --with-openssl=build/3rdlib/openssl-1.0.1u \
--with-select_module --with-http_ssl_module \
--add-module=build/3rdlib/nginx-http-flv-module-master
5、最終目錄結構
nginx-flv
├─auto
├─build
│ ├─3rdlib
│ │ ├─nginx-http-flv-module-master
│ │ ├─openssl-1.0.1u
│ │ ├─pcre-8.34
│ │ └─zlib-1.2.11
│ └─output
├─conf
├─contrib
├─docs
├─misc
├─src
└─build.bat
6、打開mingw命令行工具(默認在C:\MinGW\msys\1.0\msys.bat)進入nginx-flv目錄執行build.bat,結束后會在nginx-flv/build/output目錄下生成Makefile
7、以管理員身份打開VS2015本機工具命令提示符x86進入nginx-flv目錄后運行
nmake /f build/output/Makefile
過程大概十分鍾,編譯完成后會在nginx-flv/build/output目錄下生成nginx.exe
三、部署
1、新建文件夾 nginx-rtmp
2、將剛剛編譯生成的nginx.exe拷貝到nginx-rtmp目錄下
3、將nginx源碼目錄下的conf文件夾拷貝到nginx-rtmp目錄下
4、將nginx源碼目錄下的docs/html文件夾拷貝到nginx-rtmp目錄下
5、在nginx-rtmp目錄下新建logs和temp文件夾
6、將nginx-http-flv-module目錄下的stat.xsl拷貝到nginx-rtmp/html目錄下
7、配置conf/nginx.conf文件
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#error_log logs/error.log debug;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
# 添加RTMP服務
rtmp {
server {
listen 1935; # 監聽端口
chunk_size 4000;
application live {
live on;
gop_cache on;
}
}
}
# HTTP服務
http {
include mime.types;
default_type application/octet-stream;
#access_log logs/access.log main;
server {
listen 8080; # 監聽端口
location /stat.xsl {
root html;
}
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location / {
root html;
}
}
}
8、整個服務部署文件構架如下
nginx-rtmp
│ nginx.exe
│
├─conf
│ fastcgi.conf
│ fastcgi_params
│ koi-utf
│ koi-win
│ mime.types
│ nginx.conf
│ scgi_params
│ uwsgi_params
│ win-utf
│
├─html
│ 50x.html
│ index.html
│ stat.xsl
│
├─logs
│ access.log
│ error.log
│
└─temp
├─client_body_temp
├─fastcgi_temp
├─proxy_temp
├─scgi_temp
└─uwsgi_temp
9、啟動nginx
(1)、進入nginx-rtmp目錄下雙擊 nginx.exe
(2)、cmd命令行進入nginx-rtmp目錄下執行
start /b nginx.exe -c conf\nginx.conf
10、使用ffmpeg推流,VLC拉流
11、網頁打開http://localhost:8080/stat可以看到nginx媒體流的狀態
12、關閉nginx
cmd命令行進入nginx-rtmp目錄下執行
nginx.exe –s stop
原文鏈接:
編譯:https://blog.csdn.net/kaychangeek/article/details/105095844
部署:https://blog.csdn.net/KayChanGEEK/article/details/105098588