我想将视频流与 nginx 一起用于 windows 服务器。我有这个 nginx 配置:
#user nobody;
worker_processes 1;
error_log logs/error.log;
error_log logs/error.log notice;
error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
proxy_max_temp_file_size 0;
proxy_cache_path /nginx/cache levels=1:2 keys_zone=STATIC:1000m max_size=1000m inactive=720m;
proxy_temp_path /nginx/tmp;
server {
listen 81;
server_name 127.0.0.1;
location ~* .(jpe?g|gif|png|ico|css|pdf|ppt|txt|bmp|rtf|js)$ {
access_log off;
proxy_pass http://10.1.4.22:9001;
proxy_cache STATIC;
proxy_ignore_headers "Set-Cookie";
proxy_hide_header "Set-Cookie";
}
location / {
proxy_pass http://10.1.4.22:9001;
}
location ~* /!/scorms.ecp/\d+(/.*\.(mp4|webm|ogv))$ {
root /video;
proxy_pass http://10.1.4.22:9001;
rewrite /!/scorms.ecp/\d+/(\w+)/\d+/\d+/\w+/(.+) /$1/$2 break;
try_files $1 @fallback;
error_log logs/error.log debug;
flv;
mp4;
mp4_buffer_size 512k;
mp4_max_buffer_size 1m;
#mp4_limit_rate on;
#mp4_limit_rate_after 30s;
}
location @fallback {
proxy_pass http://10.1.4.22:9001;
flv;
mp4;
mp4_buffer_size 512k;
mp4_max_buffer_size 1m;
}
}
}
此配置中最重要的是:
location ~* /!/scorms.ecp/\d+(/.*\.(mp4|webm|ogv))$ {
root /video;
proxy_pass http://10.1.4.22:9001;
rewrite /!/scorms.ecp/\d+/(\w+)/\d+/\d+/\w+/(.+) /$1/$2 break;
try_files $1 @fallback;
error_log logs/error.log debug;
flv;
mp4;
mp4_buffer_size 512k;
mp4_max_buffer_size 1m;
#mp4_limit_rate on;
#mp4_limit_rate_after 30s;
}
我发送请求http://host:port/!/scorms.ecp/27/TESTC/1/1/images/pravilo2.mp4。在 error.log 我有:
2016/05/25 09:53:19 [error] 9200#7996: *1 CreateFile() "D:\PAPISDK_4_T\nginx-1.10.0/html/TESTC/pravilo11.mp4" failed (3: The system cannot find the path specified), client: 10.1.4.22, server: 127.0.0.1, request: "GET /!/scorms.ecp/27/TESTC/1/1/images/pravilo11.mp4 HTTP/1.1", host: "10.1.4.22:81", referrer: "http://10.1.4.22:81/!/scorms.ecp/27/TESTC/1/1/start.html"
我不明白为什么 nginx 会尝试查找“D:\PAPISDK_4_T\nginx-1.10.0/html/TESTC/pravilo11.mp4”而不是“D:\video/TESTC/pravilo11.mp4”。我尝试使用“root D:\video;” 并收到同样的错误。我也尝试使用“别名”而不是“根”,但我收到了下一个错误:
alias /video; -> "alias" cannot be used in location "/!/scorms.ecp/\d+(/.*\.(mp4|webm|ogv))$" where URI was rewritten
如何调整 Windows 的 nginx 配置以通过以下路径“D:\video/TESTC/pravilo11.mp4”而不是“D:\PAPISDK_4_T\nginx-1.10.0/html/TESTC/pravilo11.mp4”查找视频文件?