Ngnix配置反向代理及添加媒体文件处理
因项目的ckplayer视频播放不能拖动播放,因此添加ngnix解决ckplayer的问题。
下载nginx-1.11.10.tar.gz文件及nginx_mod_h264_streaming-2.2.7.tar.gz文件
安装nginx
解压nginx-1.11.10.tar.gz后,当前文件夹打开终端运行./configure
输出完毕后运行make
然后运行make install
nginx安装完毕(默认安装/usr/local/nginx路径下)。
运行nginx:sudo /usr/local/nginx/sbin/nginx
修改nginx.conf后重载nginx:sudo /usr/local/nginx/sbin/nginx -s reload
停止nginx:sudo /usr/local/nginx/sbin/nginx -s stop
添加媒体文件扩展
解压nginx_mod_h264_streaming-2.2.7.tar.gz文件,
在nginx-1.11.10.tar.gz后文件夹打开终端运行./configure --add-module=/usr/local/nginx_mod_h264_streaming-2.2.7 --prefix=/usr/local/nginx --with-http_flv_module --with-http_mp4_module
运行完毕后执行make,若有错误,可打开rely-file/nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c文件注释如下内容:
/* TODO: Win32
if (r->zero_in_uri)
{
return NGX_DECLINED;
}
*/
删掉nginx-1.11.10/objs/Makefile内-Werror后重新执行make命令。
执行完成后复制生成的nginx文件到/usr/local/nginx/sbin/(备份原文件后覆盖)。
nginx配置
nginx/conf下nginx.conf文件
server {
# 后期项目访问地址,端口
listen 8080;
server_name 192.168.1.164;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
# 设置项目根路径
root /Users/ZYB/workspace/IdeaProjects_assoft/mch/mch/WebContent;
# 项目原始地址
proxy_pass http://192.168.1.234:8480;
# 拦截mp4文件
location ~ .*\.mp4$ {
mp4;
# 设置项目根路径
root /Users/ZYB/workspace/IdeaProjects_assoft/mch/mch/WebContent;
}
# root html;
# index index.html index.htm;
}
# location ^~ /mch/shipin/ceshi/ {
# mp4;
# }
# location ^~ /mch/shipin/ceshi/ {
# flv;
# }
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
win下的nginx程序下载后执行exe文件,另win下nginx自带媒体文件处理包,只需配置nginx/conf下nginx.conf文件即可。