配置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/

5)配置截图

5)别名方式

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

猜你喜欢

转载自www.cnblogs.com/lovelinux199075/p/9052277.html