Win10 compile Nginx-1.19.6 detailed configuration and push stream


I recently read FFMPEG's streaming related information, which is a bit messy and a bit old. First of all, let's prepare related tools. Nginx shouldn't be a big problem with the configuration on the Linux side. The compilation on the windows side may be a bit more cumbersome, so test it on windows.

Success style

Insert picture description here

Precondition

Do not have Chinese in the directory path, otherwise there will be problems with the compilation, especially prefixwhen the path setting is defined without Chinese

Download the required libraries

Package and download FFMPEG4.2.3 library files and Nginx1.19.6 source code and compiled files.
Baidu search, you can find the corresponding download address, if the download speed is slow, you can go to github to search and download

Nginx1.19.6

download link

openssl-1.1.1g

download link

pcre-8.44

download link

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

Download
opens MSYSinto the source directory, perform the following, or manually extracting Jieke

mkdir -p objs/lib
cd objs/lib
tar -xf ../../pcre-8.44.tar.bz2
tar -xf ../../zlib-1.2.11.tar.gz
tar -xf ../../openssl-1.1.1g.tar.gz

Compile dependent library files

Install related tools

Install visual studio

Download link
For its integrated tools, some Makefiles are compiled with nmake, and Microsoft's tools are used on the Windows side, which can reduce many errors

Install perl

Download
case of the Problem: Can not locate Win32 / Console.pm in @INC (you may need to install the Win32 :: Console module)
reference
Insert picture description here

Install sed for windows

Download URL Add the
path C:\Program Files (x86)\GnuWin32\bin
to the environment variable Path after installation

Compile Nginx

Open and MSYSexecute the following command to enter the Nginx source code directory:

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.8

After generating the Makefile, open the command line tool of vs, enter the Nginx directory again and execute the following compilation commands:

nmake

Open the command line tool of vs.
Insert picture description here
I choose 64-bit and enter the following to powershellenter the powershell tool. The command can be used like a Linux terminal.
Enter the directory where the Makefile file is located and execute it.

nmake

It will automatically compile openssl zlib pcre, statically link, and generate Nginx targets.

installation

The build script is install.bashplaced in the objs directory

#!/bin/bash
mkdir -p install_dir
mkdir -p .\install_dir\conf
mkdir -p .\install_dir\logs

cp .\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\

Open MSYS to execute this script

Run test

./nginx -t

Insert picture description here
For possible problems, port occupancy, confirm to uncheck, the IIS service will temporarily use port 80, causing startup errors.
Refer to the
Insert picture description here
browser input for processinglocalhost . See the following page to show that the startup is successful.
Insert picture description here

nmake compilation options

nmake /?

nmake compilation error handling

Refer here

Repost streaming test

Configure 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;
        }
	}
}

Restart Nginx

./nginx.exe -s reload

Install FFMPEG, execute the following command

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

Use VLC player, enter the streaming address to play

http://192.168.50.61:8080/live?port=1985&app=live&stream=mystream
192.168.50.61 is the server IP
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_42892101/article/details/111468465