The steps to build a nginx+rtmp live server on the Mac are detailed _nginx

Source: Internet
Author: User
Tags curl nginx server


Objective

How to build nginx

I believe we all know nginx is a very good open source server, use it to do HLS or rtmp streaming media server is a very good choice, so small set up the installation process online, now share to everyone and make a memo. Have the need of friends can refer to study, let's take a look together.

Nginx build 

I. Installation of Homebrow


Brow has been installed to skip this step directly.



Execute command


Ruby-e "$ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install)"


If you have already installed it and want to uninstall it:


Ruby-e "$ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"


Second, install Nginx





First Glone Nginx project to Local:



Brew Tap Homebrew/nginx


To perform the installation:



Brew Install Nginx-full--with-rtmp-module


Slow installation process, wait patiently





By manipulating the steps above Nginx and RTMP modules are installed, the following starts to configure the Nginx rtmp module





First, let's see where our nginx are installed.



Brew Info Nginx-full


After executing the above command, we can see the information











Nginx Installation Location



/usr/local/cellar/nginx-full/1.10.1/bin/nginx


Nginx Configuration file Location



/usr/local/etc/nginx/nginx.conf


Third, the Operation Nginx





Execute the command to test if the Nginx service can be started successfully



Nginx


The command line is shown in the following illustration











In the browser address bar input: http://localhost:8080 (direct click)





If you appear






Welcome to nginx!. 03





On behalf of Nginx, the installation was successful.





If the terminal prompts



Nginx: [Emerg] bind () to 0.0.0.0:8080 failed (48:address already in use)


Represents 8080





Port is occupied, view Port PID



Lsof-i tcp:8080


Kill 8080-Port-consuming PID



Kill 9603 (replace here with 8080-port PID)


And then re-execute the Nginx





Nginx Common method: Reload a configuration file



Nginx-s Reload


Reload log:



 Nginx-s Reopen


Stop Nginx



Nginx-s stop


Orderly Exit Nginx



Nginx-s quit


Iv. Configuration of rtmp





Now we're going to modify the nginx.conf configuration file and configure the RTMP





Copy nginx configuration file location



/usr/local/etc/nginx/nginx.conf


Turn on the Finder Shift + command + G to go and open the nginx.conf with the Notepad tool



HTTP {
  ...
}


After the HTTP node, add the rtmp configuration:



rtmp {

 server {
   listen 1935;


  #直播流配置
   application Rtmplive {
     live on;
   #为 the RTMP engine to set the maximum number of connections. The default is off
   max_connections 1024


    ;


   Application hls{

     live on;
     HLS on;
     Hls_path/usr/local/var/www/hls;
     hls_fragment 1s;
   }
  }


V. Installation of FFMEPG Tools



Brew Install FFmpeg


Installing this will take a while to wait. Then prepare a video file as a push stream, and then we install a video player that supports the RTMP protocol, and the Mac can use VLC






vlc.04





The following figure indicates that the FFmpeg installation is complete






FFmpeg installation is complete 0.5





Six, FFMEPG after the installation is complete can start to push the flow



Ffmpeg-re-i the absolute path of your video file (such as/users/lideshan/downloads/demo.mp4)-vcodec copy-f flv rtmp://localhost:1935/zbcs/room
//such as: Ffmpeg-re-i/users/jiangys/documents/document/demo.mp4-vcodec copy-f flv rtmp://localhost:1935/zbcs/room


Here Zbcs is the path name of the configured application in the above configuration file; The room at the back can be written casually.





Push-Flow interface:











Seven, the verification video





Then open VLC on the computer and click the Player softwareFile---->Open Networkto select Network in the Bouncing box and enter the URL:



Rtmp://localhost:1935/zbcs/room








Double click to play











Play interface











Error handling





When the 1.FFMEPG command pushes the stream, the connection is prompted to fail.[tcp @ 0x7ff162504b60] Connection to tcp://localhost:1935 failed (Connection refused), trying next address





This error is due to the need to reboot the Nginx after the nginx.conf has been configured. After the input command restarts, there is no problem.



Nginx-s Reload








2. After the installation of Nginx, in the browser address bar input: http://localhost:8080 display does not open the Web page





Solution: Because after installation Nginx server, sometimes need to wait a few minutes before it takes effect. If the Nginx service is successfully started under test, the command



Nginx


Please refer to "Step Installation" 3rd.





Summarize





OK, to this the basic installation is over, we install step by step can be installed successfully, the above is the entire content of this article, I hope to learn or work for everyone to bring some help, if you have questions you can message exchange.

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.