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

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
P
Privacy International News Feed
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Troy Hunt's Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Attack and Defense Labs
Attack and Defense Labs
S
Secure Thoughts
V2EX - 技术
V2EX - 技术
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
O
OpenAI News
Cloudbric
Cloudbric
Google Online Security Blog
Google Online Security Blog
Schneier on Security
Schneier on Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Help Net Security
Help Net Security
Cyberwarzone
Cyberwarzone
G
GRAHAM CLULEY
L
Lohrmann on Cybersecurity
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
NISL@THU
NISL@THU
N
News and Events Feed by Topic
T
Tenable Blog
S
Security @ Cisco Blogs
N
News and Events Feed by Topic
The Hacker News
The Hacker News
C
CXSECURITY Database RSS Feed - CXSecurity.com
宝玉的分享
宝玉的分享
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
美团技术团队
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google DeepMind News
Google DeepMind News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tailwind CSS Blog
V
Visual Studio Blog
P
Proofpoint News Feed
Webroot Blog
Webroot Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 三生石上(FineUI控件)
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Jina AI
Jina AI
雷峰网
雷峰网
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
腾讯CDC
L
LangChain Blog
The Register - Security
The Register - Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东

博客园 - 懒牛拉车

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";
}