I was thrilled when F5 announced the purchase of NGINX a year ago, because as a longtime F5er, I knew NGINX was a perfect fit. That feeling was confirmed when, in one of our first joint meetings, NGINX employees discussed something deeply important to me: their commitment to the “community”. Since joining the NGINX team as a product manager, I’ve had the pleasure of seeing that commitment in action and gotten to work more deeply with the community.
The NGINX Community Is Coming Together During the COVID-19 Pandemic
Those of us working with open source typically use “community” to describe people who support an open source project by submitting code. While important, they are only a small part of the NGINX community. Who, then, are the other members of the community? We also value those of you who:
- Use NGINX in the projects you share on GitHub
- Rely on NGINX to securely deliver sites, apps, and APIs to your users
- Write blog posts on installing and using NGINX
- Help NGINX users on public forums
In recent months, members of the NGINX community have truly come together to support each other and the many organizations struggling to maintain operations during the COVID‑19 pandemic. Many of you have flagged sites that might benefit from NGINX software, or even donated time and expertise on how to tune NGINX for optimal performance. In an effort to do our part, we’ve published Free Resources for Websites Impacted by COVID‑19, and have been excited to see the community rally around new NGINX users.
As part of our efforts to help organizations cope with increased traffic and add new functionality, we’ve been providing up to five free instances of NGINX Plus to organizations on the frontline of the pandemic. That has included medical providers, government offices, and – most relevant to this blog – schools, universities, and education‑focused non‑profits. We detected a trending use case among these organizations that probably won’t surprise you: streaming video!
With schools around the world shutting their doors and rapidly implementing distance learning, we expect the use of streaming video to increase exponentially over the coming weeks and months. In the rest of this blog I explain how you can use NGINX Open Source and NGINX Plus to enable stable, secure, and scalable video streaming.
A big thanks goes out to NGINX Technical Solutions Architect James Jones for recording demo videos to accompany this blog!
Streaming Live Video and Storing Videos with NGINX Open Source
Our solution for streaming video takes advantage of the Real‑Time Messaging Protocol (RTMP) module for NGINX. In this video, James goes through the process step by step:
So that you don’t have to take notes while watching the James’s demo, we’ve captured all of the commands and configuration in the following sections.
- Installing the Build Tools
- Installing Dependencies
- Compiling NGINX with the RTMP Module
- Configuring NGINX
- Validating the Configuration and Starting NGINX
- Testing the Playback Methods
An Important Note: Don’t Forget Security!
The NGINX configurations presented in this blog do not include security measures to restrict who can watch your video stream. There are a variety of ways to secure your streams with the front‑end application your viewers use to watch the video, such as allowing access only from certain IP addresses or requiring viewers to authenticate.
Installing the Build Tools
Before compiling NGINX, you need to have some basic build tools installed: autoconf, gcc, git, and make. To download and install them, run the command for your operating system (if it’s not included here, consult the OS vendor documentation).
- For Debian and Ubuntu:
- For CentOS, Oracle Linux, and RHEL:
Installing Dependencies
The NGINX build also requires several dependencies: Perl Compatible Regular Expressions (PCRE), OpenSSL, and zlib for compression.
Installing Dependencies with a Package Manager
The easier way to download and install the dependencies is with a package manager. Run the command for your operating system (if it’s not included here, consult the OS vendor documentation).
- For Debian and Ubuntu:
- For CentOS, Oracle Linux, and RHEL:
Installing Dependencies from Source
If you instead want to build and install the dependencies from source, see our instructions.
Compiling NGINX with the RTMP Module
To complete the build, you clone the GitHub repositories for RTMP and NGINX, run the NGINX configure command, and then compile NGINX.
Configuring NGINX
You can configure NGINX to stream video using one or both of the HTTP Live Streaming (HLS) and Dynamic Adaptive Streaming over HTTP (DASH) protocols. The protocols provide the same functionality, so choosing between them is really a matter of preference. If you’re not familiar with them, see HLS vs DASH on the Vidbeo blog.
HLS Configuration
For HLS, the configuration is as follows. In the demo (at time point 5:10), James explains the purpose of these directives.
DASH Configuration
For DASH, the configuration is as follows. In the demo, James combines HLS and DASH in a single configuration, as many directives are the same for both protocols.
Validating the Configuration and Starting NGINX
It’s always a good idea to validate your NGINX configuration to make sure there are no syntactic errors. Run this command:
Then run this command to start NGINX:
Testing the Playback Methods
Start your video stream. OBS Studio is a commonly used open source tool that allows you to livestream from your workstation to your NGINX server by configuring a custom RTMP server. Configure OBS to stream to rtmp://NGINX_server/tv/tv2, where NGINX_server is the IP address or hostname of your NGINX server. No stream key is required.
James doesn’t use OBS in the demo because he is streaming video from a file rather than live. He starts the video stream (at 9:30) by running the stream.sh script, which has these contents:
The video he is streaming (specified with the -I argument) is the open source Big Buck Bunny video from blender.org. For details about the other arguments, see the ffmpeg documentation.
Once video is streaming, you can test that NGINX is correctly serving it using the protocols you have configured. James opens three instances of the VLC media player and accesses the appropriate URL for each playback method. In the URLs, NGINX_server is the IP address or hostname of his NGINX server:
- RTMP – rtmp://NGINX_server/live/bbb
- HLS – http://NGINX_server/live/bbb.m3u8
- DASH – http://NGINX_server/live/bbb.mpd
Improving the User Experience with NGINX Plus
If you’re building a video library or course, you may need capabilities beyond what is possible with NGINX Open Source. NGINX Plus includes extended features to improve performance and the end-user experience with prebuilt modules. You can:
- Support higher scale by caching videos
- Provide video-on-demand (VOD) services
- Manage your streaming costs and capacity by limiting bandwidth
During the COVID‑19 pandemic, NGINX is providing a free one‑year license for up to five instances of NGINX Plus to organizations in the education, public government, and non‑profit sectors (subject to review and approval). For details, see Free Resources for Websites Impacted by COVID‑19.
To incorporate the RTMP module into NGINX Plus, you load it dynamically. See the NGINX Plus Admin Guide.
In this second demo, James shows how easy it is to set up NGINX Plus as a load balancer for three video servers, using Ansible and Terraform:
To access the files James uses in the second demo, see his GitHub repo.
We’re in This Together
If you’re having trouble implementing video streaming, or any other use case, we’re here to help! NGINX employees and the community are monitoring the NGINX channel on Stack Overflow1 and responding to questions and requests as quickly as possible.
If you work for an organization on the frontlines of the pandemic and have advanced needs, you may qualify for the NGINX Plus licenses mentioned above as well as a higher tier of F5 DNS Load Balancer Cloud Service. See Free Resources for Websites Impacted by COVID‑19 for details.
Also check out that blog for a rundown of easy ways to improve website performance with free resources from NGINX and F5.
1Stack Overflow is a third‑party website and is not affiliated with F5. Inc. F5 and its affiliates disclaim any liability for content (including general information and proposed solutions to questions) posted on Stack Overflow or any other third‑party website.
About the Author
Related Blog Posts
Secure Your API Gateway with NGINX App Protect WAF
As monoliths move to microservices, applications are developed faster than ever. Speed is necessary to stay competitive and APIs sit at the front of these rapid modernization efforts. But the popularity of APIs for application modernization has significant implications for app security.
How Do I Choose? API Gateway vs. Ingress Controller vs. Service Mesh
When you need an API gateway in Kubernetes, how do you choose among API gateway vs. Ingress controller vs. service mesh? We guide you through the decision, with sample scenarios for north-south and east-west API traffic, plus use cases where an API gateway is the right tool.
Deploying NGINX as an API Gateway, Part 2: Protecting Backend Services
In the second post in our API gateway series, Liam shows you how to batten down the hatches on your API services. You can use rate limiting, access restrictions, request size limits, and request body validation to frustrate illegitimate or overly burdensome requests.
New Joomla Exploit CVE-2015-8562
Read about the new zero day exploit in Joomla and see the NGINX configuration for how to apply a fix in NGINX or NGINX Plus.
Why Do I See “Welcome to nginx!” on My Favorite Website?
The ‘Welcome to NGINX!’ page is presented when NGINX web server software is installed on a computer but has not finished configuring