Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Version

Description

Date

1.0.1

Initial document

25 Dec 2024

I. Server requirement

1. Web server

xStreamer supports almost OS: Windows, MacOS, Linux. However we recommend to use Linux, document is applied for linux system only.

...

  • 4GB of RAM - recommend 8GB

  • 40GB of HDD

  • 2 CPU core

  • 3 domains / sub domains

    • api.[your-domain] and point to server IP address

    • admin.[your-domain] and point to server IP address

    • [your-domain] and point to server IP address

II. Software requirements

xStreamer architecture needs these softwares

...

Ensure all softwares above are running before setup source code

Testing

From command line / terminal please run these commands to check

1. NodeJS

Code Block
$ node -v
v16.8.2

2. MongoDB

Code Block
$ mongo --version
MongoDB shell version v4.2.7
git version: 1b82c812a9c0bbf6dc79d5400de9ea99e6ffa025
allocator: system
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

3. Redis server

Code Block
$ redis-server --version
Redis server v=5.0.4 sha=00000000:0 malloc=libc bits=64 build=d4ba11298acbb366

4. FFMPEG

Code Block
$ ffmpeg -version
fmpeg version 2.8.15-0ubuntu0.16.04.1 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.10) 20160609
configuration: --prefix=/usr --extra-version=0ubuntu0.16.04.1 --build-suffix=-ffmpeg --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --cc=cc --cxx=g++ --enable-gpl --enable-shared --disable-stripping --disable-decoder=libopenjpeg --disable-decoder=libschroedinger --enable-avresample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libpulse --enable-librtmp --enable-libschroedinger --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxvid --enable-libzvbi --enable-openal --enable-opengl --enable-x11grab --enable-libdc1394 --enable-libiec61883 --enable-libzmq --enable-frei0r --enable-libx264 --enable-libopencv
libavutil      54. 31.100 / 54. 31.100
libavcodec     56. 60.100 / 56. 60.100
libavformat    56. 40.101 / 56. 40.101
libavdevice    56.  4.100 / 56.  4.100
libavfilter     5. 40.101 /  5. 40.101
libavresample   2.  1.  0 /  2.  1.  0
libswscale      3.  1.101 /  3.  1.101
libswresample   1.  2.101 /  1.  2.101
libpostproc    53.  3.100 / 53.  3.100

5. NGINX

Code Block
$ nginx -v
nginx version: nginx/1.10.3

6. Pm2

Code Block
$ pm2 -v
[PM2] Spawning PM2 daemon with pm2_home=/Users/xxx/.pm2
[PM2] PM2 Successfully daemonized
4.4.0

7. Yarn

Code Block
$ yarn -v
1.16.0

III. Setup and test project locally

We provide source code with 4 folders, check below and use in the app accordingly

  • front-office web frontend

  • back-office admin control panel for the application

  • api api of the application

  • config-sample

    • env product environment example config

      • api.env sample configuration for api

      • front-office.env sample configuration for front web

      • back-office.env sample configuration for admin web

    • nginx

      • admin.example.com.conf sample nginx configuration for admin web

      • api.example.com.conf sample nginx configuration for api

      • example.com.conf sample nginx configuration for web frontend

1. API

  • Ensure node v16.x, MongoDB, Redis server, FFMPEG and yarn are running

  • CD to your API folder

  • Run yarn insall --production=false to install nodeJS dependencies and dev dependencies

...

  • Open browsers and run http://localhost:8080 it should show success message or Hello World!

2. Frontend web (front office)

  • Ensure nodejs and yarn are running

  • From frontend root directory run yarn insall --production=false to install nodeJS dependencies and dev dependencies

...

  • Then you can open browser http://localhost:8081 to see the web

3. Admin web

  • Similar Frontend web, same steps.

  • Create .env file from config-sample > env > back-office.env. Content looks like below. Change it with your configuration accordingly

...

  • Then you can open browser http://localhost:8082 to see the web

IV. Setup and setup production environment with nginx

1. API

  • Make sure you have installed nodeJS dependencies by yarn install --production=false command. Configure it like local setup, pm2 was installed

  • In API root directory, run yarn build

...

Code Block
pm2 start yarn --name api.example.com -- start

2. Frontend web

  • cd user web folder

  • Make sure you have installed nodeJS dependencies by yarn install --production=false command. Configure it like local setup, pm2 was installed

  • Run yarn build

...

Code Block
pm2 start yarn --name example.com -- start

3. Admin web

  • cd user admin folder

    Make sure you have installed nodeJS dependencies by yarn install --production=false command. Configure it like local setup, pm2 was installed

  • Run yarn build

...

Code Block
pm2 start yarn --name admin.example.com -- start

4. Setup nginx

a. Api

  • Let say our frontend code is in /var/www/api.example.com folder and api is running under port 8080, add new file in /etc/nginx/sites-enabled/api.example.com and content as bellow

  • You have to change with our server name and source code path

Code Block
server {
  listen 80;
	root /var/www/api.example.com/public;

	index index.html index.htm;
  server_name api.example.com;
  gzip on;
  gzip_proxied any;
  gzip_comp_level 4;
  gzip_types text/css application/javascript image/svg+xml;

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  sendfile_max_chunk 512;
  client_max_body_size 2000M;

  access_log off;
  error_log off;

	location / {
    proxy_set_header   X-Forwarded-For $remote_addr;
    proxy_set_header   Host $http_host;
    proxy_pass         http://localhost:8080;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_cache_bypass $http_upgrade;
	}

  location /.well-known {
    alias /var/www/api.example.com/public/.well-known;
  }

  # check if url is a protected folder such as privated videos
  # then check auth
	location ~/protected/ {
	  auth_request /authcheck;
	  root /var/www/api.example.com/public/;
	}

	location = /authcheck {
	  internal;
    set $query '';
    if ($request_uri ~* "[^\?]+\?(.*)$") {
      set $query $1;
    }
    proxy_pass http://localhost:8080/files/auth/check?$query;
    proxy_pass_request_body   off;
    proxy_set_header Content-Length "";
	}
}

b. Frontend

  • Let say our frontend code is in /var/www/example.com folder and Frontend app is running under port 8081, add new file in /etc/nginx/sites-enabled/example.com and content as bellow

  • You have to change with our server name and source code path

Code Block
server {
  listen 80;
	server_name example.com;

	root /var/www/example.com/public;

  gzip on;
  gzip_proxied any;
  gzip_comp_level 4;
  gzip_types text/css application/javascript image/svg+xml;

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  sendfile_max_chunk 512;

  # tuning performance for log request
  access_log off;
  error_log off;

	location / {
    proxy_pass http://localhost:8081/;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;
    proxy_redirect        off;
    proxy_set_header      Host $host;
    proxy_set_header      X-Real-IP $remote_addr;
    proxy_set_header      X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header      Proxy "";
  }

  location /.well-known {
    alias /var/www/example.com/public/.well-known;
  }

  location /_next/static/ {
    alias /var/www/example.com/dist/.next/static/$1;
    access_log off;
    expires max;
  }
}

c. Admin

  • Let say our frontend code is in /var/www/admin.example.com folder and Frontend app is running under port 8082, add new file in /etc/nginx/sites-enabled/admin.example.com and content as bellow

  • You have to change with our server name and source code path

Code Block
server {
  listen 80;
	server_name admin.example.com;
	root /var/www/admin.example.com/public;

  gzip on;
  gzip_proxied any;
  gzip_comp_level 4;
  gzip_types text/css application/javascript image/svg+xml;

  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;
  sendfile_max_chunk 512;

  access_log off;
  error_log off;

	location / {
    proxy_set_header   X-Forwarded-For $remote_addr;
    proxy_set_header   Host $http_host;
    proxy_pass         http://localhost:8082;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_cache_bypass $http_upgrade;
  }

  location /.well-known {
    alias /var/www/admin.example.com/public/.well-known;
  }

  location /_next/static/ {
    alias /var/www/admin.example.com/dist/.next/static/$1;
    access_log off;
    expires max;
  }
}

d. Testing

5. Check applications are running under pm2

  • Run pm2 ls to see your applications

  • Run pm2 stop [id] to stop app or pm2 reload [id] to reload

  • Run applications in start up by pm2 startup then pm2 save

6. Set up nginx with https

7. Migration

  • From API root directory run yarn migrate to seed default values for settings and users

    • Default admin: admin@[yourdomain] with domain is in .env file

    • Default password: adminadmin

    • If admin password is wrong, you can run node script reset-admin-pw to reset it to adminadmin

  • You can change default values in src > migrations folder