Set up on-demand video on nginx (MP4 playback)

Source: Internet
Author: User
Tags geoip image filter install openssl openssl library install perl nginx server automake

First, there must be a GCC-C ++ Environment

Yum-y install gcc-C ++

1Use openresty

Openresty of 1.11.2.1 and OpenSSL of 1.0.2 are used here.

      [email protected]: ~#yum install readline-devel pcre-devel openssl-devel gcc      [email protected]: ~# tar -zxvf openresty-1.11.2.1.tar.gz      [email protected]: ~#tar -zxvf openssl-1.0.2h.tar.gz      [email protected]: ~#cd openresty-1.11.2.1      [email protected]: ~#./configure --prefix=/app/openresty --user=xxx --group=xxx --with-http_v2_module --with-openssl=/home/appdeploy/nginx/openssl-1.0.2h --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_sub_module --with-http_stub_status_module --with-http_perl_module --with-http_mp4_module --with-http_flv_module

 

You can set user and group here, or use the following command later.

Chown-R [user]: After the command above the folder name is executed, compile and install openrestry. The installation directory is the/APP/openrestry specified in the configuration.

   [email protected]: ~#make && make install

 

If you do not have the permission during installation, you can use Su to switch to root. Pay attention to the permission of the openrestry directory after installation.
After openrestry is installed, go to the installation directory and modify the nginx. conf configuration file in the nginx folder of openrestry.

Worker_processes 1; # Number of worker processes, which can be set to 1. # error_log/usr/local/nginx/logs/error. log crit; # PID/usr/local/nginx/logs/nginx. PID; events {use epoll; worker_connections 65535;} HTTP {include mime. types; default_type application/octet-stream; log_format main '$ remote_addr-$ remote_user [$ time_local] ''" $ request "$ Status $ bytes_sent'' "$ http_referer" "$ http_user_agent" ''" $ gzip_ratio "'; keepalive_timeou T 60; Limit 128; client_header_buffer_size 32 K; limit 4 32 K; access_log off; gzip on; gzip_min_length 1100; gzip_buffers 4 8 K; gzip_types text/plain; output_buffers 1 32 K; postpone_output 1460; client_header_timeout 3 m; interval 3 m; send_timeout 3 m; sendfile on; tcp_nopush on; tcp_nodelay on; server {Listen 8080; SERVER_NAME 10.202.94.16; R OOT/APP/openresty/nginx/html/; limit_rate_after 30 m; limit_rate 700 K; # Set this parameter as needed. The speed limit is 700 K/s index index.html after the video buffer is 30 m; charset UTF-8; location ~ \. FLV $ {FLV;} location ~ \. MP4 $ {MP4;} error_page 500 502 503 504/50 x.html; location =/50x.html {root HTML ;}}}

 

After modification, start the nginx Server

  [email protected]: ~#/app/openresty/nginx/sbin/nginx -c /app/openresty/nginx/conf/nginx.conf

Put the MP4 file in the/APP/openresty/nginx/html/directory.
Access http: // 10.202.94.16: 8080/xxx.mp4 in a browser.

2Use nginx

We recommend that you use nginx later than nginx 1.1.3. By default, MP4 is supported, so you do not need to install a bunch of complicated plug-ins. Version 1.3.14 is used here.

  [email protected]: ~# tar -zxvf nginx-1.3.14.tar.gz  [email protected]: ~# cd nginx-1.3.14  [email protected]: ~# ./configure --prefix=/app/nginx --user=xxx --group=xxx --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_sub_module --with-http_stub_status_module --with-http_perl_module --with-http_mp4_module --with-http_flv_module  [email protected]: ~# make&& make install

 

Then, modify nginx in/APP/nginx as in openrestry. Pay attention to modifying the directory.

The effect is as follows. The video is displayed across the entire screen. If you want to modify the video, such as embedded videos on the page, you can place the videoHTML5Page, and then access the HTML file through the nginx server. There is an open-source video.JSIt is easy to use. I will not go into details here.

 

Handle error messages:


Download the nginx package from http://nginx.org/download/nginx-1.9.15.tar.gz( or wget http://nginx.org/download/nginx-1.9.15.tar.gzdirectly on linux)

Decompress the package and go to the directory.

  [email protected]: ~# tar -zxvf nginx-1.9.15.tar.gz  [email protected]: ~# cd nginx-1.9.15


Set Configuration Information

[Email protected]: ~ #./Configure -- prefix =/usr/local/nginx, or do not execute this step.


Compile and install

    [email protected]: ~# make    [email protected]: ~# make install


The make process is to convert source code files written in various languages into executable files and various library files;
Make install copies the compiled executable files and library files to appropriate places.

The configuration information may be incorrect.

[Email protected]: ~ #./Configure -- prefix =/usr/local/nginx, the following error occurs:/configure: error: the HTTP rewrite module requires the PCRE Library.

Solution: Install PCRE
 

 [email protected]: ~# yum -y install pcre pcre-devel


-Y: Skip all steps that require manual confirmation.

SSL error missing. error message: [email protected]: ~ #./Configure
Error: the HTTP cache module requires MD5 functions from OpenSSL library. you can either disable the module by using -- without-http-Cache option, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using -- with-http_ssl_module -- With-OpenSSL = <path> options.


Solution: Install OpenSSL

  [email protected]: ~# yum -y install openssl openssl-devel


The compiler is missing. The error message is as follows:

    [email protected]: ~# ./configure    error: C compiler cc is not found


Solution: Install gcc-C ++

    [email protected]: ~# yum -y install gcc-c++ autoconf automake


Autoconf is configured automatically, and automake is compiled automatically.
The zlib package is missing. The error message is as follows:

    [email protected]: ~# ./configure:     error: the HTTP gzip module requires the zlib library.You can either disable the module by using –without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using –with-zlib=<path> option.


Solution: Install zlib

    [email protected]: ~# yum install -y zlib-devel


Libxml2 is true. The error message is as follows:

    [email protected]: ~# ./configure:     error: the HTTP XSLT module requires the libxml2/libxslt libraries. You can either do not enable the module or install the libraries.


Solution:

    [email protected]: ~# yum -y install libxml2 libxml2-dev    [email protected]: ~# yum -y install libxslt-devel


Http_image_filter_module is an integrated image processing module provided by nginx. It must be supported by GD-devel. The error message is as follows:

    [email protected]: ~# ./configure:     error: the HTTP image filter module requires the GD library.You can either do not enable the module or install the libraries.


Solution:

    [email protected]: ~# yum -y install gd-devel


The extutils is missing. The error message is as follows:

    [email protected]: ~# ./configure:     error: perl module ExtUtils::Embed is required


Solution:

    [email protected]: ~# yum -y install perl-devel perl-ExtUtils-Embed


Geoip is missing. The error message is as follows:

    [email protected]: ~# ./configure:     error: the GeoIP module requires the GeoIP library.You can either do not enable the module or install the library.


Solution:

    [email protected]: ~# yum -y install GeoIP GeoIP-devel GeoIP-data


After the installation is complete, start the installation successfully, and the/usr/local/nginx directory is as follows:
FastCGI. conf Koi-win nginx. conf. Default
FastCGI. conf. Default logs scgi_params
Fastcgi_params mime. types scgi_params.default
Fastcgi_params.default mime. types. Default uwsgi_params
HTML nginx uwsgi_params.default
Koi-UTF nginx. conf win-UTF
Start
Ensure that port 80 of the system is not occupied by other programs. Run the/usr/local/nginx command to start nginx,

    r[email protected]: ~# netstat -ano|grep 80


If no result is found, run the command. If no result is found, ignore this step. (SUDO must be enabled in Ubuntu; otherwise, it can only run on the foreground)

    [email protected]: ~# sudo /usr/local/nginx/nginx


Open the browser to access the IP address of this machine. If the browser displays welcometo nginx! Nginx has been installed and runs successfully.

 

 

Live Video construction:

Rtmp Protocol

Set up on-demand video on nginx (MP4 playback)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.