Nginx配置文件下载
背景:假设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";
}
Nginx配置文件下载相关推荐
- nginx配置wss协议
需求:nginx配置websocket协议连接,(背景,在一个使用一个免费的仅仅支持单域名的证书时,既要支持https协议,也要支持wss协议时,我们可以配置一个nginx根据不同的路径去跳转) 我所 ...
- nginx配置 实现文件下载
需求:上传文件到服务器后,对外提供url路径,来完成文件下载 nginx配置 server {listen 8008;client_max_body_size 500m; //文件大小限制,默认1mp ...
- nginx配置参数详解
PS:Nginx使用有两三年了,现在经常碰到有新用户问一些很基本的问题,我也没时间一一回答,今天下午花了点时间,结合自己的使用经验,把Nginx的主要配置参数说明分享一下,也参考了一些网络的内容,这篇 ...
- 三个案例看Nginx配置安全
之前在Sec-News中推荐了一个开源程序 https://github.com/yandex/gixy,作用是来检测Nginx配置文件中存在的问题.正好Pwnhub上周的比赛也出现了一道题,包含由 ...
- nginx配置多个站点共用80端口
原文链接:https://blog.csdn.net/zhezhebie/article/details/73459874 -------------------------------------- ...
- NGINX配置基于Node.js服务的负载均衡服务器
NGINX配置基于Node.js服务的负载均衡服务器 本部署指南说明了如何使用NGINX开源和NGINX Plus在Node.js应用程序服务器池之间平衡HTTP和HTTPS通信.本指南中的详细说明适 ...
- nginx配置一个简单的php网站遇到的问题
安装完nginx后,想查看nginx的位置,可以通过查看软件安装路径命令 whereis nginx 这里的/usr/local/nginx/ 即是nginx的安装位置,配置文件在 /usr/loca ...
- nginx 配置多个域名 指向不同服务_Nginx的几个常用配置和技巧
文章列举了几个Nginx常见的,实用的,有趣的配置,希望看过之后能说一句:学到了! 一个站点配置多个域名 server { listen 80; server_name ops-coffee.cn b ...
- Nginx 配置示例
文章目录 Nginx主配置文件调优 Nginx HTTP跳转HTTPS Nginx代理PHP服务 Nginx作为代理服务器 Nginx作为负载均衡服务器 Nginx作为静态文件服务器 Nginx反向代 ...
最新文章
- “积水上报”广获好评 畅移信息接棒 “互联网+政务”落地
- 跨站脚本(XSS)漏洞 (一)
- Verilog自编函数clog2替代SV中的系统函数$clog2
- Hibernate 拦截器 Hibernate 监听器
- 文本分类实战技巧(tricks)汇总
- 改变浏览器视角大小:Viewport Resizer
- 漫画:如何实现抢红包算法?
- c语言判断素数(c语言判断素数)
- java生成uuid主键_java生成UUID
- 如果使用CSS创建表格显示
- ubuntu mysql无法启动服务器_ubuntu – Mysql无法启动mysqld.sock缺失
- 前端---HTML制作百度首页
- Spark编程核心抽象—RDD
- git log vs git diff 中的点式范围(Dotted Range Notations)异同
- C语言:简单的switch()函数,代码讲解
- win7家庭版桌面没有计算机图标,Win7 home basic家庭普通版显示桌面图标的方法
- 电子发票电子化报销入账归档 给区块链领域带来了什么样的机遇
- ui(new Ui::MainWindow) 解惑
- outlook你的邮件服务器证书无效,安卓手机outlook无法登录、添加帐户
- 管理规划:目标是什么?