執行
$ ./install.sh
詳細步驟,請參考「install.sh」。
此範例將「nginx」安裝到「/usr/local/share/nginx/」這個路徑。
執行下面指令,觀看「/usr/local/share/nginx/」的資料夾結構。
$ tree /usr/local/share/nginx
顯示
/usr/local/share/nginx/
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── html
│   ├── 50x.html
│   └── index.html
├── logs
└── sbin
    └── nginx
4 directories, 18 files
請參考「/usr/local/share/nginx/conf/nginx.conf」的設定,設定如下
rtmp {
	server {
		listen  2020;
		application live {
			live on;
			allow publish all;
			allow play all;
		}
	}
}
相關的「Directives」
可以參考
執行
$ /usr/local/share/nginx/sbin/nginx -h
顯示
nginx version: nginx/1.9.9
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: /usr/local/share/nginx/)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file
執行
$ sudo /usr/local/share/nginx/sbin/nginx
上面指令寫在「server-start.sh」。
執行
$ sudo /usr/local/share/nginx/sbin/nginx -s reload
上面指令寫在「server-reload.sh」。
若原本已經啟動「nginx」,
修改完「/usr/local/share/nginx/conf/nginx.conf」,則是可以執行這個指令。
執行
$ sudo /usr/local/share/nginx/sbin/nginx -s stop
上面指令寫在「server-stop.sh」。
一般的狀況下,採用上面的方式來「stop」。
若遇到特殊的狀況,上面的方式無法運作的時候
可以執行下面指令
$ ps aux | grep nginx
顯示
root     27138  0.0  0.0  36900  4980 ?        Ss   09:33   0:00 nginx: master process /usr/local/share/nginx/sbin/nginx
nobody   27139  0.0  0.1  37568  8312 ?        S    09:33   0:00 nginx: worker process
nobody   27140  0.0  0.1  37096  7536 ?        S    09:33   0:00 nginx: cache manager process
透過「kill」這個指令來「stop」。
sudo kill -9 27138
sudo kill -9 27139
sudo kill -9 27140
或是也可以透過「killall」這個指令來「stop」。
$ sudo killall -9 nginx
以下假設有一個範例檔案,路徑是「~/Videos/test.mp4」。
當啟動「nginx」後,
先開啟一個「Terinaml」,執行下面指令
$ ffmpeg -re -i ~/Videos/test.mp4 -c copy -f flv rtmp://localhost:2020/live/film
上面指令,寫在「push.sh」。
然後在開啟另一個「Terminal」,執行下面指令觀看
$ ffplay rtmp://localhost:2020/live/film
也可以執行下面指令觀看
$ vlc rtmp://localhost:2020/live/film
也可以執行下面指令觀看
$ mpv rtmp://localhost:2020/live/film
上面指令寫在「view.sh」。