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

Practical Optimization of MySQL Paging Limit

Preface When we use query statements, we often ne...

Detailed explanation of mysql integrity constraints example

This article describes the MySQL integrity constr...

20 excellent foreign web page color matching cases sharing

This article collects 20 excellent web page color ...

Detailed explanation of setting resource cache in nginx

I have always wanted to learn about caching. Afte...

CentOS7 uses yum to install mysql 8.0.12

This article shares the detailed steps of install...

Java example code to generate random characters

Sample code: import java.util.Random; import java...

How to implement Linux deepin to delete redundant kernels

The previous article wrote about how to manually ...

Angular Cookie read and write operation code

Angular Cookie read and write operations, the cod...

Solution to the horizontal scroll bar in iframe under IE6

The situation is as follows: (PS: The red box repr...

Notes on element's form components

Element form and code display For details, please...

Detailed explanation of how to install PHP curl extension under Linux

This article describes how to install the PHP cur...

Introduction to document.activeELement focus element in JavaScript

Table of contents 1. The default focus is on the ...

Example of using js to natively implement year carousel selection effect

Preface Use js to achieve a year rotation selecti...