最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

设置ngnix下的文件在浏览器端直接下载而不是被浏览器默认打开

业界 admin 4浏览 0评论
    server {
        listen       443 ssl;
        server_name  localhost;


        ssl_certificate      key/1__.hexunzc_bundle.crt;
        ssl_certificate_key  key/2__.hexunzc.key;


        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;


        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;


        location / {
            root   html;
            index  index.html index.htm;

        }


        location ~ ^/attach/product/financing/(.*)$ {
add_header Content-Disposition "attachment; filename=$1";  
}

    }


在nginx.conf文件中添加红色部分的配置,即当  /attach/product/financing/ 这个目录下的文件被请求时加上一个头部信息告诉浏览器直接下载文件而不是打开,比如pdf

    server {
        listen       443 ssl;
        server_name  localhost;


        ssl_certificate      key/1__.hexunzc_bundle.crt;
        ssl_certificate_key  key/2__.hexunzc.key;


        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;


        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;


        location / {
            root   html;
            index  index.html index.htm;

        }


        location ~ ^/attach/product/financing/(.*)$ {
add_header Content-Disposition "attachment; filename=$1";  
}

    }


在nginx.conf文件中添加红色部分的配置,即当  /attach/product/financing/ 这个目录下的文件被请求时加上一个头部信息告诉浏览器直接下载文件而不是打开,比如pdf

发布评论

评论列表 (0)

  1. 暂无评论