首页  >  文章  >  运维  >  nginx开启列目录的示例分析

nginx开启列目录的示例分析

WBOY
WBOY转载
2023-05-26 11:36:401336浏览

nginx开启列目录

当你想让nginx作为文件下载服务器存在时,需要开启nginx列目录

server {
 location download {
  autoindex on;

  autoindex_exact_size off;
  autoindex_localtime on;
 }
}

autoindex_exact_size: 为on(默认)时显示文件的确切大小,单位是byte;改为off显示文件大概大小,单位KB或MB或GB

autoindex_localtime: 为off(默认)时显示的文件时间为GMT时间;改为on后,显示的文件时间为服务器时间

默认当访问列出的txt等文件时会在浏览器上显示文件的内容,如果你想让浏览器直接下载,加上下边的配置

if ($request_filename ~* ^.*?\.(txt|pdf|jpg|png)$) {
 add_header Content-Disposition 'attachment';
}

以上是nginx开启列目录的示例分析的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:yisu.com。如有侵权,请联系admin@php.cn删除