Install nginx

Install two dependency libraries

sudo apt-get install autoconf automake
sudo apt-get install libpcre3 libpcre3-dev
Copy the code

Install zlib library

sudo apt-get install openssl
sudo apt-get install libssl-dev
Copy the code

If the following information is displayed after the installation command is entered, please refer to the “Ubuntu” “Can’t get the lock” solution “to solve the problem

E: cannot obtain the lock /var/lib/dppg/lock-open (11: Resources temporarily unavailable) E: cannot lock the management directory (/var/lib/dppg/). Is it occupied by another process?Copy the code

Go to your home directory and create a new folder, using LXF as an example

cd ~
mkdir lxf
Copy the code

Download the required source code

/ / download nginx - RTMP source wget HTTP: / / https://github.com/arut/nginx-rtmp-module/archive/master.zip / / modify the package the name of the master. The mv zip module. ZipCopy the code
/ / download nginx wget HTTP: / / https://github.com/nginx/nginx/archive/master.zipCopy the code
/ / download nginx rely on pcre wget source code for ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gzCopy the code

After the download is complete, run the unzip command to decompress the file

Zip master.zip unzip module.zip tar -zxvf pcl-8.39.tar. gzCopy the code

Configure the compile file, ready to compile and install

// Go to nginx-master directory CD nginx-master/Copy the code

In the nginx-master directory, there is an auto folder with a configuration file called configure. Let’s do some configuration with it first

Auto /configure --prefix=/usr/local/nginx --with-pcre=.. / pcl-8.39 --with-http_ssl_module --with-http_v2_module --with-http_flv_module --with-http_mp4_module --add-module=.. / pcRE-8.39 --with-http_ssl_module --with-http_v2_module --with-http_flv_module --with-http_mp4_module --add-module=.. /nginx-rtmp-module-master/Copy the code

This creates a Makefile (a configuration file that defines a set of rules for specifying compilation operations) and an objs folder

Make // install sudo make installCopy the code

When you make it, you see it compiled successfully

Now let’s go test it out

 cd /usr/local/nginx/sbin/
sudo ./nginx -t
Copy the code

If successful, the configuration file is correct. If it is failed, check whether you did not add sudo

Start the nginx server

sudo ./nginx
Copy the code

The default port is 80, so go to your browser and type in the local address 127.0.0.1. Nginx has been successfully installed

Configure nginx

Create a push stream store folder

// uses /usr/localThe/var/WWW/HLS, for examplecd /usr/local
sudo mkdir -p var/www/hls
Copy the code

Go to the conf directory of nginx and use vim to edit the nginx.conf file

cd /usr/local/nginx/conf
sudo vim nginx.conf
Copy the code

Configure Nginx to support HTTP stream pulling

location /hls {
  types {
    application/vnd.apple.mpegurl    m3u8;
    video/mp2t ts;
  }
  root /usr/local/var/www;
   add_header Cache-Control    no-cache;
}
Copy the code

Configure Nginx to support RTMP stream pushing

rtmp { server { listen 1935; application rtmplive { live on; max_connections 1024; } application hls{ live on; hls on; hls_path /usr/local/var/www/hls; hls_fragment 1s; }}}Copy the code

Restart the nginx server

cd /usr/local/nginx/sbin/
sudo ./nginx -s reload
Copy the code

If sudo./nginx -s reload is executed, the following problem occurs

nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
Copy the code

Use the nginx -c parameter to specify the location of the nginx.conf file, and reload it

sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
Copy the code

My Ubuntu address is 192.168.123.191

Push to RTMP to server RTMP: / / 192.168.123.191:1935 / rtmplive/LXF

Ffmpeg-re-i profiled. Mp4-vcodec libx264 -vprofile Baseline -acodec AAC-AR 44100-strict-2 - AC 1-f flv -s1280 x720 - q 10 RTMP: / / 192.168.123.191:1935 / rtmplive/LXFCopy the code

Push to HLS to http://192.168.123.191/hls/lxf.m3u8 on the server

Ffmpeg-re-i profiled. Mp4-vcodec libx264 -vprofile Baseline -acodec AAC-AR 44100-strict-2 - AC 1-f flv -s1280 x720 - q 10 RTMP: / / 192.168.123.191:1935 / HLS/LXFCopy the code

If the following error occurs, ffMPEG is not installed on your computer

-bash: ffmpeg: command not found
Copy the code

Use Homebrew to install FFmpeg

/ / install Homebrew ruby - e "$(curl - fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" / / install FFmpeg brew  install ffmpegCopy the code

Start to push the stream, the terminal began to constantly refresh the stream information

We can use the software VLC on the computer to test whether the stream is successfully pushed

OK, RMTP is open normally, HLS will not be demonstrated, the same