12、验证已安装的Nginx服务器是否支持mp4、flv等视频
cd /usr/local/nginx/sbin
nginx –V
configure arguments:
--add-module=/nginx/nginx_mod_h264_streaming-2.2.7 --with-pcre=/nginx/pcre-7.9 --with-zlib=/nginx/zlib/1.2.3 --prefix=/usr/local/nginx --with-http_flv_module --with-http_stub_status_module --with-openssl=/nginx/openssl-0.9.3 --with-http_mp4_module --with-cc-opt='-O3'
13、配置Nginx配置文件
cd /usr/local/nginx/conf/
vi nginx.conf ##修改配置文件
user videoapp video; ##管理用户
worker_processes 8; ##后台进程
error_log /usr/local/nginx/logs/error.log;
##nginx错误日志存放路径
pid /usr/local/nginx/logs/nginx.pid;
events {
use epoll;
##轮训方式
worker_connections 65535;
##允许的最大连接数
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /usr/local/nginx/logs/access.log;
sendfile on;
tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 801;
server_name localhost;
root /usr/local/nginx/html ;
#charset koi8-r;
limit_rate_after 5m;
limit_rate 512k;
charset utf-8;
access_log /usr/local/nginx/logs/host.access.log main;
location / {
root html;
index index.html index.htm;
# limit_rate_after 5m;
# limit_rate 512k;
}
#error_page 404 /404.html;
location ~ \.flv$ {
flv;
}
location ~ \.mp4$ {
mp4;
}
location ~(favicon.ico) {
log_not_found off;
expires 30d;
break;
}
14、拷贝视频及falsh播放器到video目录下
15、拖动播放测试http://127.0.0.1:801/video/player.swf?type=http&file=2.flv
http://127.0.0.1:801/player.swf?type=http&file=xxy.mp4
三、后续完善的工作
1、为节省带宽防止用户直接下载视频我们需要做如下设置(视频防盗链):
1、到http://wiki.codemongers.com/NginxHttpAccessKeyModule去下载防盗链模块,没办法总有人想下载。还是要做好防盗链工作的。
需要注意的是,下载完防盗链模块之后需要修改下配置文件讲config文件中的“$HTTP_ACCESSKEY_MODULE” 改成“ngx_http_accesskey_module”,不改的话没办法开启防盗链模块。
2、执行编译:./configure --add-module=/nginx/nginx_mod_h264_streaming-2.2.7 --with-pcre=/nginx/pcre-7.9 --with-zlib=/nginx/zlib/1.2.3 --prefix=/usr/local/nginx --with-http_flv_module --with-http_stub_status_module --with-openssl-opt=enable --with-http_mp4_module --add-module=/nginx/nginx-accesskey-2.0.3 --with-cc-opt='-O3
3、make && make install 安装完毕 其他配置参数同上13步骤的配置
4、最后开启防盗链功能
location ~ \.mp4$ {
mp4;
limit_conn one 2;
limit_rate 200k;
accesskey on;
accesskey_hashmethod md5;
accesskey_arg “key”;
accesskey_signature “movie.weiqp.cn$remote_addr”;
}
