配置nginx作为下载站点

nginx默认情况是不允许列出整个目录浏览下载

1)autoindex参数详解
autoindex   on                                          //on开启目录浏览
autoindex_exact_size    off;            //off显示出文件的大概大小,单位是kB或者MB或者GB;默认为on, 显示出⽂件的确切⼤⼩,单位是bytes。
autoindex_localtime on;             //显示的⽂件时间为⽂件的服务器时间。默认为off,显示的⽂件时间为GMT时间。
charset utf-8,gbk;                  //默认中文目录乱码,添加上解决乱码问题;
2)配置下载站点
#vim /usr/local/nginx/conf/nginx.conf 
location /download {
    root html;
    autoindex on;
    autoindex_localtime on;
    autoindex_exact_size off;
}

注意

location /download {
    root html;
    用户访问:192.168.1.31/download 对应的nginx站点目录是/usr/local/nginx/html/download;
location / {
    root html;
    用户访问:192.168.1.31 对应访问的nginx站点目录是/usr/local/nginx/html 
3)创建目录和添加文件
mkdir /usr/local/nginx/html/download/test -pv  
cp /etc/hosts /usr/local/nginx/html/download 
nginx -t 
nginx -s reload 
4)验证

http://192.168.1.31/download/
1195071-20180517173954420-1649363797.png

5)配置截图

1195071-20180517174022958-1789801405.png

5)别名方式
location /upload {
    alias /load;
        autoindex on;
        autoindex_localtime on;
        autoindex_exact_size off;
}
用户访问:192.168.1.31/upload 对应的nginx站点目录是/load,而不是/load/upload 

转载于:https://www.cnblogs.com/lovelinux199075/p/9052277.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值