原因:Nginx缓存导致无法在线播放
node项目在用Nginx反代后,发现直接访问内网地址可以在线播放mp4,但走Nginx后mp4就只能缓冲完毕后播放。
刚开始以为是新装的Nginx没有在编译时带上 –with-http_flv_module –with-http_mp4_module,但后来发现不是,最终发现是宝塔默认开启了proxy_cache cache_one; 将proxy_cache 设为off后问题解决。
location /
{
proxy_pass http://127.0.0.1:3030;
proxy_set_header Host 127.0.0.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;
# proxy_hide_header Upgrade;
proxy_cache off;
add_header X-Cache $upstream_cache_status;
#Set Nginx Cache
set $static_file31ND2yGy 0;
if ( $uri ~* "\.(gif|png|jpg|css|js|woff|woff2)$" )
{
set $static_file31ND2yGy 1;
expires 1m;
}
if ( $static_file31ND2yGy = 0 )
{
add_header Cache-Control no-cache;
}
}
另:proxy_buffers也建议关闭。
———————————–
Nginx缓存导致无法在线播放