Use nginx and nginx-rtmp-module in Ubuntu to set up the correct posture of the Streaming Media Server. nginxrtmpmodule

Source: Internet
Author: User

Use nginx and nginx-rtmp-module in Ubuntu to set up the correct posture of the Streaming Media Server. nginxrtmpmodule

When I used nginx and nginx-rtmp-module to build a Streaming Media Server, I encountered an embarrassing problem: when I added the nginx-rtmp-module to nginx, I first uninstalled the original nginx, and then downloaded the source code of nginx and nginx-rtmp-module to re-compile and install it. after the reinstallation, I tested that it is normal for the streaming media server, but then the problem arises, because I have some WEB projects deployed in the previously established LUMP environment, and now I have reinstalled nginx, these projects need to be redeployed. as a result, I began to redeploy these WEB projects, but the results left me crying in the toilet, because the nginx directory structure has changed a lot, as a result, I cannot configure the original WEB project. after that, I have been struggling for a long time and found many solutions on the Internet. However, most of these solutions focus on how to compile and install nginx and perform the push-pull flow test, I am not involved in this issue. later, when I browsed the post, I saw someone saying that I had compiled ng The slave executable file can be replaced with the original nginx shared library to solve the problem, so I immediately tried it and found that it was OK! Currently, nginx can run streaming media services and deploy WEB projects simultaneously!

The following is a brief introduction of my operation process, hoping to help you with the same problem (my configuration environment: Ubuntu Server 16.04 + nginx1.10.0 + nginx-rtmp-module-master ).

1. Install nginx in apt-get mode first. The nginx version installed in this mode is 1.10.0.

sudo apt-get update2 sudo apt-get install nginx

2. create a directory with your name under your favorite directory to store the source code of nginx and nginx-rtmp-module, for example: I created the nginx directory under the root directory/softwares (softwares is also created by myself). Next I will download nginx and nginx-rtmp-module to the nginx directory.

 cd softwares/2 sudo mkdir nginx

3. Enter the nginx directory.

 cd nginx/

4. download nginx source code. Note: The downloaded source code version must be consistent with the nginx version installed in step 1 to avoid unnecessary problems. there are many ways to obtain the nginx source code. We recommend two methods here.

Method a: run the apt-get source nginx command on the terminal to directly obtain the source code of the corresponding version.

 sudo apt-get source nginx

After downloading this method will automatically decompress, The nginx-1.10.0 directory is nginx source directory.

Method B: Find the corresponding version on the nginx official website and download it.

 sudo wget http://nginx.org/download/nginx-1.10.0.tar.gz

After downloading this method, manually decompress it. The decoding command is as follows:

 sudo tar zxvf nginx-1.10.0.tar.gz

5. Download The nginx-rtmp-module source code.

 sudo wget https://github.com/arut/nginx-rtmp-module/archive/master.zip

Because nginx-rtmp-module has been open source on GitHub, you can also get it directly from GitHub. GitHub address: https://github.com/arut/nginx-rtmp-module.

6. decompress the nginx-rtmp-module source code package.

 sudo unzip master.zip

7. Go to the nginx source code directory.

 cd nginx-1.10.0/

8. view the current nginx configuration information and save the current configuration information to a complete place. Later, You need to configure the nginx source code based on the current configuration information.

 nginx -V

Note that the value V in the command line is in upper case. Only the nginx version is displayed in lower case. The current nginx configuration information is as follows:

--with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads

9. Configure the nginx source code compilation information and add the nginx-rtmp-module to nginx.


 sudo ./configure --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads --add-module=../nginx-rtmp-module-master


Note that this line of command is actually composed of the following: sudo. /configure <original configuration information> -- add-module = .. /nginx-rtmp-module-master. in this way, the nginx-rtmp-module is added to the nginx configuration, and the previously saved nginx configuration information is added to the configuration information used for this compilation, make sure that the compiled nginx is consistent with the original nginx function. I have carefully learned that I did not write all the original configuration information When configuring nginx information, because if I copied and pasted all the information, some poorly handled errors may occur during compilation. These errors are not found a good solution at half past one, so some configuration information is reduced, after the scale-down, there is no big difference in the functional modules, so you can use it with confidence.

10. After the configuration is complete, run the make command to compile the nginx source code. After the compilation is complete, the nginx executable file will be generated under the objs directory of the nginx source code directory.

 sudo make

11. copy the generated nginx executable file to the/usr/sbin directory to replace the original nginx shared library file. note: The original/usr/sbin directory contains an nginx shared library file, which is replaced by the compiled nginx executable file.

 sudo nginx /usr/sbin

12. Restart nginx.

 sudo service nginx restart

13. Check nginx configuration again.

 nginx -V

We can see that the nginx-rtmp-module has been added to nginx.

 --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_v2_module --with-http_sub_module --with-http_xslt_module --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-threads --add-module=../nginx-rtmp-module-master

I tried to push the stream and pull the stream. The function is normal. I ran the original WEB project again. It is also normal!

Finally, I will explain why we should first install nginx through apt-get and then compile and replace it. the reason is to facilitate the deployment of WEB projects in the LUMP environment. if you do not install nginx using apt-get, but directly download the source code for compilation and installation, the nginx configuration directory is incomplete, it is difficult to deploy a WEB Project (maybe some operations can also be implemented, but the specific operation still takes time to study nginx ). if you do not set up the streaming media service, we recommend that you install nginx in apt-get mode. The steps are simple and easy to use!

 


Related Article

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.