Nginx make download site

Nginx is implemented using the module ngx_http_autoindex_module, which processes requests ending with a slash ("/") and generates a directory listing.
This module will be automatically loaded when nginx is compiled, but the module is disabled by default, use the following commands to complete the corresponding configuration

autoindex

Enable or disable directory listing output

grammar autoindex on|off;
Defaults autoindex off;
Location http、server、location

autoindex_exact_size

Corresponding to the HTLM format, specify whether to display the detailed size of the file in the directory list
. The default is on, which displays the exact size of the file, and the unit is bytes. After changing to off, the approximate size of the file is displayed in kB or MB or GB

grammar autoindex_exact_size on|off;
Defaults autoindex_exact_size on;
Location http、server、location

autoindex_format

Format directory listings

grammar autoindex_format html|xml|json|jsonp;
Defaults autoindex_format html;
Location http、server、location

Note: This command appears in version 1.7.9 and later

autoindex_localtime

Corresponding to the HTML format, whether to display the time on the directory listing.
The default is off, and the displayed file time is GMT time. After changing to on, the displayed file time is the server time of the file

the case

  • Environment file path /home/download
    insert image description here

  • Nginx configuration

server {
  listen 8068;
  server_name localhost;
  location /download{
    root /home;
    autoindex on;
    autoindex_exact_size on;
    autoindex_format html;
    autoindex_localtime on;
  }
}
  • access effect

insert image description here

  • xml format

insert image description here

  • json format
    insert image description here

Guess you like

Origin blog.csdn.net/u010859650/article/details/127899558