nginx module - autoindex, fancyindex

最後更新: 2024-10-09

目錄

 


ngx_http_autoindex_module

 

# Default: off

autoindex on;

# on(Default): accurately (in bytes); off: rounded (KB, MB or GB)

autoindex_exact_size on;

# Show UTC time (Default is "off")

autoindex_localtime on;

用外觀較好的 themes -  autoindex.html

使用 add_after_body 車入下載好的 thems (.autoindex.html)

# mkdir -p /home/seafile/clients_software
# cd /home/seafile/clients_software
# wget https://phuslu.github.io/autoindex.html -O .autoindex.html

location /clients {
    autoindex            on;
    autoindex_localtime  on;
    autoindex_exact_size off;
    alias                /home/seafile/clients_software;
    add_after_body       /clients/.autoindex.html;
}

Hide files from autoindex

.autoindex.html

Other Opts

# Default: html

autoindex_format html | xml | json | jsonp;

 


ngx_http_fancyindex_module

 

Install

fancyindex module (nginx-extras)

https://github.com/aperezdc/ngx-fancyindex

wget https://github.com/aperezdc/ngx-fancyindex/archive/v0.4.3.zip -O ngx-fancyindex-v0.4.3.zip

./configure --prefix=/opt/nginx \
 ...
 --with-http_addition_module \
 --add-dynamic-module=/usr/src/nginx/ngx-fancyindex-0.4.3

make

make install

Config

[1] nginx.conf

load_module "modules/ngx_http_fancyindex_module.so";

[2] sites-enabled/default

location ~ ^/.nginx/ { allow all; }
location ~ ^/\. { deny all; }
location / {
  include snippets/fancyindex.conf;
  try_files $uri $uri/ =404;
}

[3] snippets/fancyindex.conf

#autoindex on;
#autoindex_localtime on;

fancyindex               on;       # Enable fancy indexes
fancyindex_localtime     on;
fancyindex_time_format   "%F %R";
fancyindex_exact_size    off;      # Output human-readable file sizes
fancyindex_name_length   127;
fancyindex_hide_symlinks on;

fancyindex_header "/.nginx/header.html";
fancyindex_footer "/.nginx/footer.html";

Theme

[Theme 1]

Link=https://github.com/leshniak/fancyindex-royal-theme

wget $Link/archive/refs/heads/master.zip \
-O fancyindex-royal-theme.zip

unzip fancyindex-royal-theme.zip

ls fancyindex-royal-theme-master/.nginx/

footer.html  header.html  icons  icons.json  script.js  style.css

[Theme 2]

https://github.com/artyuum/Nginx-FancyIndex-Theme

Config

location /  {
    fancyindex on;
    fancyindex_header "/fancyindex_theme/header.html";
    fancyindex_ignore "/fancyindex_theme";
}

location /fancyindex_theme {
    alias /etc/nginx/fancyindex_theme;
    try_files $uri $uri/ =404;
}

 

 

Creative Commons license icon Creative Commons license icon