Server | Nginx |
Operating System | CentOS |
Step 1: install dependencies
$ yum -y groupinstall 'Development Tools'
Check dependencies, if not installed, install
pcre pcre-devel openssl openssl-devel zlib zlib-devel
wget git unzip perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel libxml2 libxml2-devel gd gd-devel pcre-devel GeoIP GeoIP-devel
Step 2: download nginx and rtmp module and compile
Download
$ cd ~/downloads
$ wget http://nginx.org/download/nginx-1.19.9.tar.gz // check latest version
$ wget https://github.com/arut/nginx-rtmp-module/archive/v1.2.1.zip // check latest version
Extract zip
$ tar -xvf nginx-1.19.9.tar.gz
$ unzip v1.2.1.zip
Configure
./configure --prefix=/usr/share/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib64/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--http-client-body-temp-path=/var/lib/nginx/tmp/client_body \
--http-proxy-temp-path=/var/lib/nginx/tmp/proxy \
--http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi \
--http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi \
--http-scgi-temp-path=/var/lib/nginx/tmp/scgi \
--pid-path=/run/nginx.pid \
--lock-path=/run/lock/subsys/nginx \
--user=nginx \
--group=nginx \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-stream_ssl_preread_module \
--with-http_addition_module \
--with-http_xslt_module=dynamic \
--with-http_image_filter_module=dynamic \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_degradation_module \
--with-http_slice_module \
--with-http_stub_status_module \
--with-http_perl_module=dynamic \
--with-http_auth_request_module \
--with-mail=dynamic \
--with-mail_ssl_module \
--with-pcre \
--with-pcre-jit \
--with-stream=dynamic \
--with-stream_ssl_module \
--with-google_perftools_module \
--add-module=../nginx-rtmp-module-1.2.1 \
--with-debug
$ make
$ make install
$ nginx -V // check if install successfuly
Step 3 – Create a Systemd Service File for Nginx
$ vi /lib/systemd/system/nginx.service
Add the following content to this file
[Unit]
Description=nginx - high performance web server
Documentation=https://nginx.org/en/docs/
After=network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/var/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
ExecStop=/bin/kill -s TERM $MAINPID
[Install]
WantedBy=multi-user.target
Then, reload the daemon command
$ systemctl daemon-reload
// enable nginx
systemctl start nginx
systemctl enable nginx
Check installation
$ ip a // get your server ip address
Step 4: config RTMP
$ chown -R nginx:nginx /root/documents/web-rtmp
Step 5: install FFMPEG
Step 6: play
type | description | tools |
---|---|---|
Video On Demand Stream | ||
Live Stream | OBS | |
Enable firewall to allow HTTP and HTTPS (80 and 443 ports)
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --reload