Win10编译Nginx-1.19.6详细配置

piaoxue888 2022-11-9 440

最近看了下FFMPEG的推流相关资料,有点杂乱也有点老,首先第一步吧,准备相关工具。Nginx在linux端使用配置应该没多大问题,在windows端的编译可能繁琐一点,那么就在windows上测试吧。

成功样式

在这里插入图片描述

前提条件

目录路径不要有中文,不然编译会有问题,特别是定义prefix时路径设置不要有中文

下载所需库

打包下载FFMPEG4.2.3库文件和Nginx1.19.6源码及编译文件
百度搜索,即可找到对应下载地址,如遇下载速度慢,可以前往github搜索下载

Nginx1.19.6

下载地址

openssl-1.1.1g

下载地址

pcre-8.44

下载地址

zlib-1.2.11

下载地址
nginx-http-flv-module has all features that nginx-rtmp-module provides, so DON’T compile nginx-http-flv-module along with nginx-rtmp-module.

nginx-http-flv-module

下载地址
打开 MSYS进入源码目录,执行以下,或者手动解压皆可

mkdir -p objs/libcd objs/libtar -xf ../../pcre-8.44.tar.bz2tar -xf ../../zlib-1.2.11.tar.gztar -xf ../../openssl-1.1.1g.tar.gz12345

编译依赖库文件

安装相关工具

安装visual studio

下载地址
要它的集成工具,有些Makefile就是使用nmake去编译,Windows端就用微软的工具吧,能减少很多错误

安装perl

下载地址
如遇以下问题处理:Can’t locate Win32/Console.pm in @INC (you may need to install the Win32::Console module)
参考
在这里插入图片描述

安装sed for windows

下载地址
安装后将路径C:\Program Files (x86)\GnuWin32\bin
加入到环境变量Path中

编译Nginx

打开MSYS执行以下命令进入Nginx源码目录:

auto/configure --with-cc=cl --with-debug --prefix=install_dir --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.44 --with-zlib=objs/lib/zlib-1.2.11 --with-openssl=objs/lib/openssl-1.1.1g --with-openssl-opt=no-asm --with-http_ssl_module --with-http_sub_module --add-module=objs/lib/nginx-http-flv-module-1.2.81

生成Makefile后,打开vs的命令行工具,再次进入到Nginx目录执行以下编译命令:

nmake1

打开vs的命令行工具
在这里插入图片描述
我选择64位的,输入以下powershell进入powershell工具,命令可以像linux终端一样用了
进入Makefile文件所在目录执行

nmake1

将自动编译openssl zlib pcre,静态链接,生成Nginx目标。

安装

建立脚本install.bash放在objs目录下

#!/bin/bashmkdir -p install_dirmkdir -p .\install_dir\confmkdir -p .\install_dir\logscp .\nginx.exe .\install_dir\cp ..\conf\koi-win .\install_dir\conf\cp ..\conf\koi-utf .\install_dir\conf\cp ..\conf\win-utf .\install_dir\conf\cp ..\conf\mime.types .\install_dir\conf\cp ..\conf\fastcgi.conf .\install_dir\conf\cp ..\conf\fastcgi_params .\install_dir\conf\cp ..\conf\uwsgi_params .\install_dir\conf\cp ..\conf\scgi_params .\install_dir\conf\cp ..\conf\nginx.conf .\install_dir\conf\cp -R ..\docs\html .\install_dir\12345678910111213141516

打开MSYS执行此脚本

运行测试

./nginx -t1

在这里插入图片描述
对于可能出现的问题,端口占用,确认取消勾选,IIS服务会暂用80端口,导致启动出错。
处理参考
在这里插入图片描述
浏览器输入localhost,见如下页面说明启动成功。
在这里插入图片描述

nmake编译选项

nmake /?1

nmake编译报错处理

参考这里

转推流测试

配置Nginx

nginx.conf

#user  nobody;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;}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;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
	
    server {
        listen       8080;
        server_name	 localhost;
		
		location /live {
			flv_live on; #打开 HTTP 播放 FLV 直播流功能
            chunked_transfer_encoding  on; #支持 'Transfer-Encoding: chunked' 方式回复
			add_header 'Access-Control-Allow-Credentials' 'true'; #添加额外的 HTTP 头
			add_header 'Access-Control-Allow-Origin' '*'; #添加额外的 HTTP 头
			add_header Access-Control-Allow-Headers X-Requested-With;
			add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
			add_header 'Cache-Control' 'no-cache';
        }
	}}rtmp {
    out_queue           4096;
    out_cork            8;
    max_streams         128;
    timeout             15s;
    drop_idle_publisher 15s;

    log_interval 5s; #log 模块在 access.log 中记录日志的间隔时间,对调试非常有用
    log_size     1m; #log 模块用来记录日志的缓冲区大小
	
    server {
        listen 1985;
		server_name aron566; #用于虚拟主机名后缀通配
        application live {  
            live on;
        }
	}}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149

重新启动Nginx

./nginx.exe -s reload1

安装FFMPEG,执行以下命令

ffmpeg -i rtmp://58.200.131.2:1935/livetv/jstv -vcodec copy -acodec copy -f flv rtmp://localhost:1985/live/mystream1

使用VLC播放器,输入拉流地址播放

http://192.168.50.61:8080/live?port=1985&app=live&stream=mystream
192.168.50.61为服务器IP


最新回复 (0)
返回
发新帖