How to use Nginx to carry rtmp live server

How to use Nginx to carry rtmp live server

This time we set up an rtmp live broadcast server for computers or mobile phones to push live streams to the server, and then other terminals such as computers or mobile phones can watch the live video. Here we use computer screen recording software to broadcast the real-time recorded computer screen images to other people. A total of three parts are required. First, the screen recording software records the computer screen and transmits the picture stream to the server. Second, the server rtmp is set up and should be able to receive the pictures uploaded by the screen recording software. Third, the video player client can connect to the rtmp server and receive the video stream pushed by the rtmp server, so that the real-time picture of the screen recording software in the first part can be watched in real time. The core here is the second part, building an rtmp server.

1. Download nginx

Nginx is a server software, similar to tomcat, used to publish server programs

(1) Download address: Execute the wget http://nginx.org/download/nginx-1.15.3.tar.gz command in Linux to download the compressed package.

(2) Decompress using the tar command: tar xvf nginx-1.15.3.tar.gz

2. Download nginx rtmp module

​ wget https://codeload.github.com/arut/nginx-rtmp-module/tar.gz/v1.2.1 Unzip the same tar xvf v1.2.1

3. Compile nginx

./configure --prefix=./bin --add-module=../nginx-rtmp-module-1.2.1

4. Modify the conf file in nginx-rtmp-module

cd nginx-rtmp-module-1.2.1 to open the folder, cd test folder, and modify the content of the nginx.conf file to:

worker_processes 1;
 
error_log logs/error.log debug;
 
events {
    worker_connections 1024;
}
 
rtmp {
    server {
        listen 1935;
 
        application myapp {
            live on;
 
            #record keyframes;
            #record_path /tmp;
            #record_max_size 128K;
            #record_interval 30s;
            #record_suffix .this.is.flv;
 
            #on_publish http://localhost:8080/publish;
            #on_play http://localhost:8080/play;
            #on_record_done http://localhost:8080/record_done;
        }
    }
}
 
http {
    server {
        listen 8080;
 
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
 
        location /stat.xsl {
            root /path/to/nginx-rtmp-module/;
        }
 
        location /control {
            rtmp_control all;
        }
 
        #location /publish {
        # return 201;
        #}
 
        #location /play {
        # return 202;
        #}
 
        #location /record_done {
        # return 203;
        #}
 
        location /rtmp-publisher {
            root /path/to/nginx-rtmp-module/test;
        }
 
        location / {
            root /path/to/nginx-rtmp-module/test/www;
        }
    }
}

The streaming address will be rtmp://IP:PORT/myapp/{abc}, where abc in {abc} is optional and is usually a streaming password. When pushing or receiving video streams to the server, you can fill in a password, such as abc. The default rtmp server port is 1935. If this port is occupied, you can kill the process occupying this port using the following command:

kill -9 pid (where pid is the process id).

Then replace nginx.conf under nginx-1.15.3/bin/conf with this conf,

Run the mv nginx.conf nginx.conf.bak command to rename the original nginx.conf without deleting the original file.

5. Start nginx

cd nginx-1.15.3

Open the nginx folder

/root/nginx-1.15.3/bin/sbin/nginx

Start nginx

6. Verify whether nginx rtmp streaming media is deployed successfully

After startup, access 122.112.220.253:8080 from your browser.

If it doesn't open,
1. Create security rules on the server, develop entry rules, open ports 1935 and 8080, and use TCP as the protocol.
2. In nginx.conf under nginx-1.15.3/bin/conf, modify the user at the top: user root;

At this point, the content of nginx.conf is as follows:

user root;
worker_processes 1;
 
error_log logs/error.log debug;
 
events {
    worker_connections 1024;
}
 
rtmp {
    server {
        listen 1935;
 
        application myapp {
            live on;
	    drop_idle_publisher 5s;
        }
    }
}
 
http {
    server {
        listen 8082;
 
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
 
        location /stat.xsl {
            root /root/nginx-rtmp-module-1.2.1/;
        }
 
        location /control {
            rtmp_control all;
        }
 
    
 
        location /rtmp-publisher {
            root /root/nginx-rtmp-module-1.2.1/test;
        }
 
        location / {
            root /root/nginx-rtmp-module-1.2.1/test/www;
        }
    }
}

3. Restart nginx and access 122.112.220.253:8082 again. Success.

Next time we will use a screen recording software to record the computer screen, use the rtmp protocol to push the computer screen image to the server, and use a player to play the rtmp live stream on the server.

This is the end of this article about using Nginx to carry rtmp live broadcast server. For more relevant rtmp live broadcast server content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Nginx builds rtmp live server implementation code
  • Detailed explanation of configuring Nginx+RTMP+HLS+HTTPFLV server in Ubuntu 18.04 to realize on-demand/live broadcast/recording functions
  • Detailed steps to build nginx+rtmp live server on Mac

<<:  Why is the MySQL auto-increment primary key not continuous?

>>:  Div css naming standards css class naming rules (in line with SEO standards)

Recommend

How to assign default values ​​to fields when querying MySQL

need When querying a field, you need to give the ...

Solution to 1067 when Mysql starts in Windows

I just started working a few days ago and install...

How to configure two-way certificate verification on nginx proxy server

Generate a certificate chain Use the script to ge...

Detailed explanation of Apache website service configuration based on Linux

As an open source software, Apache is one of the ...

How to convert a string into a number in JavaScript

Table of contents 1.parseInt(string, radix) 2. Nu...

Detailed explanation of the watch listener example in vue3.0

Table of contents Preface The difference between ...

How many common loops do you know about array traversal in JS?

Preface As a basic data structure, arrays and obj...

Teach you to implement a simple promise step by step

Table of contents Step 1: Build the framework Ste...

Binary Type Operations in MySQL

This article mainly introduces the binary type op...

Steps for installing MySQL 8.0.16 on Windows and solutions to errors

1. Introduction: I think the changes after mysql8...