准备工作
- nginx源代码
https://nginx.org/download/nginx-1.24.0.tar
- nginx-http-flv-module
https://github.com/winshining/nginx-http-flv-module
- PCRE, zlib and OpenSSL
https://sourceforge.net/projects/pcre/files/pcre/8.45/
https://zlib.net/current/zlib.tar.gz
https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-1.1.1w.tar.gz
将nginx解压到一个文件夹,并在其中新建objs文件夹,将其余四个文件复制到objs/lib中(注:不建议有目录中有中文名称)

编译
安装MSYS2 MSYS,该工具可在windows环境下提供编译功能
https://www.msys2.org/
进入到目录下

执行以下命令,这里要注意objs文件夹下的路径要写对,如果下载版本和我的不一致,需要对应修改文件名
auto/configure \
--with-cc=cl \
--with-debug \
--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.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=objs/lib/pcre-8.45 \
--with-zlib=objs/lib/zlib-1.3.1 \
--with-openssl=objs/lib/openssl-1.1.1c \
--with-openssl-opt=no-asm \
--add-module=objs/lib/nginx-http-flv-module \
--with-http_ssl_module
出现以下内容即表示成功。
打开x86 Native Tools Command Prompt for VS 2022,来到nginx目录,输入nmake,如果出现以下问题,说明需要安装perl

重新编译,最后编译成功
补充,sed为linux指令,需要单独安装并配置环境变量
配置
在nginx目录下新建文件夹logs、temp。将objs目录下的nginx.exe复制到nginx目录下,根据以下内容完成配置,即可启动。
worker_processes 1;
events {
worker_connections 1024;
}
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;
rtmp {
server {
listen 1935; #监听的端口号
chunk_size 8192; # 单一推流数据包的最大容量
application dfx { # 创建rtmp应用hls
live on; # 当路径匹配时,开始播放
allow publish 127.0.0.1;
allow play all;
}
}
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location /dfx {
flv_live on; # 启用 HTTP-FLV
}
location /flv {
add_header 'Access-Control-Allow-Origin' '*'; # 允许跨域
flv_live on;
chunked_transfer_encoding on; # 启用分块传输编码
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
参考链接:https://blog.csdn.net/byna11sina11/article/details/117735684
附:本文提供已编译完成的推流服务器压缩包,可直接运行使用。下载资源即可获取
8771

被折叠的 条评论
为什么被折叠?



