很多场景下,我们需要对用户提供文件下载功能,比如不同版本的软件列表,或者对外提供的一些公开的报表下载。
例如linux提供的内核源码下载列表界面如下:
配置实战需求描述
已有系统,服务端使用的是nginx服务器,域名为www.***.com,是一个php项目。现在要在该域名上实现一个文件下载的目录,所有要下载的文件都放到/home/havy/download/。
实现方案
在原有nginx配置中增加location模块,对www.***.com/attach访问路径设置为下载目录根目录/home/havy/download/,并且对该location块开启目录文件列表,详细配置如下:
server{ listen80; server_namewww.** *.com; #此模块为新加配置 location~ ^/attach{ root/home/havy/webroot/; autoindexon; # 开启目录文件列表 autoindex_exact_sizeon; # 显示出文件的确切大小,单位是bytes autoindex_localtimeon; # 显示的文件时间为文件的服务器时间 charsetutf- 8,gbk; # 避免中文乱码 } location~ ^/(favicon.ico|static){ root/home/www/yuhaiwei/odp/webroot; } location~ .php${ root/home/havy/webroot; fastcgi_pass$php_upstream; fastcgi_indexindex.php; includefastcgi.conf; } location/ { root/home/havy/webroot; indexindex.php; fastcgi_pass$php_upstream; includefastcgi.conf; rewrite^/([^/.]*)(/[^?]*)?((?.*)?)$/ $1/index.php $2$3break; } }
这样,当访问www.***.com/attach就展现出/home/havy/download/目录下文件列表了。
按字母顺序浏览:A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
→我们致力于为广大网民解决所遇到的各种电脑技术问题 如果您认为本词条还有待完善,请 编辑词条
上一篇什么是LRU算法(漫画)?
下一篇网易关停薄荷直播