Java教程

nginx修改Content-Type

本文主要是介绍nginx修改Content-Type,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

开发中遇到了一打开MP4文件就进行下载的问题,排查发现是浏览器有迅雷插件,而且MP4的媒体Content-Type类型是application/octet-stream,这就导致迅雷识别为需要下载,然后就弹出了下载框。

现解决方案为修改nginx配置,对MP4后缀文件进行处理,强制修改Content-Type类型为:video/mp4。

配置如下:

location ^~/minio/ {
        if ($request_uri ~* \.mp4$) {
            rewrite ^/minio/(.*)$ /_mp4_path/$1 last;
        }
        internal;
        proxy_no_cache 1;
        proxy_set_header Referer $minio_referer;
        proxy_pass http://###.com/rms-test/;
}
location ~ ^/_mp4_path/(.*)$ {
        internal;
        proxy_no_cache 1;
        proxy_hide_header Content-Type;
        add_header Content-Type video/mp4;
        proxy_set_header Referer $minio_referer;
        proxy_pass http://###.com/rms-test/$1;
}


这篇关于nginx修改Content-Type的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!