惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

G
Google Developers Blog
宝玉的分享
宝玉的分享
月光博客
月光博客
B
Blog
云风的 BLOG
云风的 BLOG
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
N
Netflix TechBlog - Medium
博客园_首页
GbyAI
GbyAI
人人都是产品经理
人人都是产品经理
A
About on SuperTechFans
Y
Y Combinator Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
D
Docker
爱范儿
爱范儿
博客园 - 司徒正美
H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
酷 壳 – CoolShell
酷 壳 – CoolShell
Microsoft Security Blog
Microsoft Security Blog
D
DataBreaches.Net

博客园 - 懒牛拉车

xxx tmp Thinkphp 3.2 Cookie丢失导致中英文混排 第一个python自动化实例 每次用npm都很烦人 js 判断mac地址是否为组播地址 项目在本地时,css/js文件在浏览器刷新时,从(memory cache)读取,放服务器上就不会 模拟json_decode解析非法utf-8编码字符串 php socket 循环ping ip,显示能ping通的IP地址 thinkphp3.2.2 CheckLangBehavior.class中,使用session无效原因分析 Thikphp 3.2 session页面传递失败问题 火狐autocomplete="off"无效 testlink windows 安装笔记 宝塔面板部署thinkcmf问题 coreseek 測試用例 coreseek 基与Sphinx 的全文索引 centos6 nginx 配置本地https访问 centos6 nginx安装好以后,添加拓展ssl centos6 php7 安装 memcache 和 memcached - 懒牛拉车 centos7 搭建 php7 + nginx (2) - 懒牛拉车 centos7 搭建 php7 + nginx (1)
Nginx配置文件下载
懒牛拉车 · 2022-06-06 · via 博客园 - 懒牛拉车

背景:假设WEB目录为/nginx/wwwroot,web访问路径为 http://abc.com/ ,现在需要当url为http://abc.com/download/***.tar的时候,下载其他目录下的文件。

环境:默认vhost.conf配置如下

server {
    listen       80;
    listen       [::]:80;
    server_name  localhost;

    limit_conn perip 7;
    
    location / {
        root   /nginx/wwwroot;
        if (!-e $request_filename) {
                rewrite  ^(.*)$  /index.php?s=/$1  last;
                break;
        }
        index  index.php index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;

    location ~ \.php$ {
        root           /nginx/wwwroot;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

方式1:反向代理(缺点:需要多开放一个端口)

server {
    listen        8099;
    root  /mnt/nandflash/;
    location / {
        autoindex on;
        autoindex_exact_size on;
        autoindex_localtime on;
        charset utf-8,gbk;
    }
}

location /download/ {
    proxy_pass http://127.0.0.1:8099/;
}

方式2 (缺点:需要通过http://abc.com/nandflash/**.zip访问)

location ~ /nandflash  { 
    root /mnt;
    if ($request_filename ~* ^.*?\.(tar|zip)$){
        add_header Content-Disposition: 'attachment';
        add_header  Content-Type application/octet-stream;
    }
}

方式3 虚拟目录

location ~ /download/(.*)\.(tar|zip)$ {
    alias  /mnt/nandflash/$1.$2;
}

以上3中方法,理论上应该有文件夹权限的问题,但我环境没碰到,本人就没管了,算是个坑吧。

下面方式是网上很多文章中提到的办法,但在我的环境下,没有效果。

location ~ /download {
    alias /mnt/nandflash/;
    autoindex on;
    autoindex_exact_size on;
    autoindex_localtime on;
    charset utf-8,gbk;
}

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