본문 바로가기
etc

[nginx] CentOS 7에 nginx 최신 버전과 nginx vod 모듈 구성

by 엠플 (주)엠플 2021. 7. 27.

■ 문서 개요
CentOS 7에 nginx 최신 버전과 nginx vod 모듈 구성 방법에 대해 기술

■ 참고 사항
- 80, 443등의 동영상 연결을 위해 방화벽 해제 또는 특정 포트는 열어줘야 함

1. CentOS 7을 최소 설치로 진행합니다. 


2. nginx system requirement를 맞춰주기 위해 아래의 명령어를 사용해서 설치를 진행합니다.
yum install -y epel-release git wget gcc gcc-c++ tar gd gd-devel perl-ExtUtils-Embed geoip geoip-devel pcre-devel zlib-devel openssl-devel


3. nginx를 /usr/local/src에 다운로드합니다.
cd /usr/local/src
wget http://nginx.org/download/nginx-1.9.9.tar.gz 


4. nginx-vod-module을 다운로드 합니다.
git clone https://github.com/kaltura/nginx-vod-module.git 


5. nginx-1.19.9.tar.gz 압축을 풀어줍니다.
tar xvfz nginx-1.9.9.tar.gz


6. nginx 계정생성을 진행합니다.
useradd --system --home /var/lib/nginx --shell /sbin/nologin --comment "nginx system user" nginx


7. 컴파일을 진행합니다.
cd /usr/local/src/nginx-1.9.9
./configure --add-module=../nginx-vod-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 \
--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_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 \
--with-http_mp4_module \
--with-file-aio \
--with-cc-opt="-O3" \
--prefix=/etc/nginx


make


make install


nginx -V


8. 권한을 변경합니다.


9. /etc/nginx/nginx.conf 설정을 변경합니다.
vi /etc/nginx/nginx.conf


worker_processes  1;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
 
    server {
        listen       80;
        server_name  localhost;
 
        location / {
            root   html;
            index  index.html index.htm;
        }
 
        error_page   500 502 503 504  /50x.html;
 
        location = /50x.html {
            root   html;
        }
 
        # vod settings
        vod_mode local;
        vod_fallback_upstream_location /fallback;
        vod_last_modified 'Sun, 19 Nov 2000 08:52:00 GMT';
        vod_last_modified_types *;
        vod_align_segments_to_key_frames on;
        vod_manifest_segment_durations_mode accurate;
        vod_segment_duration 1000;
        vod_hls_index_file_name_prefix playlist;
 
        # vod caches
        vod_metadata_cache metadata_cache 512m;
        vod_response_cache response_cache 128m;
 
        # gzip mainfests
        gzip on;
        gzip_types application/vnd.apple.mpegurl;
 
        # file handle caching / aio
        open_file_cache          max=1000 inactive=5m;
        open_file_cache_valid    2m;
        open_file_cache_min_uses 1;
        open_file_cache_errors   on;
        aio on;
 
        location /contents {
                root /home/hls;
                vod hls;
                add_header Access-Control-Allow-Headers '*';
                add_header Access-Control-Expose-Headers 'Server,range,Content-Length,Content-Range';
                add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
                add_header Access-Control-Allow-Origin '*';
                expires 100d;
        }
        location /vod_status {
                vod_status;
                access_log off;
        }
    }
}


10. /lib/systemd/system/nginx.service를 등록합니다.
vi /lib/systemd/system/nginx.service


[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


11. 서비스를 실행합니다.
systemctl daemon-reload


systemctl start nginx


11-1. journalctl -xe를 사용하여 오류를 확인합니다.


vi /usr/local/lib64/perl5/nginx.pm


11-2. XSLoader::load('nginx', $VERSION);를 주석 처리합니다.
#XSLoader::load('nginx', $VERSION);


systemctl start nginx


systemctl enable nginx


12. 컨텐츠 디렉토리를 생성합니다.
mkdir /home/hls/contents -p


13. nginx를 재시작합니다.
systemctl restart nginx


14. 컨텐츠를 업로드합니다.


15. 테스트 PC에서 VLC Player를 설치합니다.
    https://get.videolan.org/vlc/3.0.16/win64/vlc-3.0.16-win64.exe

16. VLC로 네트워크 스트림을 열어 내용을 확인합니다.
http://IP(xxx.xxx.xxx.xxx)/contents/영상파일명.mp4/playlist.m3u8

tail -f /var/log/nginx


17. Web에 포팅 될 HLS Player는 아래의 링크들 중에 골라서 진행할 수 있습니다.
http://www.mediaelementjs.com/

 

MediaElement.js - HTML5 video and audio unification framework

Love HTML5, but having Flashbacks? Easy partner, we can handle it. MediaElement.js is a blazingly fast and amazingly powerful HTML5 audio and video library that creates a unified feel for media files (MP4, MP3, FLV), streaming content (HLS, M(PEG)-DASH, RT

www.mediaelementjs.com

GitHub - bharadwajpro/m3u8-player: M3U8 Player in browser. Play any live stream m3u8 link with this website at https://bharadwajpro.github.io/m3u8-player

 

M3U8 Player

 

bharadwajpro.github.io

The Most Powerful & Flexible Video Platform | JW Player

 

The Most Powerful & Flexible Video Platform | JW Player

High quality, consistent playback, so that you can reach viewers everywhere. Whether across websites, mobile apps, or connected TV, our player delivers a beautiful experience and increases your ad revenue.

www.jwplayer.com

Flowplayer: The Performance First Online Video Platform

 

Flowplayer | Flowplayer: The Performance First Online Video Platform

Flowplayer is an online video platform for broadcasters, publishers, and media houses. It gives you top ranking ad fill rates and the best-of-breed live streaming.

flowplayer.com

 

댓글0