Use nginx and nginx-rtmp-module to build a streaming media server

零下一度
Release: 2017-06-29 11:11:43
Original
2363 people have browsed it

I encountered a very embarrassing problem when using nginx and nginx-rtmp-module to build a streaming media server. That was the approach I initially took when adding the nginx-rtmp-module module to nginx. First uninstall the original nginx, then download the source code of nginx and nginx-rtmp-module, recompile and install it. After reinstalling, I tested the streaming media server and it was normal, but then the problem came because I had some WEB The projects were deployed in the LUMP environment that was built before. Now that nginx has been reinstalled, these projects need to be redeployed. So, I started to redeploy these WEB projects, but the result made me cry in the toilet because the directory of nginx The structure has changed a lot, so I can't configure the original WEB project. After that, I struggled and wandered for a long time. I searched for many solutions on the Internet, but most of these solutions focused on how to compile and install nginx and The push-pull flow test did not involve my problem. Later, when I was browsing the post, I saw someone saying that replacing the original nginx shared library with the nginx executable file compiled by myself could solve the problem, so I immediately tried it. It turned out that it really works! Now nginx can run streaming media services and deploy WEB projects at the same time, and have the best of both worlds!

Let me briefly introduce my operation process, hoping to help others who encounter the same problem. If you have a problem, please bring some help (my configuration environment: Ubuntu Server 16.04 + nginx1.10.0 + nginx-rtmp-module-master).

 1. First install nginx using apt-get. Currently using The version number of nginx installed in this way is 1.10.0

1 sudo apt-get update2 sudo apt-get install nginx
Copy after login

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

1 cd softwares/2 sudo mkdir nginx
Copy after login

3. Enter the nginx directory.

1 cd nginx/
Copy after login

4. Download the nginx source code. Note: The downloaded source code version needs to be consistent with the version of nginx installed in step 1. , to avoid unnecessary problems. There are many ways to obtain nginx source code. Here are two methods recommended.

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

1 sudo apt-get source nginx
Copy after login

This method will automatically decompress after downloading. The nginx-1.10.0 directory is the nginx source code directory.

Method b: Find the corresponding version on the official website of nginx and then Download.

1 sudo wget nginx.org/download/nginx-1.10.0.tar.gz
Copy after login

After downloading in this way, you need to manually decompress it yourself. Decoding command:

1 sudo tar zxvf nginx-1.10.0.tar.gz
Copy after login

5. Download nginx-rtmp-module Source code.

1 sudo wget github.com/arut/nginx-rtmp-module/archive/master.zip
Copy after login

Because nginx-rtmp-module is open source on GitHub, you can also get it directly from GitHub. GitHub address:

6. Unzip nginx- Compressed package of rtmp-module source code.

1 sudo unzip master.zip
Copy after login

7. Enter the nginx source code directory.

1 cd nginx-1.10.0/
Copy after login

8. View the current nginx configuration information, And save the current configuration information completely to one place. Later, when compiling the nginx source code, you need to configure it based on the current configuration information.

1 nginx -V
Copy after login
Copy after login

Note that the V in the command line is capitalized. , only the version number of nginx can be seen in lowercase. My 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
Copy after login

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

1 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
Copy after login

Note that this line of command actually consists of: sudo ./configure --add-module=../nginx-rtmp- module-master. In this way, 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, ensuring that the compiled nginx is as consistent as the original The functions of nginx are consistent. Careful students will find that I actually did not write in all the original configuration information when configuring nginx information. The reason is that if I copy and paste them all, there will be some problems that are not easy to deal with during compilation. I haven't found a good solution for these errors for a while, so I reduced some configuration information. After the reduction, there is not much difference in the functional modules, so you can use it with confidence.

 10. After the configuration is completed, execute the make command to start compiling the nginx source code. After the compilation is completed, the nginx executable file will be generated in the objs directory of the nginx source code directory.

1 sudo make
Copy after login

 11. Will the generated nginx Copy the executable file to the /usr/sbin directory and replace the original nginx shared library file. Note: There is an nginx shared library file in the /usr/sbin directory. We use the compiled nginx executable file to replace it.

1 sudo nginx /usr/sbin
Copy after login

12. Restart nginx.

1 sudo service nginx restart
Copy after login

13. Check the nginx configuration information again.

1 nginx -V
Copy after login
Copy after login

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

1 --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
Copy after login

I tried pushing and pulling the stream, and the function was normal. I ran the original WEB project again, and it was normal!

Finally, I will explain why we need to install nginx through apt-get first, and then Compile and replace. The reason is to facilitate the deployment of WEB projects in the LUMP environment. If you do not install nginx through apt-get first, but directly download the source code to compile and install, the nginx configuration directory will be incomplete and it will be difficult to deploy WEB Project (deployment may also be achieved through certain operations, but you still need to spend time studying nginx for the specific operation). If you do not build a streaming media service, I recommend installing nginx through apt-get. The steps are simple and worry-free. !

The above is the detailed content of Use nginx and nginx-rtmp-module to build a streaming media server. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!