DEV Community

Samuyi
Samuyi

Posted on

How To Setup Nginx For HLS Video Streaming On Centos 7

Introduction

HLS stands for HTTP live streaming. It’s an HTTP based media streaming protocol developed by Apple. Unlike UDP based protocols like RTP it can’t be blocked by firewalls that only allow HTTP traffic. It can be delivered by HTTP servers such as Nginx and can distributed through CDNs.

The default install of Nginx doesn’t come complied with an HLS module; but there’s an open source Nginx module that supports HLS. We would need to compile Nginx from source and add the module during compilation.

This tutorial shows you how to install Nginx and use it as a video live streaming server.

Prerequisites

To follow along with this tutorial please ensure the following are present on the target machine:

  • git, wget, gcc, gcc-c++, perl, gd, gd-devel, perl-ExtUtils-Embed, geoip, geoip-devel and tar
  • A non root user with sudo capabilities

If you don’t have the build utilities you would need to install them. Run this to do so:

$ sudo yum update
$ sudo yum install epel-release
$ sudo yum install git wget gcc gcc-c++ tar gd gd-devel perl-ExtUtils-Embed geoip geoip-devel

Step 1 - Download and Compile Nginx With It’s Dependencies

We need to download the dependency libraries for Nginx; including the open sorce nginx-rtmp module used to provide Nginx with HLS capabilities. First off we download the PCRE module required by Nginx Core and Rewrite modules. Run this to do so:

 $    wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz
 $   tar -zxf pcre-8.42.tar.gz
 $   rm -rf pcre-8.42.tar.gz
 $   cd pcre-8.42
 $   ./configure
 $   make
 $   sudo make install
 $   cd

Next we download the zlib module required by the Nginx Gzip module of nginx and install it. Run this to do so:

$ wget http://zlib.net/zlib-1.2.11.tar.gz
$ tar -zxf zlib-1.2.11.tar.gz
$ rm -rf zlib-1.2.11.tar.gz
$ cd zlib-1.2.11
$ ./configure
$ make
$ sudo make install
$ cd 

Up next, we download the openssl module required by the Nginx SSL module. Run this to do so:

$ wget http://www.openssl.org/source/openssl-1.0.2q.tar.gz
$ tar -zxf openssl-1.0.2q.tar.gz
$ rm -rf openssl-1.0.2.tar.gz
$ cd openssl-1.0.2q
$ ./config
$ make
$ sudo make install
$ cd

We then download the open source nginx-rtmp module from its github repository. To do that run:

$ git clone git://github.com/arut/nginx-rtmp-module.git

Finally we download the Nginx source. We would be downloading the latest stable version, which as of this writing is 1.14.2, from nginx.org. Run this to do so:

$ wget https://nginx.org/download/nginx-1.14.2.tar.gz
$ tar zxf nginx-1.14.2.tar.gz
$ rm -rf nginx-1.14.2.tar.gz
$ cd nginx-1.14.2

Now that we have the necessary dependencies, we can compile Nginx. Now we need to configure the build options. This is done by running the “./configure” script in the directory with a host of options for Nginx to compile. The options include the paths to the open source module, zlib module, pcre module and openssl module all previously downloaded and installed. We also need to specify which in built Nginx modules we want compiled. We run this to get the desired build option:

$ ./configure  --add-module=../nginx-rtmp-module \
--sbin-path=/usr/sbin/nginx \ 
--lock-path=/var/run/nginx.lock \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/run/nginx.pid \   
--with-pcre=../pcre-8.42 \    
--with-zlib=../zlib-1.2.11 \  
--with-openssl=../openssl-1.0.2q \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--user=nginx \                 
--group=nginx \                
--with-http_auth_request_module \
--with-http_degradation_module \
--with-http_geoip_module \     
--with-http_gunzip_module \    
--with-http_gzip_static_module \
--with-http_image_filter_module \
--with-http_mp4_module \
--with-http_perl_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module  \
--with-http_stub_status_module \
--with-http_v2_module \
--with-stream_ssl_module \
--with-stream \
--with-threads \
--prefix=/etc/nginx

Finally compile and build Nginx.

$ make 
$ sudo make install

To check if it was installed properly run:

$ nginx -V #The output should be the Nginx version, compiler version, and configure script parameters.

We need to install the Nginx man pages, to do that run this:

$ sudo cp ~/nginx-1.14.2/man/nginx.8 /usr/share/man/man8
$ sudo gzip /usr/share/man/man8/nginx.8

Now we clean up the libraries previously downloaded.

$ rm -rf nginx-1.14.2 nginx-rtmp-module openssl-1.0.2q pcre-8.42 zlib-1.2.11

Step 2 – Setup and Configure Nginx

Now that the Nginx binary is installed in our search path, we need to setup an nginx user. To setup the nginx user, run:

$ sudo useradd --system --home /var/lib/nginx --shell /sbin/nologin --comment "nginx system user" nginx

We also need to create the directory where Nginx logs are stored and make user nginx the owner. For that we run:

$ sudo mkdir /var/log/nginx &&  sudo chown nginx:nginx /var/log/nginx 

With that done, it’s time to create the nginx systemd service unit file. It’s contents should be something like this:

  [Unit]
  Description=nginx - high performance web server
  Documentation=https://nginx.org/en/docs/
  After=network.target remote-fs.target nss-lookup.target
  Wants=network-online.target
        [Service]
  Type=forking
  PIDFile=/run/nginx.pid
  ExecStartPre=/usr/bin/rm -f /run/nginx.pid 
  ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
  ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
  ExecReload=/bin/kill -s HUP $MAINPID
  KillSignal=SIGQUIT
  TimeoutStopSec=5
  KillMode=process
  PrivateTmp=true
     [Install]
  WantedBy=multi-user.target

We now paste the above contents in the nginx service file:

$ sudo vim  /lib/systemd/system/nginx.service   # You can replace vim with whichever editor you prefer

Now we reload systemctl daemon and start Nginx.

$ sudo systemctl daemon-reload
$ sudo systemctl start nginx
$ sudo systemctl enable nginx

Now we need to configure Nginx to stream videos. Our nginx.conf file; located in the /etc/nginx/ directory, should look like this:

user  nginx;
worker_processes  auto;
 server_tokens off;
events {
    worker_connections  1024;
}
# We need to setup an rmtp server to stream video from client devices
rtmp {
    server {
      listen 1935;
      chunk_size 4096;
      ping 30s;
      notify_method get;
      allow play all;
       # rmtp handler our clients connect to for live streaming, it runs on port 1935. It converts the stream to HLS and stores it on our server
   application app {
          live on;
          hls on;   
          hls_path /var/www/hls/live;
          hls_nested on;  # create a new folder for each stream
          record_notify on;
          record_path /var/www/videos;
          record all;
          record_unique on;
     }

    application vod {
       play /var/www/videos;
    }
 }
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    gzip  on;
    server {
        listen       80;
        server_name  _;
        location / {
            root   html;
            index  index.html index.htm;
        }
          # the http end point our web based users connect to see the live stream
          location /live {
            types {
                application/vnd.apple.mpegurl m3u8; 
             }
                 alias /var/www/hls/live;
                add_header Cache-Control no-cache;
       }
   }

We need to also create the directory where our video stream is stored.

 $ sudo mkdir -p /var/www/hls/live

Now we can restart nginx to reload the new configuration file.

$ sudo systemctl restart nginx

Step 3- Stream and Publish Videos

Now to live stream videos from a client machine, assuming the client has the video stored locally and ffmpeg installed, we run this to publish to our server:

$ ffmpeg -i /path/to/video  -c:v h264 -c:a aac  -strict -2 -f flv rtmp://server_ip:1935/app/unique_stream_name     #the name of the stream has to be unique  

Our viewers can watch the video on vlc media player by streaming the url: http://server_ip/live/unique_stream_key/index.m3u8. It is also possible to publish video from webcam from a Linux client machine by running:

$ ffmpeg -f video4linux2 -i /dev/video0 -c:v libx264 -an -f flv rtmp://server_ip:1935/app/unique_stream_name

From a mac book, it’s this way

$ ffmpeg -f avfoundation -framerate 30 -i "0" -c:v libx264 -an -f flv rtmp://server_ip:1935/app/unique_stream_name

Conclusion

And thats how to setup HLS with Nginx. To go further we could write an application in our favorite programming language to handle user authentication and maybe store videos on a media server. The key thing is that our users can live stream videos with regular HTTP.

Top comments (14)

Collapse
 
lblanks240 profile image
lblanks240

git clone git://github.com/arut/nginx-rtmp-module.git i attempted to down load this to my server this was the error is there another way to get this plugin?

thanks
lenard

[root@server ~]# git clone git://github.com/arut/nginx-rtmp-module.git
Cloning into 'nginx-rtmp-module'...
fatal: unable to connect to github.com:
github.com[0: 192.30.253.113]: errno=Connection refused

Collapse
 
lblanks240 profile image
lblanks240

i finally downloaded the module but now i get i have put this plugin in several places i am not sure what to do

Lenard

configuring additional modules
adding module in ../nginx-rtmp-module
./configure: error: no ../nginx-rtmp-module/config was found
[root@server nginx-1.17.0]# ls
auto conf html man README
CHANGES configure LICENSE nginx-rtmp-module.git src
CHANGES.ru contrib Makefile objs

Collapse
 
samuyi profile image
Samuyi

check the path specified for the cloned module and make sure the module was cloned without any errors. The config file that caused the error is located on the project root directory on github. So i suggest you make sure the path specified is the correct path to the module.

Thread Thread
 
lblanks240 profile image
lblanks240

what will be the best way to get this file without errors?

Thread Thread
 
lblanks240 profile image
lblanks240

i had to use wget to get the file

Thread Thread
 
lblanks240 profile image
lblanks240

i was wondering if you could please let me know if i got the conf file correct

thanks
lenard

* @version 1.8.10

* @package Engintron for cPanel/WHM

* @author Fotis Evangelou

* @url engintron.com

* @copyright Copyright (c) 2010 - 2018 Nuevvo Webware P.C. All rights reserved.

* @license GNU/GPL license: gnu.org/copyleft/gpl.html

*/

user nginx;
pid /var/run/nginx.pid;

worker_processes auto;
worker_rlimit_nofile 65535;
server_tokens off;

events {
multi_accept on;
use epoll;
worker_connections 65535;
}

We need to setup an rmtp server to stream video from client devices

rtmp {
server {
listen 1935;
chunk_size 4096;
ping 30s;
notify_method get;
allow play all;
# rmtp handler our clients connect to for live streaming, it runs on port 1935. It converts the stream to HLS and stores it on our server
application app {
live on;
hls on;

hls_path /var/www/hls/live;
hls_nested on; # create a new folder for each stream
record_notify on;
record_path /var/www/videos;
record all;
record_unique on;
}

application vod {
   play /var/www/videos;
}

}
}

http {
## Basic Settings ##
client_body_buffer_size 128k;
client_body_timeout 30s; # Use 5s for high-traffic sites
client_header_timeout 30s; # Use 5s for high-traffic sites
client_max_body_size 1024m;
keepalive_timeout 20s;
port_in_redirect off;
sendfile on;
server_names_hash_bucket_size 512;
server_name_in_redirect off;
server_tokens off;
tcp_nodelay on;
tcp_nopush on;
types_hash_max_size 2048;
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name _;
location / {
root html;
index index.html index.htm;
}
# the http end point our web based users connect to see the live stream
location /live {
types {
application/vnd.apple.mpegurl m3u8;
}
alias /var/www/hls/live;
add_header Cache-Control no-cache;
}
}include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name _;
location / {
root html;
index index.html index.htm;
}
# the http end point our web based users connect to see the live stream
location /live {
types {
application/vnd.apple.mpegurl m3u8;
}
alias /var/www/hls/live;
add_header Cache-Control no-cache;
}
}

Thread Thread
 
lblanks240 profile image
lblanks240 • Edited

i really need some help i crashed my server i messed something in the conf file up. here is a copy of the logs.

thanks
lenard

[root@server ~]# ffmpeg -i input.mp4 output.avi
ffmpeg version N-90389-g72bb955625 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-16)
configuration: --prefix=/usr/local/ffmpegtoolkit --pkg-config-flags=--static --extra-libs=-lpthread --enable-gpl --enable-shared --enable-nonfree --enable-pthreads --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libmp3lame --enable-libvpx --enable-libfdk-aac --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libx265 --enable-libxvid --enable-postproc --enable-swscale --enable-avfilter --enable-libass --enable-runtime-cpudetect --extra-cflags=-I/usr/local/ffmpegtoolkit/include/ --extra-ldflags=-L/usr/local/ffmpegtoolkit/lib --enable-version3
libavutil 56. 11.100 / 56. 11.100
libavcodec 58. 14.100 / 58. 14.100
libavformat 58. 10.100 / 58. 10.100
libavdevice 58. 2.100 / 58. 2.100
libavfilter 7. 13.100 / 7. 13.100
libswscale 5. 0.102 / 5. 0.102
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
input.mp4: No such file or directory
[root@server ~]# sudo systemctl stop nginx
[root@server ~]# sudo systemctl restart nginx
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
[root@server ~]# journalctl -xe
Jun 15 08:03:40 server.1xxxhost.net sshd[39155]: Disconnected from 82.196.15.195 port 60082 [preauth]
Jun 15 08:03:53 server.1xxxhost.net kernel: Firewall: TCP_IN Blocked IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e
Jun 15 08:03:56 server.1xxxhost.net kernel: Firewall: CC_DENY IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e8:c0:08
Jun 15 08:03:59 server.1xxxhost.net kernel: Firewall: TCP_IN Blocked IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e
Jun 15 08:04:01 server.1xxxhost.net systemd[1]: Started Session 8399 of user root.
-- Subject: Unit session-8399.scope has finished start-up
-- Defined-By: systemd

-- Support: lists.freedesktop.org/mailman/list...

-- Unit session-8399.scope has finished starting up.

-- The start-up result is done.
Jun 15 08:04:01 server.1xxxhost.net systemd[1]: Started Session 8400 of user root.
-- Subject: Unit session-8400.scope has finished start-up
-- Defined-By: systemd

-- Support: lists.freedesktop.org/mailman/list...

-- Unit session-8400.scope has finished starting up.

-- The start-up result is done.
Jun 15 08:04:01 server.1xxxhost.net CROND[39169]: (root) CMD (/usr/local/cpanel/whostmgr/bin/dnsqueue > /dev/null 2>&1)
Jun 15 08:04:01 server.1xxxhost.net CROND[39170]: (root) CMD (/etc/nginx/utilities/https_vhosts.sh >> /dev/null 2>&1)
Jun 15 08:04:04 server.1xxxhost.net kernel: Firewall: TCP_IN Blocked IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e
Jun 15 08:04:05 server.1xxxhost.net kernel: Firewall: TCP_IN Blocked IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e
Jun 15 08:04:07 server.1xxxhost.net kernel: Firewall: TCP_IN Blocked IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e
Jun 15 08:04:32 server.1xxxhost.net kernel: Firewall: TCP_IN Blocked IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e
Jun 15 08:04:35 server.1xxxhost.net sudo[39200]: root : TTY=pts/0 ; PWD=/root ; USER=root ; COMMAND=/bin/systemctl
Jun 15 08:04:35 server.1xxxhost.net sudo[39200]: pam_unix(sudo:session): session opened for user root by root(uid=0)
Jun 15 08:04:35 server.1xxxhost.net kernel: Firewall: CC_DENY IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e8:c0:08
Jun 15 08:04:35 server.1xxxhost.net polkitd[2391]: Registered Authentication Agent for unix-process:39201:23422165 (sys
Jun 15 08:04:35 server.1xxxhost.net systemd[1]: Starting nginx - high performance web server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd

-- Support: lists.freedesktop.org/mailman/list...

-- Unit nginx.service has begun starting up.
Jun 15 08:04:35 server.1xxxhost.net nginx[39207]: nginx: [emerg] unknown directive "includon" in /etc/nginx/nginx.conf:
Jun 15 08:04:35 server.1xxxhost.net systemd[1]: nginx.service: control process exited, code=exited status=1
Jun 15 08:04:35 server.1xxxhost.net systemd[1]: Failed to start nginx - high performance web server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd

-- Support: lists.freedesktop.org/mailman/list...

-- Unit nginx.service has failed.

-- The result is failed.
Jun 15 08:04:35 server.1xxxhost.net systemd[1]: Unit nginx.service entered failed state.
Jun 15 08:04:35 server.1xxxhost.net systemd[1]: nginx.service failed.
Jun 15 08:04:35 server.1xxxhost.net polkitd[2391]: Unregistered Authentication Agent for unix-process:39201:23422165 (s
Jun 15 08:04:35 server.1xxxhost.net sudo[39200]: pam_unix(sudo:session): session closed for user root
Jun 15 08:04:37 server.1xxxhost.net kernel: Firewall: UDP_OUT Blocked IN= OUT=eth0 SRC=205.251.153.170 DST=104.155.14
Jun 15 08:04:39 server.1xxxhost.net kernel: Firewall: TCP_IN Blocked IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e
Jun 15 08:04:45 server.1xxxhost.net kernel: Firewall: CC_DENY IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e8:c0:08
Jun 15 08:04:49 server.1xxxhost.net kernel: Firewall: UDP_IN Blocked IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e
Jun 15 08:04:53 server.1xxxhost.net kernel: Firewall: CC_DENY IN=eth0 OUT= MAC=00:16:3e:5d:bc:26:88:75:56:3c:e8:c0:08
lines 1619-1673/1673 (END)

without the firewall

[root@server ~]# journalctl -xe
Jun 15 14:40:06 server.1xxxhost.net sshd[7052]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.9
Jun 15 14:40:08 server.1xxxhost.net sshd[7052]: Failed password for invalid user admin from 192.99.245.135 port 44964 ssh2
Jun 15 14:40:08 server.1xxxhost.net sshd[7052]: Received disconnect from 192.99.245.135 port 44964:11: Bye Bye [preauth]
Jun 15 14:40:08 server.1xxxhost.net sshd[7052]: Disconnected from 192.99.245.135 port 44964 [preauth]
Jun 15 14:40:19 server.1xxxhost.net sshd[7057]: Invalid user levendov from 164.132.192.5 port 60912
Jun 15 14:40:19 server.1xxxhost.net sshd[7057]: input_userauth_request: invalid user levendov [preauth]
Jun 15 14:40:19 server.1xxxhost.net sshd[7057]: pam_unix(sshd:auth): check pass; user unknown
Jun 15 14:40:19 server.1xxxhost.net sshd[7057]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=164.1
Jun 15 14:40:22 server.1xxxhost.net sshd[7057]: Failed password for invalid user levendov from 164.132.192.5 port 60912 ssh2
Jun 15 14:40:22 server.1xxxhost.net sshd[7057]: Received disconnect from 164.132.192.5 port 60912:11: Bye Bye [preauth]
Jun 15 14:40:22 server.1xxxhost.net sshd[7057]: Disconnected from 164.132.192.5 port 60912 [preauth]
Jun 15 14:41:01 server.1xxxhost.net systemd[1]: Started Session 8602 of user root.
-- Subject: Unit session-8602.scope has finished start-up
-- Defined-By: systemd

-- Support: lists.freedesktop.org/mailman/list...

-- Unit session-8602.scope has finished starting up.

-- The start-up result is done.
Jun 15 14:41:01 server.1xxxhost.net CROND[7075]: (root) CMD (/etc/nginx/utilities/https_vhosts.sh >> /dev/null 2>&1)
Jun 15 14:41:09 server.1xxxhost.net sshd[7081]: Invalid user cbethenc from 82.196.15.195 port 52178
Jun 15 14:41:09 server.1xxxhost.net sshd[7081]: input_userauth_request: invalid user cbethenc [preauth]
Jun 15 14:41:09 server.1xxxhost.net sshd[7081]: pam_unix(sshd:auth): check pass; user unknown
Jun 15 14:41:09 server.1xxxhost.net sshd[7081]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=82.19
Jun 15 14:41:12 server.1xxxhost.net sshd[7081]: Failed password for invalid user cbethenc from 82.196.15.195 port 52178 ssh2
Jun 15 14:41:12 server.1xxxhost.net sshd[7081]: Received disconnect from 82.196.15.195 port 52178:11: Bye Bye [preauth]
Jun 15 14:41:12 server.1xxxhost.net sshd[7081]: Disconnected from 82.196.15.195 port 52178 [preauth]
Jun 15 14:41:19 server.1xxxhost.net sshd[7086]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=190.6
Jun 15 14:41:19 server.1xxxhost.net sshd[7086]: pam_succeed_if(sshd:auth): requirement "uid >= 1000" not met by user "root"
Jun 15 14:41:21 server.1xxxhost.net sshd[7086]: Failed password for root from 190.67.116.12 port 56396 ssh2
Jun 15 14:41:21 server.1xxxhost.net sshd[7086]: Received disconnect from 190.67.116.12 port 56396:11: Bye Bye [preauth]
Jun 15 14:41:21 server.1xxxhost.net sshd[7086]: Disconnected from 190.67.116.12 port 56396 [preauth]
Jun 15 14:41:23 server.1xxxhost.net sudo[7088]: root : TTY=pts/0 ; PWD=/root ; USER=root ; COMMAND=/bin/systemctl restart nginx
Jun 15 14:41:23 server.1xxxhost.net sudo[7088]: pam_unix(sudo:session): session opened for user root by root(uid=0)
Jun 15 14:41:23 server.1xxxhost.net polkitd[2391]: Registered Authentication Agent for unix-process:7089:23977290 (system bus name :1.17262 [
Jun 15 14:41:23 server.1xxxhost.net systemd[1]: Starting nginx - high performance web server...
-- Subject: Unit nginx.service has begun start-up
-- Defined-By: systemd

-- Support: lists.freedesktop.org/mailman/list...

-- Unit nginx.service has begun starting up.
Jun 15 14:41:23 server.1xxxhost.net nginx[7095]: nginx: [emerg] unknown directive "includon" in /etc/nginx/nginx.conf:123
Jun 15 14:41:23 server.1xxxhost.net systemd[1]: nginx.service: control process exited, code=exited status=1
Jun 15 14:41:23 server.1xxxhost.net systemd[1]: Failed to start nginx - high performance web server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd

-- Support: lists.freedesktop.org/mailman/list...

-- Unit nginx.service has failed.

-- The result is failed.
Jun 15 14:41:23 server.1xxxhost.net systemd[1]: Unit nginx.service entered failed state.
Jun 15 14:41:23 server.1xxxhost.net systemd[1]: nginx.service failed.
Jun 15 14:41:23 server.1xxxhost.net polkitd[2391]: Unregistered Authentication Agent for unix-process:7089:23977290 (system bus name :1.17262
Jun 15 14:41:23 server.1xxxhost.net sudo[7088]: pam_unix(sudo:session): session closed for user root
lines 1591-1645/1645 (END)

Collapse
 
arihantdaga profile image
arihant daga • Edited

This is very nice. Thank you for this article. I have a doubt. I wanted to make a webiste similar to netflix(On a smaller level, i understand), where i have few video files(Movies) and i want to stream those to the web browser.

I understood that i can convert all my files using ffmpeg. using this command

ffmpeg -i /path/to/video  -c:v h264 -c:a aac  -strict -2 -f flv rtmp://server_ip:1935/app/unique_stream_name     #the name of the stream has to be unique  

But Shall i do this will all my files only once and generate chunks. Or shall i issue this command every time a new user request a video. I have seen that these files under the directory /var/www/hls/live are lost on restarting nginx.

Collapse
 
samuyi profile image
Samuyi

As far as i know it has to be done for every request.

Collapse
 
littlerichard3755 profile image
littlerichard3755

Great article, I've been able to setup my server for streaming and able to livestream to the server and push to other platforms. I can also use VLC to view the live stream by xxx.xxx.xxx.xxx/live/123456/index...., however I am not able to view the livestream with an embedded player on a website. Is it due to crossdomain or do I need an SSL certificate, or am I leaving something out. your assistance would be greatly appreciated.

Collapse
 
terrancio profile image
terrancio

"ffmpeg -i /path/to/video -c:v h264 -c:a aac -strict -2 -f flv rtmp://server_ip:1935/app/unique_stream_name #the name of the stream has to be unique "

When it says /Path/To/Video what exactly should I put there? because I chose a directory thinking it's where I was gonna save video files, but after I pressed Enter it appeared in Red "It is a directory" so... may you help me, please?

Collapse
 
manas86 profile image
manas86 • Edited

Cool article. I'm just stuck on point 3. can you please explain a bit in details like server-ip from which server. Just missing a little piece of information on streaming part like you did for nginx

Collapse
 
samuyi profile image
Samuyi

The ip or hostname of the remote machine Nginx is running on

Collapse
 
scx1899 profile image
gti.scx1899@gmail.com • Edited

hi
please upload shell script fullconfig.sh this page install&config all level and set this page
Centos & ubanta

thanks

Some comments may only be visible to logged-in visitors. Sign in to view all comments.