nginx默认是不允许列出整个目录的。那如何开启Nginx的目录文件列表功能?

方法是修改Nginx的配置文件nginx.conf,linux下默认在/usr/local/nginx/conf

编辑nginx.conf文件,在location serverhttp段中加入

autoindex on;

另外两个参数最好也加上去:

autoindex_exact_size off;

默认为on,显示出文件的确切大小,单位是byte(s)

改为off后,显示出文件的大概大小,单位是kB或者MB或者GB

autoindex_localtime on;

默认为off,显示的文件时间为GMT时间

改为on后,显示的文件时间为文件的服务器时间

[toggle hide="yes" title="配置示例(点击展开)" color="black"]
http
{
include mime.types;
default_type application/octet-stream;

autoindex on;
autoindex_exact_size off;
autoindex_localtime on;

server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;

sendfile on;
tcp_nopush on;

keepalive_timeout 60;

tcp_nodelay on;

fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;

gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";

#limit_conn_zone $binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.

server_tokens off;
#log format
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log off;
[/toggle]

编辑后重新加载/启动即可,军哥的LNMP只需执行lnmp reload即可