執行
$ ./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
├── hls
├── html
│   ├── 50x.html
│   ├── index.html
│   └── live.html
├── logs
└── sbin
    └── nginx
5 directories, 19 files
請參考「/usr/local/share/nginx/conf/nginx.conf」的設定
http {
	server {
		listen	   8080;
		server_name  localhost;
		location / {
			root   html; ## /usr/local/share/nginx/html
			index  index.html index.htm;
		}
	}
}
請參考「/usr/local/share/nginx/conf/nginx.conf」的設定
				hls_path /usr/local/share/nginx/hls;
請參考「/usr/local/share/nginx/conf/nginx.conf」的設定
http {
	server {
		listen	   8080;
		server_name  localhost;
		location /hls {
			alias  hls; ## /usr/local/share/nginx/hls
		}
	}
}
請參考「/usr/local/share/nginx/conf/nginx.conf」的設定,和參考「push-hls.sh」。
rtmp {
	server {
		listen 2020;
		application hls {
				live on;
				hls on;
				hls_path /usr/local/share/nginx/hls;
				hls_fragment 5s;
		}
	}
}
可以參考
執行
$ /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/hls/film
上面指令寫在「push.sh」。
然後執行
$ ls /usr/local/share/nginx/hls -1
會看到
film-0.ts
film-1.ts
film-2.ts
film-3.ts
film-4.ts
film-5.ts
...略...
film.m3u8
也就是會在「/usr/local/share/nginx/hls」這個資料夾,陸續產生上面這些檔案。
然後在開啟另一個「Terminal」,執行下面指令觀看
$ ffplay rtmp://localhost:2020/hls/film
也可以執行下面指令觀看
$ vlc rtmp://localhost:2020/hls/film
也可以執行下面指令觀看
$ mpv rtmp://localhost:2020/hls/film
上面指令寫在「view-rtmp.sh」。
也可以執行下面指令觀看
$ ffplay http://localhost:8080/hls/film.m3u8
也可以執行下面指令觀看
$ vlc http://localhost:8080/hls/film.m3u8
也可以執行下面指令觀看
$ mpv http://localhost:8080/hls/film.m3u8
上面指令寫在「view-hls.sh」。
執行下面指令觀看網頁
$ firefox http://localhost:8080/live.html
上面指令寫在「view-page.sh」。
請參考「/usr/local/share/nginx/html/live.html」的內容,
網頁是播放「 http://localhost:8080/hls/film.m3u8 」。
當過一段時間後,再觀看「/usr/local/share/nginx/hls」,裡面的「film*」的這些檔案,是會被清除的。
可以查詢「hls」,參考「直播協議 hls 筆記」這篇的說明。
我之前也有寫了一篇「關於「m3u」和「mpv」和「smplayer」的操作使用」。