Nginx_開啓目錄文件列表功能

ngx_http_autoindex_module  此模塊用於自動生成目錄列表,ngx_http_autoindex_module只在 ngx_http_index_module模塊未找到索引文件時發出請求.javascript

nginx默認是不容許列出整個目錄的。css

開啓目錄列表:
打開nginx.conf文件,在location server 或 http段中加入
 autoindex on;
java

 

 例如:node

http {
    include       mime.types;
    default_type  application/octet-stream;
nginx

    autoindex on;//自動顯示目錄
    autoindex_exact_size off;//人性化方式顯示文件大小不然以byte顯示
    autoindex_localtime on;//按服務器時間顯示,不然以gmt時間顯示
web

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 8m;
    limit_zone one $binary_remote_addr 32k;
服務器

    sendfile        on;
    tcp_nopush     on;
app

    keepalive_timeout  60;
    tcp_nodelay on;
tcp

    gzip  on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;
spa

    log_format  wwwlogs  '$remote_addr - $remote_user [$time_local] $request $status $body_bytes_sent $http_referer $http_user_agent $http_x_forwarded_for';
    #include default.conf;
    include vhost/*.conf;
}


另外兩個參數最好也加上去:
autoindex_exact_size off;
默認爲on,顯示出文件的確切大小,單位是bytes。
改成off後,顯示出文件的大概大小,單位是kB或者MB或者GB
autoindex_localtime on;
默認爲off,顯示的文件時間爲GMT時間。
 改成on後,顯示的文件時間爲文件的服務器時間

配置Nginx目錄列表的方法詳細參照:http://wiki.nginx.org/NginxChsHttpAutoindexModule

若是想但願目錄列表支持header,footer則能夠安裝三方插件: 
http://wiki.nginx.org/NginxNgxFancyIndex

相關文章
相關標籤/搜索